<div class="container-fluid" style="">

	<div class="jumbotron">
		<div class="row">
			<div class="col-md-4 text-center align-self-center">
				<img class="image-responsive" src="<?php echo base_url($company['file_location'].$company['file_name']); ?>" style="max-height: 15rem; max-width: 15rem;">
			</div>
			<div class="col-md-8">
				<h1 class="display-4" id="cardName"><?php echo $company['name']; ?></h1>
				<p class="lead" id="cardProfile"><?php echo $company['profile']; ?></p>
				<hr class="my-4">
				<p id="cardPhone"><?php echo $company['phone']; ?></p>
				<p><a id="cardWebsite" target="_blank" href="<?php echo 'http://'.$company['website']; ?>"><?php echo $company['website']; ?></a></p>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col">
			<button onclick="printClaimReport()" type="button" class="btn btn-dark btn-round btn-sm pull-right" style="height:100px; width: 100%; ">
				<h5 class="card-title"><i class="fa fa-print"></i> Print</h5>
				<p class="card-text">Print OT Claim Cross Job Details Report.</p>
			</button>
		</div>
	</div>

	<section style="padding-top: 2rem; padding-bottom: 2rem;">
		<div class="card">
			<div class="card-body">
				<h4 class="card-title">OT Claim Cross Job Details Report</h4>
				<hr>
				<form id="filterForm">
					<div class="form-row">
						<div class="col">
							<label for="filter_department">Job Owner (Department)</label>
							<select name="filter_department" id="filter_department" class="form-control form-control-sm">
								<option value="">-- Please select --</option>  
                                    <?php if(!empty($department)) foreach($department as $row){
	                                    echo '<option value="'.$row['id'].'" ';
	                                    echo ($row['id'] == $filter_dept)?'selected':''; 
	                                    echo ' >'.$row['name'].' ['.$row['branch_name'].']</option>'; 
	                                }?>
                            </select>
						</div>
						<div class="col">
							<label for="filter_year">Submission Year</label>
							<select id="filter_year" type="text" class="form-control form-control-sm">
								<option value="" selected="selected">-- Please select --</option>
                                    <?php if($yearList) foreach($yearList as $row){
	                                    echo '<option value="'.$row->year.'" ';
	                                    echo ($row->year == $filter_year)?'selected':''; 
	                                    echo ' >'.$row->year.'</option>'; 
	                                }?>
							</select>
						</div>
						<div class="col">
							<label for="filter_month">Submission Month</label>
							<select id="filter_month" type="text" class="form-control form-control-sm">
								<option value="" selected="selected">-- Please select --</option>
		                            <?php if(!empty($month)) foreach ($month as $row){
	                                    echo '<option value="'. $row->id.'" ';
	                                    echo ($row->id == $filter_month)?'selected':''; 
	                                    echo ' >'. $row->month.'</option>'; 
	                                }?>
							</select>
						</div>
						<div class="col">
							<label for="filter_submit"><br></label>
							<button type="button" class="btn btn-primary btn-sm btn-block" id="filter_submit" name="filter_submit" onclick="filterReport()"><i class="fas fa-search"></i> Submit</button>
						</div>
					</div>
				</form>
				<br><hr>
				<div class="table-responsive">
					<table id="table_CrossJobClaimReport" class="table table-hover table-bordered">
						<thead>
							<tr>
								<th class="text-center">#</th>
								<th class="text-center">Job Owner (Department)</th>
                                <th class="text-center">Total (RM)</th>
								<th class="text-center">Converted to AL</th> 
							</tr>
						</thead>
						<tbody>
							<?php 
								$i = 1;
								if($cross_job_dept) foreach($cross_job_dept as $row) { ?>
									<tr>
										<td scope="row" class="text-center"><?php echo $i; ?></td>
										<td><b><?php echo $row->job_deptName; ?> - <?php echo $row->job_branchName; ?></b>
											<?php 
												$cross_job_details = $this->model_ot->getSummaryCrossJOb($row->svDeptID,$row->month,$row->year); //echo $this->db->last_query();
												$j = 1;
												if($cross_job_details) foreach($cross_job_details as $row_det) { ?>
													<a href="<?php echo base_url('hr/overtime/adminOtList/'.$row_det['otID'].'/'.$row_det['peopleID'])?>" target="_blank"><br><small><?php echo $j; ?>. <?php echo $row_det['staffName']; ?> 
													[<?php echo $row_det['staff_deptName']; ?> - <?php echo $row_det['staff_branchName']; ?>] <i>Submission : <?php echo $row_det['month']; ?>, <?php echo $row_det['year']; ?></i></small></a>
											<?php $j++; } ?>
										</td>
										<td class="text-right">
											<?php $cross_job_details = $this->model_ot->getSummaryCrossJOb($row->svDeptID,$row->month,$row->year);
												if($cross_job_details) foreach($cross_job_details as $row_det) { ?>
													<?php $sum = 0; ?>
													<?php if($row_det['basic_pay'] <= 2000 && $row_det['position'] == 'Trainee'){ ?>
														<?php 
			                                                if(!empty($row_det['totalHoursApproved'])){ $row_det['totalHoursApproved'] = $row_det['totalHoursApproved']; } else { $row_det['totalHoursApproved'] = 0; };

		                                                    $totalClaim = $row_det['totalHoursApproved']*6; //trainee fix rate

		                                                    if(!empty($row_det['NormalMeal'])){ $row_det['NormalMeal'] = $row_det['NormalMeal']; } else { $row_det['NormalMeal'] = 0; };
		                                                    if(!empty($row_det['RestMeal'])){ $row_det['RestMeal']     = $row_det['RestMeal']; } else { $row_det['RestMeal'] = 0; };
		                                                    if(!empty($row_det['PublicMeal'])){ $row_det['PublicMeal'] = $row_det['PublicMeal']; } else { $row_det['PublicMeal'] = 0; };

		                                                    if($row_det['NormalMeal'] > 0){
		                                                        $NormalMeal = $row_det['NormalMeal']*5;
		                                                    }else{
		                                                         $NormalMeal = 0;
		                                                    }
		                                                    if($row_det['RestMeal'] > 0){
		                                                        $RestMeal = $row_det['RestMeal']*10;
		                                                    }else{
		                                                        $RestMeal = 0;
		                                                    }
		                                                    if($row_det['PublicMeal'] > 0){
		                                                        $PublicMeal = $row_det['PublicMeal']*10;
		                                                    }else{
		                                                        $PublicMeal = 0;
		                                                    }

		                                                    $totalMeal = $NormalMeal + $RestMeal + $PublicMeal;

		                                                    $totalDept = $totalClaim + $totalMeal;

		                                                    $sum+=$totalDept;

			                                            ?>
													<?php } else if(!empty($row_det['basic_pay']) && $row_det['basic_pay'] <= 2000){ ?>
														<?php 
		                                                    if(!empty($row_det['totalHoursApproved'])){ $row_det['totalHoursApproved'] = $row_det['totalHoursApproved']; } else { $row_det['totalHoursApproved'] = 0; };

		                                                    if(!empty($row_det['NormalMeal'])){ $row_det['NormalMeal'] = $row_det['NormalMeal']; } else { $row_det['NormalMeal'] = 0; };
		                                                    if(!empty($row_det['RestMeal'])){ $row_det['RestMeal']     = $row_det['RestMeal']; } else { $row_det['RestMeal'] = 0; };
		                                                    if(!empty($row_det['PublicMeal'])){ $row_det['PublicMeal'] = $row_det['PublicMeal']; } else { $row_det['PublicMeal'] = 0; };

		                                                    if(!empty($row_det['Normal'])){ $row_det['Normal'] = $row_det['Normal']; } else { $row_det['Normal'] = 0; };
		                                                    if(!empty($row_det['Rest'])){ $row_det['Rest']     = $row_det['Rest']; } else { $row_det['Rest'] = 0; };
		                                                    if(!empty($row_det['Public'])){ $row_det['Public'] = $row_det['Public']; } else { $row_det['Public'] = 0; };

		                                                    if($row_det['NormalMeal'] > 0){
		                                                        $NormalMeal = $row_det['NormalMeal']*5;
		                                                    }else{
		                                                         $NormalMeal = 0;
		                                                    }
		                                                    if($row_det['RestMeal'] > 0){
		                                                        $RestMeal = $row_det['RestMeal']*10;
		                                                    }else{
		                                                        $RestMeal = 0;
		                                                    }
		                                                    if($row_det['PublicMeal'] > 0){
		                                                        $PublicMeal = $row_det['PublicMeal']*10;
		                                                    }else{
		                                                        $PublicMeal = 0;
		                                                    }

		                                                    $totalMeal = $NormalMeal + $RestMeal + $PublicMeal;

		                                                    if($row_det['Normal'] > 0){
		                                                        $normalDayTotal = $row_det['basic_pay']/208*1.5*$row_det['Normal'];
		                                                    }else{
		                                                        $normalDayTotal = 0;
		                                                    }
		                                                    if($row_det['Rest'] > 0){
		                                                        $restDayTotal   = $row_det['basic_pay']/208*2.0*$row_det['Rest'];
		                                                    }else{
		                                                        $restDayTotal   = 0;
		                                                    }
		                                                    if($row_det['Public'] > 0){
		                                                        $publicDayTotal = $row_det['basic_pay']/208*3.0*$row_det['Public'];
		                                                    }else{
		                                                        $publicDayTotal = 0;
		                                                    }

		                                                    $totalClaim = $normalDayTotal+$restDayTotal+$publicDayTotal; 

		                                                    $totalDept = $totalClaim + $totalMeal;

		                                                    $sum+=$totalDept;
		                                                ?>
													<?php } else if($row_det['basic_pay'] > 2000){ ?>
		                                                <?php 
		                                                    if(!empty($row_det['totalHoursApproved'])){ $row_det['totalHoursApproved'] = $row_det['totalHoursApproved']; } else { $row_det['totalHoursApproved'] = 0; };

		                                                    $totalClaim = $row_det['totalHoursApproved']*10;

		                                                    if(!empty($row_det['NormalMeal'])){ $row_det['NormalMeal'] = $row_det['NormalMeal']; } else { $row_det['NormalMeal'] = 0; };
		                                                    if(!empty($row_det['RestMeal'])){ $row_det['RestMeal']     = $row_det['RestMeal']; } else { $row_det['RestMeal'] = 0; };
		                                                    if(!empty($row_det['PublicMeal'])){ $row_det['PublicMeal'] = $row_det['PublicMeal']; } else { $row_det['PublicMeal'] = 0; };

		                                                    if($row_det['NormalMeal'] > 0){
		                                                        $NormalMeal = $row_det['NormalMeal']*5;
		                                                    }else{
		                                                         $NormalMeal = 0;
		                                                    }
		                                                    if($row_det['RestMeal'] > 0){
		                                                        $RestMeal = $row_det['RestMeal']*10;
		                                                    }else{
		                                                        $RestMeal = 0;
		                                                    }
		                                                    if($row_det['PublicMeal'] > 0){
		                                                        $PublicMeal = $row_det['PublicMeal']*10;
		                                                    }else{
		                                                        $PublicMeal = 0;
		                                                    }

		                                                    $totalMeal = $NormalMeal + $RestMeal + $PublicMeal;

		                                                    $totalDept = $totalClaim + $totalMeal;

		                                                    $sum+=$totalDept;

		                                                ?>
													<?php } ?>
													<br><small><?php echo number_format((float)$totalDept, 2, '.', ''); ?></small>
												<?php } ?>
                                        </td>
										<td class="text-center">
											<?php 
												$cross_job_details = $this->model_ot->getSummaryCrossJOb($row->svDeptID,$row->month,$row->year);  
												if($cross_job_details) foreach($cross_job_details as $row_det) { ?>
													<br><small><?php echo $row_det['convertAL']; ?></small>
											<?php } ?>
										</td>
									</tr>
								<?php
	                            $i++;
	                        } ?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</section>
</div>

<script type="text/javascript">

    function filterReport()
    {

        if($('#filter_department').val() == ""){ 
			var department = "ALL"; 
		} else { 
			var department = $('#filter_department').val(); 
		};

		if($('#filter_month').val() == ""){ 
			var month = "ALL"; 
		} else { 
			var month = $('#filter_month').val(); 
		};

		if($('#filter_year').val() == ""){ 
			var year = "ALL"; 
		} else { 
			var year = $('#filter_year').val(); 
		};

       location.replace("<?php echo base_url().'hr/Overtime_report/crossJobReport/'?>" + department + "/" + month + "/" + year);
    }

    function printClaimReport()
	{
		if($('#filter_department').val() == ""){ 
			var department = "ALL"; 
		} else { 
			var department = $('#filter_department').val(); 
		};

		if($('#filter_month').val() == ""){ 
			var month = "ALL"; 
		} else { 
			var month = $('#filter_month').val(); 
		};

		if($('#filter_year').val() == ""){ 
			var year = "ALL"; 
		} else { 
			var year = $('#filter_year').val(); 
		};


		window.open("<?php echo base_url().'hr/Overtime_report/printCrossJobReport/'?>" + department + "/" + month + "/" + year, "_blank");
	}

</script>