if ('Regular holiday' === $getHolidayByDate[0]->holiday_type) { echo 'Regular holiday'; $employeeNightDiffClocking->total_overtime_1 = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); $employeeSummaryNightDiffClocking->legal_holiday_overtime = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); } elseif ('Special non-working day' === $getHolidayByDate[0]->holiday_type) { echo 'Special non-working day'; $employeeNightDiffClocking->total_overtime_1 = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); $employeeSummaryNightDiffClocking->special_holiday_overtime = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); } } else { $employeeNightDiffClocking->total_overtime_1 = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); $employeeSummaryNightDiffClocking->regular_overtime = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); } //REST DAY: RD OT } else { $todayTotalWorkHours = strtotime(getTimeDiff($workShift['start_time'], $workShift['end_time'])); //decimalToTimeFormat($employeeNightDiffClocking->total_hours_1); //LEGAL Holiday OT/RD SPL Holiday OT //Exceed the first 8 hours if (strtotime($employeeNightDiffClocking->total_hours_1) > $todayTotalWorkHours) { if (!empty($getHolidayByDate[0]->holiday_type)) { if ('Regular holiday' === $getHolidayByDate[0]->holiday_type) { //echo 'Regular holiday'; $employeeNightDiffClocking->total_overtime_1 = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); $employeeSummaryNightDiffClocking->rest_day_legal_holiday_overtime = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); } elseif ('Special non-working day' === $getHolidayByDate[0]->holiday_type) { //echo 'Special non-working day'; $employeeNightDiffClocking->total_overtime_1 = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); $employeeSummaryNightDiffClocking->rest_day_special_holiday_overtime = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time); } } else {
function getTotalHours($clockingIn, $clockingOut, $hasOvertime = false, $overTime = '', $output = "") { $clocking['in'] = $clockingIn; $clocking['out'] = $clockingOut; //$hasOvertime = true; //$overTime = '02:00:00'; $overTimeArr = explode(':', $overTime); getTimeDiff($clocking['out'], $clocking['in']); $timeArr1 = explode(':', getTimeDiff($clocking['out'], $clocking['in'])); if ($timeArr1[0] !== '00' && $timeArr1[1] !== '00') { if (!$hasOvertime) { $totalHours = $timeArr1[0] + $overTime + $timeArr1[1] / 60 + $timeArr1[2] / 3600; $totalHours = number_format($totalHours, 2); /* echo 'Decimal Time Format: '. number_format($totalHours, 2); echo '<br />'; echo 'Decimal Minute Format: '. decimalMinutesFormat(decimalTimeToTimeFormat($totalHours)); echo '<br />'; echo 'Time Format: '. date('H:i', strtotime(decimalTimeToTimeFormat($totalHours))); */ switch ($output) { case 'decimal time': //Decimal Time Format return number_format($totalHours, 2); break; case 'decimal minutes': //Decimal Minute Format return decimalMinutesFormat($totalHours); break; default: //Time Format return date('H:i', strtotime($totalHours)); break; } } else { $totalHours = $timeArr1[0] + $overTimeArr[0] + ($timeArr1[1] + $overTimeArr[1]) / 60 + ($timeArr1[2] + $overTimeArr[2]) / 3600; $totalHours = number_format($totalHours, 2); /* echo 'Decimal Time: '. number_format($totalHours, 2); echo '<br />'; echo 'Decimal Minute Format: '. decimalMinutesFormat(decimalTimeToTimeFormat($totalHours)); echo '<br />'; echo 'Time Format: '. date('H:i', strtotime(decimalTimeToTimeFormat($totalHours))); */ switch ($output) { case 'decimal time': //Decimal Time Format return number_format($totalHours, 2); break; case 'decimal minutes': //Decimal Minute Format return decimalMinutesFormat($totalHours); break; default: //Time Format return date('H:i', strtotime($totalHours)); break; } } } }
return writeJson($response, array('ID' => $args['id'], 'RESPONSE' => $db->addJSONLibrePosts($args['id'], $request->getParsedBody()['data']))); }); $app->get('/post_cgm/{id}', function ($request, $response, $args) use($app, $db) { return writeJson($response, $db->getCGMPosts($args['id'])); }); $app->get('/post/comments/{id}', function ($request, $response, $args) use($app, $db) { $posts = $db->getPost($args['id']); $query = $request->getQueryParams(); $result = array(); $nextIndex = 1; foreach ($posts['POST'] as $post_row) { $comment = $post_row["COMMENT"]; foreach ($query as $item) { if (strlen($comment) > 1 && stripos(strtolower($comment), $item) !== false) { if (!empty($posts['POST'][$nextIndex])) { $diffMillis = getTimeDiff($posts['POST'][$nextIndex]["TIME"], $post_row["TIME"]); $pair = array("MEAL" => $post_row, "AFTER" => array("POST" => $posts['POST'][$nextIndex], "TIME_DIFF" => $diffMillis)); array_push($result, $pair); } } } $nextIndex++; } return writeJson($response, $result); }); $app->get('/post/{id}', function ($request, $response, $args) use($app, $db) { return writeJson($response, $db->getPost($args['id'])); }); $app->get('/users/{id}', function ($request, $response, $args) use($app, $db) { return writeJson($response, $db->getUsers($args['id'])); });
function getTotalHours($clockingIn, $clockingOut, $hasOvertime = false, $overTime = '', $output = "") { $clocking['in'] = $clockingIn; $clocking['out'] = $clockingOut; if (!empty($overTime)) { // start by converting to seconds $seconds = (int) ($overTime * 3600); // we're given hours, so let's get those the easy way $hours = floor($overTime); // since we've "calculated" hours, let's remove them from the seconds variable $seconds -= $hours * 3600; // calculate minutes left $minutes = floor($seconds / 60); // remove those from seconds as well $seconds -= $minutes * 60; // return the time formatted HH:MM:SS //return lz($hours).":".lz($minutes).":".lz($seconds); $format = '%s:%s:%s'; $overTime = sprintf($format, $hours, $minutes, $seconds); } //$hasOvertime = true; //$overTime = '02:00:00'; $overTimeArr = explode(':', $overTime); //getTimeDiff($clocking['out'], $clocking['in']); $timeArr1 = explode(':', getTimeDiff($clocking['out'], $clocking['in'])); if ($timeArr1[0] !== '' && $timeArr1[1] !== '') { if (!$hasOvertime) { $totalHours = $timeArr1[0] + $overTime + $timeArr1[1] / 60 + $timeArr1[2] / 3600; } else { $totalHours = $timeArr1[0] + $overTimeArr[0] + ($timeArr1[1] + $overTimeArr[1]) / 60 + ($timeArr1[2] + $overTimeArr[2]) / 3600; } $totalHours = number_format($totalHours, 2); /*switch ($output) { case 'decimal time': //Decimal Time Format return number_format($totalHours, 2); break; case 'decimal minutes': //Decimal Minute Format return decimalMinutesFormat($totalHours); break; default: //Time Format return date('H:i', strtotime($totalHours)); break; }*/ /*$hh = date('H', strtotime($totalHours)); $mm = date('i', strtotime($totalHours)); $ss = date('s', strtotime($totalHours)); $format = '%s:%s:%s'; return sprintf( $format, $hh, $mm, $ss ); //return $totalHours; */ return $totalHours; } }
function updateTraveltime($userID, $currentStation, $timestamp, $db) { $prevStation = getPreviousStation($userID, $timestamp, $db); $edge = getEdge($prevStation, $currentStation); $timeDiff = getTimeDiff($userID, $timestamp, $db); //echo "timeDiff = $timeDiff \n"; if ($prevStation != -1 && $currentStation == nextStation($userID, $prevStation)) { // correctly enter station insertTravelTimeDataIfNotExist($edge, $prevStation, $currentStation, $timestamp, $db); $query = "SELECT * FROM traveltimeData WHERE edge = '{$edge}'"; $data = $db->query($query)->fetchAll(); if ($timeDiff < 3600) { $newSum = $data[0]["sum"] + $timeDiff; $newCount = $data[0]["count"] + 1; } else { $newSum = $data[0]["sum"]; $newCount = $data[0]["count"]; } $query = "UPDATE traveltimeData SET sum = '{$newSum}',count = '{$newCount}' WHERE edge = '{$edge}'"; $db->exec($query); $query = "INSERT INTO traveltime (userID,timestamp,edge,traveltime) VALUES ('{$userID}','{$timestamp}','{$edge}','{$timeDiff}')"; $db->exec($query); } $query = "UPDATE state SET station = '{$currentStation}', timestamp = '{$timestamp}' WHERE userID = '{$userID}'; "; $db->exec($query); }