ID date_in time_in time_out
1 2017-05-04 8.10 16.20
1 2017-05-05 6.10 12.20
5 2017-05-04 9.30 16.22
5 2017-05-05 8.20 16.23
....
我希望每个员工获得搜索月份的小时数并打印报告,并且我使用dompdf进行报告。我想要的输出报告是:
ID Name Total OTHours
1 John 14.20
5 Smith 22.20
我使用以下代码。但是,不工作的小时和pdf文件的总和不起作用。请有人帮我找到解决方案???
$query = "
SELECT * FROM employee_personal_details e
INNER JOIN attendance_details a ON e.emp_id = a.emp_id
WHERE MONTH(a.date_in) = '$monthSearch'
GROUP BY e.emp_id ";
$result = mysqli_query($connect, $query);
$output = "
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Total OT Hours</th>
</tr>
";
while($row = mysqli_fetch_array($result)){
$output .= '
<tr>
<td>'.$row["emp_id"].'</td>
<td>'.$row["emp_fullName"].'</td>';
//calculate the time difference
$datetime1 = new DateTime($row['time_out']);
$datetime2 = new DateTime($row['time_in']);
$interval = $datetime1->diff($datetime2);
$workedHours = $interval->format('%h'.'.'.'%I');
//expected hours
$expectedHour=8;
//calculate the ot hours
$ot = $workedHours-$expectedHour;
if($ot>0.3){
$sumot += $ot;
}
$output .= '
<td>'.$sumot.'</td>
</tr>
';
}
$output .= '</table>';
//echo $output;
$dompdf->loadHtml($output);