<?php
$punch_in = "2019-07-01 09:00:00";
$punch_out = "2019-07-01 18:00:00";
$in_threshold = "2019-07-01 08:15:00";
$out_threshold = "2019-07-01 17:15:00";
$exact_in_threshold = "2019-07-01 08:00:00";
$exact_out_threshold = "2019-07-01 17:00:00";
function generateAttendance( $punch_in, $punch_out , $in_threshold, $out_threshold , $exact_in_threshold, $exact_out_threshold){
$lates = 0;
$overtime = 0;
// If punch_in is late = punch_in and late + 1
if ($punch_in > $in_threshold) {
$start = $punch_in;
$lates = +1;
}
// If punch_in is early = exact_time
else {
$start = $exact_in_threshold;
}
// If punch_out is early = punch_out
if ($punch_out < $out_threshold) {
$end = $punch_out;
}
// If pucn_out is overtime = exact_end and overtime + 1
else {
$end = $exact_out_threshold;
$overtime =1;
}
// If both punch in and punch_out is within threshold
if ((( $exact_in_threshold >= $in_threshold ) && ( $exact_in_threshold <= $punch_in ))
&& (( $exact_out_threshold >= $out_threshold ) && ( $exact_out_threshold <= $punch_out ))) {
$start = $punch_in;
$end = $punch_out;
}
// If punch_in is within threshold, start = punch_in and end = exact_end
else if ((( $exact_in_threshold >= $in_threshold ) && ( $exact_in_threshold <= $punch_in )) && $punch_out > $out_threshold) {
$start = $punch_in;
$end = $exact_out_threshold;
}
return array('start' => $start, 'end' => $end, 'lates' => $lates, 'overtime' => $overtime);
}
$result = generateAttendance( $punch_in, $punch_out , $in_threshold, $out_threshold , $exact_in_threshold, $exact_out_threshold);
print_r($result);
preferences:
28.58 ms | 402 KiB | 5 Q