Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. $attendance = [
  2. "2019-07-01 08:03:00",
  3. "2019-07-01 12:12:00",
  4. "2019-07-01 13:03:00",
  5. "2019-07-01 17:00:00",
  6. ];
  7.  
  8. $schedules = [
  9. [
  10. "time_start" => "08:00:00",
  11. "time_end" => "12:00:00",
  12. "in_threshold" => 15,
  13. "out_threshold" => 15
  14. ],
  15. [
  16. "time_start" => "13:00:00",
  17. "time_end" => "17:00:00",
  18. "in_threshold" => 15,
  19. "out_threshold" => 15
  20. ]
  21. ];
  22.  
  23. foreach($schedules as $schedule){
  24.  
  25. // Set time_start and time_end with threshold
  26. $mytime_start[] = date( "H:i:s",
  27. strtotime('+'. $schedule[ 'in_threshold' ] .' minutes',
  28. strtotime ( $schedule[ 'time_start' ]
  29. )));
  30. $mytime_end[] = date( "H:i:s",
  31. strtotime('+'. $schedule[ 'out_threshold' ] .' minutes',
  32. strtotime( $schedule[ 'time_end' ]
  33. )));
  34. // Get time_start and time_end to array
  35. $sched_starts[] = ( $schedule[ 'time_start' ] );
  36. $sched_ends[] = ( $schedule[ 'time_end' ] );
  37. }
  38.  
  39. function getClosestTime( $array, $date ){
  40. foreach( $array as $day ){
  41. $interval[] = abs(strtotime($date) - strtotime($day));
  42.  
  43. }
  44. asort($interval);
  45. $closest = key($interval);
  46.  
  47. return $array[$closest];
  48. }
  49.  
  50. for ($index = 0; $index < count($attendance); $index += 2)
  51.  
  52. $date_start = $attendance[$index]; // Punch In
  53. $date_end = $attendance[$index + 1]; // Punch Out
  54.  
  55. $to_date_start = date("Y-m-d", strtotime($date_start));
  56. $to_date_end = date("Y-m-d", strtotime($date_end));
  57.  
  58. $time_start = getClosestTime($mytime_start, date('H:i:s',strtotime($date_start)));
  59. $time_end = getClosestTime($mytime_end, date('H:i:s',strtotime($date_end)));
  60.  
  61. if ($time_start > $time_end) {
  62. $time_start = date("Y-m-d", strtotime($date_start));
  63. }
  64.  
  65. $time_start = date('Y-m-d H:i:s', strtotime("$to_date_start $time_start"));
  66. $time_end = date('Y-m-d H:i:s', strtotime("$to_date_end $time_end"));
  67.  
  68. $time_minus_start = date("Y-m-d H:i:s", strtotime("-15 minutes $time_start"));
  69. $time_minus_end = date("Y-m-d H:i:s", strtotime("-15 minutes $time_end"));
  70.  
  71. if ($date_start > $time_start) {
  72. $start = $late;
  73. $total_late += 1;
  74.  
  75. }else {
  76. $start = $exact_in;
  77. }
  78.  
  79. if (isBetween($time_minus_start, $time_start, $date_start)
  80. && isBetween($time_minus_end, $time_end, $date_end)) {
  81. $start = $within_in;
  82. $end = $within_out;
  83.  
  84. } else if (isBetween($time_minus_start, $time_start, $date_start) && $date_end > $time_end) {
  85. $start = $within_in;
  86. $end = $late_out;
  87. }
  88.  
  89. $total_garner_hours += ($end - $start);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement