Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $attendance = [
- "2019-07-01 08:03:00",
- "2019-07-01 12:12:00",
- "2019-07-01 13:03:00",
- "2019-07-01 17:00:00",
- ];
- $schedules = [
- [
- "time_start" => "08:00:00",
- "time_end" => "12:00:00",
- "in_threshold" => 15,
- "out_threshold" => 15
- ],
- [
- "time_start" => "13:00:00",
- "time_end" => "17:00:00",
- "in_threshold" => 15,
- "out_threshold" => 15
- ]
- ];
- foreach($schedules as $schedule){
- // Set time_start and time_end with threshold
- $mytime_start[] = date( "H:i:s",
- strtotime('+'. $schedule[ 'in_threshold' ] .' minutes',
- strtotime ( $schedule[ 'time_start' ]
- )));
- $mytime_end[] = date( "H:i:s",
- strtotime('+'. $schedule[ 'out_threshold' ] .' minutes',
- strtotime( $schedule[ 'time_end' ]
- )));
- // Get time_start and time_end to array
- $sched_starts[] = ( $schedule[ 'time_start' ] );
- $sched_ends[] = ( $schedule[ 'time_end' ] );
- }
- function getClosestTime( $array, $date ){
- foreach( $array as $day ){
- $interval[] = abs(strtotime($date) - strtotime($day));
- }
- asort($interval);
- $closest = key($interval);
- return $array[$closest];
- }
- for ($index = 0; $index < count($attendance); $index += 2)
- $date_start = $attendance[$index]; // Punch In
- $date_end = $attendance[$index + 1]; // Punch Out
- $to_date_start = date("Y-m-d", strtotime($date_start));
- $to_date_end = date("Y-m-d", strtotime($date_end));
- $time_start = getClosestTime($mytime_start, date('H:i:s',strtotime($date_start)));
- $time_end = getClosestTime($mytime_end, date('H:i:s',strtotime($date_end)));
- if ($time_start > $time_end) {
- $time_start = date("Y-m-d", strtotime($date_start));
- }
- $time_start = date('Y-m-d H:i:s', strtotime("$to_date_start $time_start"));
- $time_end = date('Y-m-d H:i:s', strtotime("$to_date_end $time_end"));
- $time_minus_start = date("Y-m-d H:i:s", strtotime("-15 minutes $time_start"));
- $time_minus_end = date("Y-m-d H:i:s", strtotime("-15 minutes $time_end"));
- if ($date_start > $time_start) {
- $start = $late;
- $total_late += 1;
- }else {
- $start = $exact_in;
- }
- if (isBetween($time_minus_start, $time_start, $date_start)
- && isBetween($time_minus_end, $time_end, $date_end)) {
- $start = $within_in;
- $end = $within_out;
- } else if (isBetween($time_minus_start, $time_start, $date_start) && $date_end > $time_end) {
- $start = $within_in;
- $end = $late_out;
- }
- $total_garner_hours += ($end - $start);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement