<?php
$font_family = 'font-family:Segue UI, Roboto, Tahoma, sans-serif;';
$table_style = 'style="border:1px solid #ccc;border-collapse:collapse;width:100%;'.$font_family.'"';
$th_style = 'style="padding:3px 5px;font-size:12px;border:1px solid #ccc;font-weight:bold;'.$font_family.'"';
$td_style = 'style="padding:3px 5px;font-size:12px;border:1px solid #ccc;'.$font_family.'"';
$h3_style = 'style="padding:3px 5px;font-size:14px;font-weight:bold;margin-bottom:10px;'.$font_family.'"';
$p_style = 'style="padding:3px 5px;font-size:12px;margin-bottom:10px;'.$font_family.'"';
?>
<h3 <?php echo $h3_style; ?>>Task in Processing</h3>
<table cellpadding="0" cellspacing="0" <?php echo $table_style; ?>>
    <tr>
        <td <?php echo $th_style; ?>>#</td>
        <td <?php echo $th_style; ?>>Task Title</td>
        <td <?php echo $th_style; ?>>Task For</td>
        <td <?php echo $th_style; ?>>Description</td>
        <td <?php echo $th_style; ?>>Assigned</td>
        <td <?php echo $th_style; ?>>Time Left</td>
        <td <?php echo $th_style; ?>>Status</td>
        <td <?php echo $th_style; ?>>Created By</td>       
    </tr>
   <?php
		if(!empty($task_processing))
		{
			$i = 0;
			foreach($task_processing as $value)
			{
				$i++;
	?>
	<tr>
		<td <?php echo $td_style;?>><?php echo $i;?></td>
		<td <?php echo $td_style;?>>
		<?php echo ucwords($value->task_title).' ('.$value->task_list_id.')'; ?>
		</td>
		<td <?php echo $td_style;?>>
			<?php 
			if($value->task_for == 1 AND $value->client_id != 0){
				$result = DB::table('client')->where('client_id',$value->client_id)->get('client')->first();
				if($result){
				    echo $result->client_title.'(IL-C'.$value->client_id.')';
				}
			}else{
				echo $value->task_for_name;
			}
			?>
		</td>
		<td <?php echo $td_style;?>>
		<?php echo $value->task_description; ?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		$task_assign = DB::table('task_assigned_admin')->where('task_list_id',$value->task_list_id)->get();
		if($task_assign){
			$myArray = array();
			foreach($task_assign as $row){
				$result = DB::table('admin')->select('user_name','user_phone','user_email','admin_id')->where('admin_id',$row->admin_id)->first();
				$myArray[] = $result->user_name; 
			}
			echo implode( ', ', $myArray );
		} 
		?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		if($value->task_status == 3){
			$date = $value->task_status_complete_time;
			$datetime1 = new DateTime($date);//start time
			$datetime2 = new DateTime($value->task_start);//end time
			$interval = $datetime2->diff($datetime1);
			//echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');
			echo $interval->format('%dD, %HH, %iM');
		}else{
			$date = date('Y-m-d H:i:s');
			$datetime1 = new DateTime($date);//start time
			$datetime2 = new DateTime($value->task_start);//end time
			$interval = $datetime2->diff($datetime1);
			//echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');
			echo $interval->format('%dD, %HH, %iM');
		}
		?>
		</td>
		<td <?php echo $td_style;?>>
		<?php 
			if($value->task_status == 1){
				echo '<span class="label label-primary">Scheduled</span>';
			}elseif($value->task_status == 2){
				echo '<span class="label label-warning">Processing</span>';
			}elseif($value->task_status == 3){
				echo '<span class="label label-success">Complete</span>';
			}
			?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		$result = DB::table('admin')->select('user_name')->where('admin_id',$value->task_added_by_admin_id)->first();
		if($result){
		echo $result->user_name.'('.$value->task_added_by_admin_id.')'; 
		}
		?>
		</td>
	</tr>  
	<?php
			}
		}else{
	?>
	<tr>
		<td colspan="6">No Result Found</td>
	</tr>
	<?php 
		}
	?>
</table>
<h3 <?php echo $h3_style; ?>>Task in Schedule</h3>
<table cellpadding="0" cellspacing="0" <?php echo $table_style; ?>>
    <tr>
        <td <?php echo $th_style; ?>>#</td>
        <td <?php echo $th_style; ?>>Task Title</td>
        <td <?php echo $th_style; ?>>Task For</td>
        <td <?php echo $th_style; ?>>Description</td>
        <td <?php echo $th_style; ?>>Assigned</td>
        <td <?php echo $th_style; ?>>Time Left</td>
        <td <?php echo $th_style; ?>>Status</td>
        <td <?php echo $th_style; ?>>Created By</td>       
    </tr>
   <?php
		if(!empty($task_schedule))
		{
			$i = 0;
			foreach($task_schedule as $value)
			{
				$i++;
	?>
	<tr>
		<td <?php echo $td_style;?>><?php echo $i;?></td>
		<td <?php echo $td_style;?>>
			<?php echo ucwords($value->task_title).' ('.$value->task_list_id.')'; ?>
		</td>
		<td <?php echo $td_style;?>>
			<?php 
			if($value->task_for == 1 AND $value->client_id != 0){
				$result = DB::table('client')->where('client_id',$value->client_id)->first();
				if($result){
				    echo $result->client_title.'(IL-C'.$value->client_id.')';
				}
			}else{
				echo $value->task_for_name;
			}
			?>
		</td>
		<td <?php echo $td_style;?>>
		<?php echo $value->task_description; ?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		$task_assign = $this->db->where('task_list_id',$value->task_list_id)->get('task_assigned_admin')->result();
		if($task_assign){
			$myArray = array();
			foreach($task_assign as $row){
			    $result = DB::table('admin')->select('user_name','user_phone','user_email','admin_id')->where('admin_id',$row->admin_id)->first();
				$myArray[] = $result->user_name; 
			}
			echo implode( ', ', $myArray );
		} 
		?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		if($value->task_status == 3){
			$date = $value->task_status_complete_time;
			$datetime1 = new DateTime($date);//start time
			$datetime2 = new DateTime($value->task_start);//end time
			$interval = $datetime2->diff($datetime1);
			//echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');
			echo $interval->format('%dD, %HH, %iM');
		}else{
			$date = date('Y-m-d H:i:s');
			$datetime1 = new DateTime($date);//start time
			$datetime2 = new DateTime($value->task_start);//end time
			$interval = $datetime2->diff($datetime1);
			//echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');
			echo $interval->format('%dD, %HH, %iM');
		}
		?>
		</td>
		<td <?php echo $td_style;?>>
		<?php 
			if($value->task_status == 1){
				echo '<span class="label label-primary">Scheduled</span>';
			}elseif($value->task_status == 2){
				echo '<span class="label label-warning">Processing</span>';
			}elseif($value->task_status == 3){
				echo '<span class="label label-success">Complete</span>';
			}
			?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		$result = DB::table('admin')->select('user_name')->where('admin_id',$value->task_added_by_admin_id)->first();
		if($result){
		echo $result->user_name.'('.$value->task_added_by_admin_id.')'; 
		}
		?>
		</td>
	</tr>  
	<?php
			}
		}else{
	?>
	<tr>
		<td colspan="6">No Result Found</td>
	</tr>
	<?php 
		}
	?>
</table>
<?php 
if($task_complete){
?>
<h3 <?php echo $h3_style; ?>>Task Completed</h3>
<table cellpadding="0" cellspacing="0" <?php echo $table_style; ?>>
    <tr>
        <td <?php echo $th_style; ?>>#</td>
        <td <?php echo $th_style; ?>>Task Title</td>
        <td <?php echo $th_style; ?>>Task For</td>
        <td <?php echo $th_style; ?>>Description</td>
        <td <?php echo $th_style; ?>>Assigned</td>
        <td <?php echo $th_style; ?>>Time Left</td>
        <td <?php echo $th_style; ?>>Status</td>
        <td <?php echo $th_style; ?>>Created By</td>       
    </tr>
   <?php
		if(!empty($task_complete))
		{
			$i = 0;
			foreach($task_complete as $value)
			{
				$i++;
	?>
	<tr>
		<td <?php echo $td_style;?>><?php echo $i;?></td>
		<td <?php echo $td_style;?>>
		<?php echo ucwords($value->task_title).' ('.$value->task_list_id.')'; ?>
		</td>
		<td <?php echo $td_style;?>>
			<?php 
			if($value->task_for == 1 AND $value->client_id != 0){
				$result = $this->db->where('client_id',$value->client_id)->get('client')->row();
				if($result){
				echo $result->client_title.'(IL-C'.$value->client_id.')';
				}
			}else{
				echo $value->task_for_name;
			}
			?>
		</td>
		<td <?php echo $td_style;?>>
		<?php echo $value->task_description; ?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		$task_assign = DB::table('task_assigned_admin')->where('task_list_id',$value->task_list_id)->get();
		if($task_assign){
			$myArray = array();
			foreach($task_assign as $row){
				$result = DB::table('admin')->select('user_name','user_phone','user_email','admin_id')->where('admin_id',$row->admin_id)->first();
				$myArray[] = $result->user_name; 
			}
			echo implode( ', ', $myArray );
		} 
		?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		if($value->task_status == 3){
			$date = $value->task_status_complete_time;
			$datetime1 = new DateTime($date);//start time
			$datetime2 = new DateTime($value->task_start);//end time
			$interval = $datetime2->diff($datetime1);
			//echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');
			echo $interval->format('%dD, %HH, %iM');
		}else{
			$date = date('Y-m-d H:i:s');
			$datetime1 = new DateTime($date);//start time
			$datetime2 = new DateTime($value->task_start);//end time
			$interval = $datetime2->diff($datetime1);
			//echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');
			echo $interval->format('%dD, %HH, %iM');
		}
		?>
		</td>
		<td <?php echo $td_style;?>>
		<?php 
			if($value->task_status == 1){
				echo '<span class="label label-primary">Scheduled</span>';
			}elseif($value->task_status == 2){
				echo '<span class="label label-warning">Processing</span>';
			}elseif($value->task_status == 3){
				echo '<span class="label label-success">Complete</span>';
			}
			?>
		</td>
		<td <?php echo $td_style;?>>
		<?php
		$result = DB::table('admin')->select('user_name')->where('admin_id',$value->task_added_by_admin_id)->first();
		if($result){
		    echo $result->user_name.'('.$value->task_added_by_admin_id.')'; 
		}
		?>
		</td>
	</tr>  
	<?php
			}
		}else{
	?>
	<tr>
		<td colspan="6">No Result Found</td>
	</tr>
	<?php 
		}
	?>
</table>
<?php 
}
?>