/*
 /echo "\n";
 echo $clockingInDateTime = date('Y-m-d H:i:s', strtotime($employeeNightDiffClocking->time_in_1));
 echo "\n";
 echo $clockingOutDateTime = date('Y-m-d H:i:s', strtotime($getClockingDateTime));								
 echo "\n";
 
 echo "\n";
 echo $clockingIn;
 echo "\n";
 echo $clockingOut;
 echo "\n";
 */
 $overTime = getOvertimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time);
 $employeeNightDiffClocking->total_hours_1 = getTotalHours($clockingIn, $clockingOut, $hasOvertime, $overTime);
 $employeeNightDiffClocking->work_hours_1 = getWorkHours($clockingIn, $clockingOut, $hasBreak, $breakTime);
 $employeeNightDiffClocking->undertime_1 = getUnderTimeHours($clockingIn, $clockingOut, $getWorkShift[0]->start_time, $getWorkShift[0]->end_time, true, $breakTime);
 //$workShift['rest_day'] = explode(', ', $getWorkShift[0]->rest_day);
 //REGULAR DAY: Reg OT
 if (!in_array($clockingInDay, $workShift['rest_day']) && !in_array($clockingOutDay, $workShift['rest_day'])) {
     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->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 {
 public function adminTimesheetSave()
 {
     //value, id, row_id, column
     $data = Input::all();
     //	return dd($data);
     if (Request::ajax()) {
         //General Settings
         $nightDiff['from'] = strtotime('22:00');
         $nightDiff['to'] = strtotime('06:00');
         $hasNightDiff = false;
         //$dayOfTheWeek = date('l');
         $breakTime = date('H:i:s', strtotime('01:00:00'));
         $getTimesheet = Timesheet::where('id', (int) trim($data["row_id"]))->first();
         //in-out 1
         if ((int) $data["column"] === 3) {
             //var_dump($data["value"]);
             if (!empty($data["value"])) {
                 $dataValueArr = explode('-', $data["value"]);
                 /*return dd(getTardinessTime($clockingIn, $shiftStart));
                 		exit;*/
                 if (!empty($dataValueArr)) {
                     //UPDARTED TIME IN AND TIME OUT
                     $clockingIn = trim($dataValueArr[0]);
                     $clockingOut = trim($dataValueArr[1]);
                     $timesheetId = $getTimesheet->id;
                     $employeeId = $getTimesheet->employee_id;
                     $clockingStatus = $getTimesheet->clocking_status;
                     $shiftStart = $getTimesheet->schedule_in;
                     $shiftEnd = $getTimesheet->schedule_out;
                     //$scheduleIn = $getTimesheet->schedule_in;
                     //$scheduleOut = $getTimesheet->schedule_out;
                     $dayDate = $getTimesheet->daydate;
                     $tardiness = $getTimesheet->tardiness_1;
                     //don't forget clocking status
                     //check schedule
                     //General Settings
                     //$nightDiff['from'] = strtotime('22:00:00');
                     //$nightDiff['to'] = strtotime('06:00:00');
                     $timeInDateTime = date('G', strtotime($clockingIn));
                     $timeOutDateTime = date('G', strtotime($clockingOut));
                     //$clockingIn =  date( 'Y-m-d', strtotime($dayDate) ).' '.date( 'H:i:s', strtotime($clockingIn) );
                     //$clockingOut =  date( 'Y-m-d', strtotime($dayDate) ).' '.date( 'H:i:s', strtotime($clockingOut) );
                     //e.g clockingIn result should be: 2015-05-15 15:30:13
                     //$hour >= 21 && $hour <= 4
                     //date('G', strtotime($nightDiff['from']))
                     //$clockingIn =  date( 'Y-m-d', strtotime($dayDate) ).' '.date( 'H:i:s', strtotime($clockingIn) );
                     //$clockingOut =  date( 'Y-m-d', strtotime($dayDate) ).' '.date( 'H:i:s', strtotime($clockingOut) );
                     //CHECK IF NIGHT DIFF TRUE
                     if (date('G', strtotime($shiftStart)) >= date('G', strtotime($nightDiff['from'])) && date('G', strtotime($shiftEnd)) <= date('G', strtotime($nightDiff['to']))) {
                         //echo 'DEBUG.IO';
                         if ($timeInDateTime < 24 && $timeInDateTime < date('G', strtotime($nightDiff['from']))) {
                             $clockingIn = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($clockingIn));
                             //$clockingIn =  date( 'Y-m-d', strtotime($dayDate) ).' '.date( 'H:i:s', strtotime($clockingIn) );
                         } else {
                             $clockingIn = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($clockingIn));
                         }
                         if ($timeOutDateTime < 24 && $timeOutDateTime < date('G', strtotime($nightDiff['to']))) {
                             $clockingOut = date('Y-m-d', strtotime($dayDate . '1 day')) . ' ' . date('H:i:s', strtotime($clockingOut));
                         } else {
                             $clockingOut = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($clockingOut));
                         }
                     } else {
                         $clockingIn = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($clockingIn));
                         $clockingOut = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($clockingOut));
                     }
                     $dayOfTheWeek = date('l', strtotime($dayDate));
                     $shift = 1;
                     $schedule = new Schedule();
                     //$getSchedule = $schedule->getSchedule($employeeId, $employeeClocking->daydate);
                     $getSchedule = DB::table('employee_schedule')->where('employee_id', $employeeId)->where('schedule_date', trim($dayDate))->first();
                     $workShift = new Workshift();
                     //$getWorkShiftByDayOfTheWeek = $workShift->getWorkShiftByDayOfTheWeek($employeeId, date('l', strtotime($employeeClocking->daydate)), $overtime->shift);
                     $getWorkShiftByDayOfTheWeek = DB::table('work_shift')->where('employee_id', $employeeId)->where('name_of_day', date('l', strtotime($dayDate)))->where('shift', $shift)->first();
                     if (!empty($getSchedule)) {
                         //$scheduled['start_time'] = $getSchedule[0]->start_time;
                         //$scheduled['end_time'] = $getSchedule[0]->end_time;
                         $scheduled['rest_day'] = $getSchedule->rest_day;
                     } elseif (!empty($getWorkShiftByDayOfTheWeek)) {
                         // From 01:00:00 change to 2015-04-30 09:00:00
                         //$scheduled['start_time'] = date( 'Y-m-d', strtotime($employeeClocking[0]->time_in_1) ).' '.
                         // From 01:00:00 change to 2015-04-30 01:00:00
                         //$scheduled['end_time'] =  date( 'Y-m-d', strtotime($clockingDateTime) ).' '.
                         $scheduled['rest_day'] = $getWorkShiftByDayOfTheWeek->rest_day;
                     }
                     $holiday = DB::table('holiday')->where('date', trim($dayDate))->first();
                     //dd($holiday);
                     $overtime = DB::table('overtime')->where('employee_id', $employeeId)->where('timesheet_id', $timesheetId)->where('seq_no', 1)->where('shift', 1)->where('overtime_status', 1)->get();
                     //dd($overtime);
                     //CHECK IF HAS NIGHTDIFF
                     if (strtotime($clockingIn) >= $nightDiff['from'] || strtotime($clockingOut) <= $nightDiff['to']) {
                         $hasNightDiff = true;
                     }
                     if (strtotime(date('H:i', strtotime($clockingIn))) === strtotime(date('H:i', strtotime($shiftStart))) && strtotime(date('H:i', strtotime($clockingOut))) === strtotime(date('H:i', strtotime($shiftEnd)))) {
                         DB::table('employee_timesheet')->where('id', $timesheetId)->update(array('time_in_1' => trim($clockingIn), 'time_out_1' => trim($clockingOut), 'tardiness_1' => '', 'undertime_1' => '', 'total_overtime_1' => '', 'overtime_status_1' => 'NULL'));
                         //Todo: update overtime table
                         DB::table('overtime')->where('employee_id', $employeeId)->where('timesheet_id', $timesheetId)->where('seq_no', 1)->where('shift', 1)->update(array('overtime_status' => 'NULL'));
                     }
                     //TARDINESS/LATES
                     if (strtotime($clockingIn) > strtotime($shiftStart)) {
                         $tardinessTime = getTardinessTime($clockingIn, $shiftStart);
                         DB::table('employee_timesheet')->where('id', $timesheetId)->update(array('time_in_1' => trim($clockingIn), 'time_out_1' => trim($clockingOut), 'tardiness_1' => $tardinessTime, 'total_overtime_1' => '', 'overtime_status_1' => 'NULL'));
                         //Todo: update overtime table
                         DB::table('overtime')->where('employee_id', $employeeId)->where('timesheet_id', $timesheetId)->where('seq_no', 1)->where('shift', 1)->update(array('overtime_status' => 'NULL'));
                         DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('lates' => $tardinessTime));
                         $getUpdatedTimesheet = Timesheet::where('id', (int) trim($timesheetId))->first();
                     } else {
                         DB::table('employee_timesheet')->where('id', $timesheetId)->update(array('time_in_1' => trim($clockingIn), 'time_out_1' => trim($clockingOut), 'tardiness_1' => ''));
                         DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('lates' => ''));
                     }
                     //dd($getUpdatedTimesheet);
                     if (!empty($getUpdatedTimesheet)) {
                         //LATE/TARDINESS: TRUE
                         if (!empty($getUpdatedTimesheet->tardiness_1)) {
                             //echo "LATE/TARDINESS: TRUE \n";
                             //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                             $workHours = getWorkHours($clockingIn, $clockingOut, $shiftEnd);
                             //TODO: Compute total hours with out overtime - getTotalHours
                             $totalHours = getTotalHours($clockingIn, $clockingOut, $shiftEnd);
                             DB::table('employee_timesheet')->where('id', $timesheetId)->update(array('time_in_1' => trim($clockingIn), 'time_out_1' => trim($clockingOut), 'work_hours_1' => $workHours, 'total_hours_1' => $totalHours));
                             //Todo: update overtime table
                             DB::table('overtime')->where('employee_id', $employeeId)->where('timesheet_id', $timesheetId)->where('seq_no', 1)->where('shift', 1)->update(array('overtime_status' => 'NULL'));
                         }
                     } else {
                         //echo "LATE/TARDINESS: FALSE \n";
                         //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                         $workHours = getWorkHours($clockingIn, $clockingOut, $shiftEnd);
                         //TODO: Compute total hours with overtime - getTotalHours
                         $totalHours = getTotalHours($clockingIn, $clockingOut, $shiftEnd);
                         DB::table('employee_timesheet')->where('id', $timesheetId)->update(array('time_in_1' => trim($clockingIn), 'time_out_1' => trim($clockingOut), 'work_hours_1' => $workHours, 'total_hours_1' => $totalHours));
                     }
                     //UNDERTIME: TRUE
                     if (strtotime($clockingOut) < strtotime($shiftEnd)) {
                         //echo "UNDERTIME: TRUE \n";
                         $undertime = getUnderTimeHours($clockingIn, $clockingOut, $shiftStart, $shiftEnd);
                         DB::table('employee_timesheet')->where('id', $timesheetId)->update(array('time_in_1' => trim($clockingIn), 'time_out_1' => trim($clockingOut), 'undertime_1' => $undertime, 'total_overtime_1' => '', 'overtime_status_1' => 'NULL'));
                         //Todo: update overtime table
                         DB::table('overtime')->where('employee_id', $employeeId)->where('timesheet_id', $timesheetId)->where('seq_no', 1)->where('shift', 1)->update(array('overtime_status' => 'NULL'));
                         DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('undertime' => $undertime));
                     } else {
                         DB::table('employee_timesheet')->where('id', $timesheetId)->update(array('time_in_1' => trim($clockingIn), 'time_out_1' => trim($clockingOut), 'undertime_1' => ''));
                         DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('undertime' => ''));
                     }
                     //OVERTIME: TRUE
                     $isOvertime = false;
                     /*if ( date('H:i', strtotime($clockingIn)) <= date('H:i', strtotime($shiftStart)) &&
                     	 date('H:i', strtotime($clockingOut)) > date('H:i', strtotime($shiftEnd)) ) {*/
                     if (strtotime($clockingIn) <= strtotime($shiftStart) && strtotime($clockingOut) > strtotime($shiftEnd)) {
                         //echo "OVERTIME: TRUE \n";
                         $isOvertime = true;
                         $totalOvertime = getOvertimeHours($clockingOut, $shiftEnd);
                         DB::table('employee_timesheet')->where('id', $timesheetId)->update(array('total_overtime_1' => $totalOvertime, 'time_in_1' => trim($clockingIn), 'time_out_1' => trim($clockingOut), 'tardiness_1' => '', 'undertime_1' => '', 'overtime_status_1' => 'NULL'));
                         //Todo: update overtime table
                         DB::table('overtime')->where('employee_id', $employeeId)->where('timesheet_id', $timesheetId)->where('seq_no', 1)->where('shift', 1)->update(array('overtime_status' => 'NULL'));
                     }
                     //dd($holiday);
                     //REST DAY: FALSE
                     if ($scheduled['rest_day'] !== 1) {
                         //HOLIDAY: TRUE
                         if (!empty($holiday)) {
                             if ('Regular holiday' === $holiday->holiday_type) {
                                 //Regular holiday
                                 //echo "Regular holiday \n";
                                 $totalHours = getTotalHours($clockingIn, $clockingOut, $shiftEnd);
                                 if (!$isOvertime) {
                                     //ISOVERTIME: FALSE
                                     DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('legal_holiday_night_diff' => $totalHours));
                                 }
                             } elseif ('Special non-working day' === $holiday->holiday_type) {
                                 //Special non-working day
                                 //echo "Special non-working day \n";
                                 $totalHours = getTotalHours($clockingIn, $clockingOut, $shiftEnd);
                                 if (!$isOvertime) {
                                     //ISOVERTIME: FALSE
                                     DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('special_holiday_night_diff' => $totalHours));
                                 }
                             }
                             //HOLIDAY: FALSE
                         } else {
                             //Regular Day
                             //echo "HOLIDAY: FALSE \n";
                             //echo "Regular Day \n";
                             $totalHours = getTotalHours($clockingIn, $clockingOut, $shiftEnd);
                             if (!$isOvertime) {
                                 //ISOVERTIME: FALSE
                                 DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('regular_night_differential' => $totalHours));
                             }
                         }
                         //REST DAY: TRUE
                     } elseif ($scheduled['rest_day'] === 1) {
                         //HOLIDAY: TRUE
                         if (!empty($holiday)) {
                             if ('Regular holiday' === $holiday->holiday_type) {
                                 //Regular holiday
                                 //echo "Regular holiday \n";
                                 $totalHours = getTotalHours($clockingIn, $clockingOut, $shiftEnd);
                                 if (!$isOvertime) {
                                     //ISOVERTIME: FALSE
                                     DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('rest_day_legal_holiday_night_diff' => $totalHours));
                                 }
                             } elseif ('Special non-working day' === $holiday->holiday_type) {
                                 //Special non-working day
                                 //echo "Special non-working day \n";
                                 $totalHours = getTotalHours($clockingIn, $clockingOut, $shiftEnd);
                                 if (!$isOvertime) {
                                     //ISOVERTIME: FALSE
                                     DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('rest_day_special_holiday_night_diff' => $totalHours));
                                 }
                             }
                             //HOLIDAY: FALSE
                         } else {
                             //Regular Day
                             //echo "HOLIDAY: FALSE \n";
                             //echo "Regular Day \n";
                             $totalHours = getTotalHours($clockingIn, $clockingOut, $shiftEnd);
                             if (!$isOvertime) {
                                 //ISOVERTIME: FALSE
                                 DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update(array('rest_day_night_differential' => $totalHours));
                             }
                         }
                     }
                     //OVERTIME TRUE
                     if (!empty($overtime)) {
                         //REST DAY: FALSE
                         if ($scheduled['rest_day'] !== 1) {
                             //HOLIDAY: TRUE
                             if (!empty($holiday)) {
                                 if ('Regular holiday' === $holiday->holiday_type) {
                                     //Regular holiday
                                     if (!$hasNightDiff) {
                                         $update = array('legal_holiday_overtime' => $totalOvertime);
                                     } elseif ($hasNightDiff) {
                                         $update = array('legal_holiday_overtime_night_diff' => $totalOvertime);
                                     }
                                     DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update($update);
                                 } elseif ('Special non-working day' === $holiday->holiday_type) {
                                     //Special non-working day
                                     if (!$hasNightDiff) {
                                         $update = array('legal_holiday_overtime' => $totalOvertime);
                                     } elseif ($hasNightDiff) {
                                         $update = array('legal_holiday_overtime_night_diff' => $totalOvertime);
                                     }
                                     DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update($update);
                                 }
                                 //HOLIDAY: FALSE
                             } else {
                                 //Regular Day
                                 //echo "HOLIDAY: FALSE \n";
                                 if (!$hasNightDiff) {
                                     $update = array('regular_overtime' => $totalOvertime);
                                 } elseif ($hasNightDiff) {
                                     $update = array('regular_overtime_night_diff' => $totalOvertime);
                                 }
                                 DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update($update);
                             }
                             //REST DAY: TRUE
                         } elseif ($scheduled['rest_day'] === 1) {
                             //HOLIDAY: TRUE
                             if (!empty($holiday)) {
                                 if ('Regular holiday' === $holiday->holiday_type) {
                                     //Regular holiday
                                     if (!$hasNightDiff) {
                                         $update = array('rest_day_legal_holiday_overtime' => $totalOvertime);
                                     } elseif ($hasNightDiff) {
                                         $update = array('rest_day_legal_holiday_overtime_night_diff' => $totalOvertime);
                                     }
                                     DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update($update);
                                 } elseif ('Special non-working day' === $holiday->holiday_type) {
                                     //Special non-working day
                                     if (!$hasNightDiff) {
                                         $update = array('rest_day_legal_holiday_overtime' => $totalOvertime);
                                     } elseif ($hasNightDiff) {
                                         $update = array('rest_day_legal_holiday_overtime_night_diff' => $totalOvertime);
                                     }
                                     DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update($update);
                                 }
                                 //HOLIDAY: FALSE
                             } else {
                                 //Regular Day
                                 //echo "HOLIDAY: FALSE \n";
                                 if (!$hasNightDiff) {
                                     $update = array('rest_day_overtime' => $totalOvertime);
                                 } elseif ($hasNightDiff) {
                                     $update = array('rest_day_overtime_night_diff' => $totalOvertime);
                                 }
                                 DB::table('employee_summary')->where('employee_id', $employeeId)->where('daydate', $dayDate)->update($update);
                             }
                         }
                     } else {
                     }
                 } else {
                     return "Not Allowed";
                 }
             } else {
                 return "Not Allowed";
             }
         }
         //in-out 2
         if ((int) $data["column"] === 4) {
             if (!empty($data["value"])) {
                 $dataValueArr = explode('-', $data["value"]);
                 return DB::table('employee_timesheet')->where('id', (int) $data["row_id"])->update(array('time_in_2' => trim($dataValueArr[0]), 'time_out_2' => trim($dataValueArr[1])));
             }
         }
         //in-out 3
         if ((int) $data["column"] === 5) {
             if (!empty($data["value"])) {
                 $dataValueArr = explode('-', $data["value"]);
                 return DB::table('employee_timesheet')->where('id', (int) $data["row_id"])->update(array('time_in_3' => trim($dataValueArr[0]), 'time_out_3' => trim($dataValueArr[1])));
             }
         }
         //return Redirect::to('/redraw/timesheet');
     }
 }
function clockingStatusClockIn3Out($clockingDateTime)
{
    $employeeId = Session::get('userEmployeeId');
    $userId = Session::get('userId');
    $dayOfTheWeek = date('l');
    $currentDate = date('Y-m-d');
    $schedule = new Schedule();
    $getSchedule = $schedule->getSchedule($employeeId, date('Y-m-d'));
    $workShift = new Workshift();
    //$getWorkShiftByEmployeeId = $workShift->getWorkShiftByEmployeeId($employeeId);
    $getWorkShiftByDayOfTheWeek = $workShift->getWorkShiftByDayOfTheWeek($employeeId, $dayOfTheWeek, 2);
    //return dd($getWorkShiftByDayOfTheWeek);
    //break;
    $holiday = new Holiday();
    $getHolidayByDate = $holiday->getHolidayByDate($currentDate);
    $timesheet = new Timesheet();
    $employeeClocking = $timesheet->getEmployeeByEmployeeIdandDate($employeeId, date('Y-m-d'));
    $summary = new Summary();
    $employeeSummary = $summary->getEmployeeSummaryByEmployeeIdandDate($employeeId, date('Y-m-d'));
    $setting = new Setting();
    $employeeSetting = $setting->getEmployeeSettingByEmployeeId($employeeId);
    if (!empty($getSchedule)) {
        //echo 'getSchedule';
        $scheduled['start_time'] = $getSchedule[0]->start_time;
        $scheduled['end_time'] = $getSchedule[0]->end_time;
        $scheduled['rest_day'] = $getSchedule[0]->rest_day;
    } elseif (!empty($getWorkShiftByDayOfTheWeek)) {
        //echo 'getWorkShiftByDayOfTheWeek';
        // From 01:00:00 change to 2015-04-30 09:00:00
        $scheduled['start_time'] = date('Y-m-d', strtotime($employeeClocking->time_in_3)) . ' ' . $getWorkShiftByDayOfTheWeek[0]->start_time;
        // From 01:00:00 change to 2015-04-30 01:00:00
        $scheduled['end_time'] = date('Y-m-d', strtotime($clockingDateTime)) . ' ' . $getWorkShiftByDayOfTheWeek[0]->end_time;
        $scheduled['rest_day'] = $getWorkShiftByDayOfTheWeek[0]->rest_day;
    }
    $employeeClocking->time_out_3 = $clockingDateTime;
    $employeeClocking->clocking_status = 'clock_out_3';
    // From 2015-04-30 08:36:16 change to 08:36:16
    $clockingIn = date('H:i:s', strtotime($employeeClocking->time_in_3));
    // From 2015-04-30 08:36:16 change to 08:36:16
    $clockingOut = date('H:i:s', strtotime($clockingDateTime));
    //SCHEDULED : TRUE
    if ((!empty($scheduled['start_time']) || $scheduled['start_time'] !== '00:00:00' || $scheduled['start_time'] !== '') && (!empty($scheduled['end_time']) || $scheduled['end_time'] !== '00:00:00' || $scheduled['end_time'] !== '')) {
        echo "SCHEDULED : TRUE \n";
        //REST DAY: FALSE
        if ($scheduled['rest_day'] !== 1) {
            echo "REST DAY: FALSE \n";
            //LATE/TARDINESS: TRUE
            if (!empty($employeeClocking->tardiness_3)) {
                echo "LATE/TARDINESS: TRUE \n";
                //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                $employeeClocking->work_hours_3 = getWorkHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                //TODO: Compute total hours with out overtime - getTotalHours
                $employeeClocking->total_hours_3 = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                //LATE/TARDINESS: FALSE
            } else {
                echo "LATE/TARDINESS: FALSE \n";
                //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                $employeeClocking->work_hours_3 = getWorkHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                //TODO: Compute total hours with overtime - getTotalHours
                $employeeClocking->total_hours_3 = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
            }
            //UNDERTIME: TRUE
            if (strtotime($clockingDateTime) < strtotime($scheduled['end_time'])) {
                echo "UNDERTIME: TRUE \n";
                echo $employeeClocking->undertime_3 = getUnderTimeHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['start_time'], $scheduled['end_time']);
            }
            //OVERTIME: TRUE
            $isOvertime = false;
            if (date('H:i', strtotime($employeeClocking->time_in_3)) <= date('H:i', strtotime($scheduled['start_time'])) && date('H:i', strtotime($clockingDateTime)) > date('H:i', strtotime($scheduled['end_time']))) {
                echo "OVERTIME: TRUE \n";
                $isOvertime = true;
                $employeeClocking->total_overtime_3 = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
            }
            //HOLIDAY: TRUE
            if (hasHoliday($currentDate)) {
                echo "HOLIDAY: TRUE \n";
                if ('Regular holiday' === $getHolidayByDate[0]->holiday_type) {
                    //Regular holiday
                    echo "Regular holiday \n";
                    if (!$isOvertime) {
                        //ISOVERTIME: FALSE
                        $employeeSummary->legal_holiday = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                    } else {
                        //ISOVERTIME: TRUE
                        $employeeSummary->legal_holiday_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                    }
                } elseif ('Special non-working day' === $getHolidayByDate[0]->holiday_type) {
                    //Special non-working day
                    echo "Special non-working day \n";
                    if (!$isOvertime) {
                        //ISOVERTIME: FALSE
                        $employeeSummary->special_holiday = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                    } else {
                        //ISOVERTIME: TRUE
                        $employeeSummary->special_holiday_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                    }
                }
                //HOLIDAY: FALSE
            } else {
                //Regular Day
                echo "HOLIDAY: FALSE \n";
                echo "Regular Day \n";
                if (!$isOvertime) {
                    //ISOVERTIME: FALSE
                    $employeeSummary->regular = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                } else {
                    //ISOVERTIME: TRUE
                    $employeeSummary->regular_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                }
            }
            if ($employeeClocking->save()) {
                $employeeSummary->save();
                return Redirect::to('/redraw/timesheet');
            }
            //REST DAY: TRUE
        } elseif ($scheduled['rest_day'] === 1) {
            echo "REST DAY: TRUE \n";
            //TODO RULES: First 8 Hours get the hours_per_day in employee setting
            //LATE/TARDINESS: TRUE
            if (!empty($employeeClocking->tardiness_3)) {
                echo "LATE/TARDINESS: TRUE \n";
                //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                $employeeClocking->work_hours_3 = getWorkHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                //TODO: Compute total hours with out overtime - getTotalHours
                $employeeClocking->total_hours_3 = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                //LATE/TARDINESS: FALSE
            } else {
                echo "LATE/TARDINESS: FALSE \n";
                //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                $employeeClocking->work_hours_3 = getWorkHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                //TODO: Compute total hours with overtime - getTotalHours
                $employeeClocking->total_hours_3 = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
            }
            //UNDERTIME: TRUE
            if (strtotime($clockingDateTime) < strtotime($scheduled['end_time'])) {
                echo "UNDERTIME: TRUE \n";
                echo $employeeClocking->undertime_3 = getUnderTimeHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['start_time'], $scheduled['end_time']);
            }
            //OVERTIME: TRUE
            $isOvertime = false;
            if (date('H:i', strtotime($employeeClocking->time_in_3)) <= date('H:i', strtotime($scheduled['start_time'])) && date('H:i', strtotime($clockingDateTime)) > date('H:i', strtotime($scheduled['end_time']))) {
                echo "OVERTIME: TRUE \n";
                $isOvertime = true;
                $employeeClocking->total_overtime_3 = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
            }
            //HOLIDAY: TRUE
            if (hasHoliday($currentDate)) {
                echo "HOLIDAY: TRUE \n";
                if ('Regular holiday' === $getHolidayByDate[0]->holiday_type) {
                    //Regular holiday
                    echo "Regular holiday \n";
                    if (!$isOvertime) {
                        //ISOVERTIME: FALSE
                        $employeeSummary->rest_day_legal_holiday = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                    } else {
                        //ISOVERTIME: TRUE
                        $employeeSummary->rest_day_legal_holiday_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                    }
                } elseif ('Special non-working day' === $getHolidayByDate[0]->holiday_type) {
                    //Special non-working day
                    echo "Special non-working day \n";
                    if (!$isOvertime) {
                        //ISOVERTIME: FALSE
                        $employeeSummary->rest_day_special_holiday = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                    } else {
                        //ISOVERTIME: TRUE
                        $employeeSummary->rest_day_special_holiday_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                    }
                }
                //HOLIDAY: FALSE
            } else {
                //Regular Day
                echo "HOLIDAY: FALSE \n";
                echo "Regular Rest Day \n";
                if (!$isOvertime) {
                    //ISOVERTIME: FALSE
                    $employeeSummary->rest_day = getTotalHours($employeeClocking->time_in_3, $clockingDateTime, $scheduled['end_time']);
                } else {
                    //ISOVERTIME: TRUE
                    $employeeSummary->rest_day_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                }
            }
            if ($employeeClocking->save()) {
                $employeeSummary->save();
                return Redirect::to('/redraw/timesheet');
            }
        }
        //SCHEDULED : FALSE
    } else {
        echo "SCHEDULED : FALSE \n";
    }
}
 public function updateTimesheetTimeOut2($data = '', $column = NULL)
 {
     //return dd($data);
     //die();
     //Settings
     $nightDiff['from'] = strtotime('22:00:00');
     $nightDiff['to'] = strtotime('06:00:00');
     $breakTime = date('H:i:s', strtotime('01:00:00'));
     $shift = 1;
     $hasNightDiff = false;
     $getTimesheet = Timesheet::where('id', (int) trim($data["row_id"]))->first();
     $clockingIn = $getTimesheet->time_in_1;
     $clockingOut = $getTimesheet->time_out_1;
     $timeInHour = date('G', strtotime($clockingIn));
     //24-hour format of an hour without leading zeros
     $timeOutHour = date('G', strtotime($clockingOut));
     //24-hour format of an hour without leading zeros
     $timesheetId = $getTimesheet->id;
     $employeeId = $getTimesheet->employee_id;
     $clockingStatus = $getTimesheet->clocking_status;
     //$shiftStart = $getTimesheet->schedule_in;
     //$shiftEnd = $getTimesheet->schedule_out;
     $dayDate = $getTimesheet->daydate;
     $tardiness = $getTimesheet->tardiness_1;
     $dayOfTheWeek = date('l', strtotime($dayDate));
     $getSummary = Summary::where('employee_id', $employeeId)->where('daydate', trim($dayDate))->first();
     $clockingDateTime = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($data['value']));
     $getTimesheet->time_out_1 = $clockingDateTime;
     $getTimesheet->clocking_status = 'clock_out_1';
     $getTimesheet->time_out_2 = '';
     $schedule = new Schedule();
     $getSchedule = DB::table('employee_schedule')->where('employee_id', $employeeId)->where('schedule_date', trim($dayDate))->first();
     $workShift = new Workshift();
     $getWorkShiftByDayOfTheWeek = DB::table('work_shift')->where('employee_id', $employeeId)->where('name_of_day', date('l', strtotime($dayDate)))->where('shift', $shift)->first();
     $holiday = new Holiday();
     $getHolidayByDate = DB::table('holiday')->where('date', trim($dayDate))->first();
     if (!empty($getSchedule)) {
         $scheduled['start_time'] = $getSchedule->start_time;
         $scheduled['end_time'] = $getSchedule->end_time;
         $scheduled['rest_day'] = $getSchedule->rest_day;
         $startTime = date('H:i:s', strtotime($scheduled['start_time']));
     } elseif (!empty($getWorkShiftByDayOfTheWeek)) {
         //$scheduled['start_time'] = $getWorkShiftByDayOfTheWeek->start_time;
         //$scheduled['end_time'] = $getWorkShiftByDayOfTheWeek->end_time;
         // From 01:00:00 change to 2015-04-30 09:00:00
         $scheduled['start_time'] = date('Y-m-d', strtotime($getTimesheet->time_out_1)) . ' ' . $getWorkShiftByDayOfTheWeek->start_time;
         // From 01:00:00 change to 2015-04-30 01:00:00
         $scheduled['end_time'] = date('Y-m-d', strtotime($clockingDateTime)) . ' ' . $getWorkShiftByDayOfTheWeek->end_time;
         $scheduled['rest_day'] = $getWorkShiftByDayOfTheWeek->rest_day;
         $startTime = $scheduled['start_time'];
     }
     //SCHEDULED : TRUE
     if ((!empty($scheduled['start_time']) || $scheduled['start_time'] !== '00:00:00' || $scheduled['start_time'] !== '') && (!empty($scheduled['end_time']) || $scheduled['end_time'] !== '00:00:00' || $scheduled['end_time'] !== '')) {
         //REST DAY: FALSE
         if ($scheduled['rest_day'] !== 1) {
             //LATE/TARDINESS: TRUE
             if (!empty($getTimesheet->tardiness_1)) {
                 //echo "LATE/TARDINESS: TRUE \n";
                 //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                 $workHours = getWorkHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                 if ($workHours >= 8 || $workHours >= 8.0 || $workHours >= 8.0) {
                     $getTimesheet->work_hours_1 = 8.0;
                 } else {
                     $getTimesheet->work_hours_1 = $workHours;
                 }
                 //TODO: Compute total hours with out overtime - getTotalHours
                 $getTimesheet->total_hours_1 = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                 //LATE/TARDINESS: FALSE
             } else {
                 //echo "LATE/TARDINESS: TRUE \n";
                 //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                 $workHours = getWorkHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                 if ($workHours >= 8 || $workHours >= 8.0 || $workHours >= 8.0) {
                     $getTimesheet->work_hours_1 = 8.0;
                 } else {
                     $getTimesheet->work_hours_1 = $workHours;
                 }
                 //TODO: Compute total hours with out overtime - getTotalHours
                 $getTimesheet->total_hours_1 = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
             }
             //GET NIGHTDIFF
             $timeInArr = array();
             $timeOutArr = array();
             $timeInArr = explode(' ', $getTimesheet->time_in_1);
             $timeOutArr = explode(' ', $clockingDateTime);
             $nightDiff['from'] = strtotime(date('Y-m-d H:i', strtotime($timeInArr[0] . ' ' . '22:00:00')));
             $nightDiff['to'] = strtotime(date('Y-m-d H:i', strtotime($timeOutArr[0] . ' ' . '06:00:00')));
             $timesheet['timeIn'] = strtotime(date('Y-m-d H:i', strtotime($getTimesheet->time_in_1)));
             $timesheet['timeOut'] = strtotime(date('Y-m-d H:i', strtotime($clockingDateTime)));
             if ($timesheet['timeIn'] >= $nightDiff['from'] && $timesheet['timeIn'] <= $nightDiff['to']) {
                 if ($timesheet['timeOut'] >= $nightDiff['to']) {
                     // SET IT TO 8.00
                     $getTimesheet->night_differential_1 = 8.0;
                 } else {
                     $getTimesheet->night_differential_1 = $workHours;
                 }
             } elseif ($timesheet['timeOut'] >= $nightDiff['from'] && $timesheet['timeOut'] <= $nightDiff['to']) {
                 if ($timesheet['timeIn'] <= $nightDiff['from']) {
                     $getTimesheet->night_differential_1 = 8.0;
                 } else {
                     $getTimesheet->night_differential_1 = $workHours;
                 }
             }
             /*else {
             
             			        if($timesheet['timeIn'] < $nightDiff['from'] && $timesheet['timeOut'] > $nightDiff['to']) {
             			            
             						$getTimesheet->night_differential_1 = 8.00;
             
             			        }
             		        
             		    	}*/
             //UNDERTIME: TRUE
             if (strtotime($getTimesheet->time_out_1) < strtotime($scheduled['end_time'])) {
                 //echo "UNDERTIME: TRUE \n";
                 $getTimesheet->undertime_1 = getUnderTimeHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['start_time'], $scheduled['end_time']);
                 $getSummary->undertime = getUnderTimeHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['start_time'], $scheduled['end_time']);
             } else {
                 //echo "UNDERTIME: FALSE \n";
                 $getTimesheet->undertime_1 = '';
                 $getSummary->undertime = '';
             }
             //OVERTIME: TRUE
             $isOvertime = false;
             if (date('H:i', strtotime($getTimesheet->time_in_1)) <= date('H:i', strtotime($scheduled['start_time'])) && date('H:i', strtotime($clockingDateTime)) > date('H:i', strtotime($scheduled['end_time']))) {
                 ////echo "OVERTIME: TRUE \n";
                 $isOvertime = true;
                 $getTimesheet->total_overtime_1 = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
             } else {
                 $isOvertime = false;
                 $getTimesheet->total_overtime_1 = '';
             }
             //HOLIDAY: TRUE
             if (hasHoliday($dayDate)) {
                 ////echo "HOLIDAY: TRUE \n";
                 if ('Regular holiday' === $getHolidayByDate->holiday_type) {
                     //Regular holiday
                     //echo "Regular holiday \n";
                     if (!$isOvertime) {
                         //ISOVERTIME: FALSE
                         $getSummary->legal_holiday = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                         $getSummary->legal_holiday_overtime = '';
                     } else {
                         //ISOVERTIME: TRUE
                         $getSummary->legal_holiday_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                         $getSummary->legal_holiday = '';
                     }
                 } elseif ('Special non-working day' === $getHolidayByDate->holiday_type) {
                     //Special non-working day
                     //echo "Special non-working day \n";
                     if (!$isOvertime) {
                         //ISOVERTIME: FALSE
                         $getSummary->special_holiday = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                         $getSummary->special_holiday_overtime = '';
                     } else {
                         //ISOVERTIME: TRUE
                         $getSummary->special_holiday_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                         $getSummary->special_holiday = '';
                     }
                 }
                 //HOLIDAY: FALSE
             } else {
                 //Regular Day
                 //echo "HOLIDAY: FALSE \n";
                 //echo "Regular Day \n";
                 if (!$isOvertime) {
                     //ISOVERTIME: FALSE
                     $getSummary->regular = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                     $getSummary->regular_overtime = '';
                     $getSummary->legal_holiday = '';
                     $getSummary->special_holiday = '';
                 } else {
                     //ISOVERTIME: TRUE
                     $getSummary->regular_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                     $getSummary->regular = '';
                     $getSummary->legal_holiday_overtime = '';
                     $getSummary->special_holiday_overtime = '';
                 }
             }
             //REST DAY: TRUE
         } elseif ($scheduled['rest_day'] === 1) {
             //LATE/TARDINESS: TRUE
             if (!empty($getTimesheet->tardiness_1)) {
                 //echo "LATE/TARDINESS: TRUE \n";
                 //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                 $workHours = getWorkHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                 if ($workHours >= 8 || $workHours >= 8.0 || $workHours >= 8.0) {
                     $getTimesheet->work_hours_1 = 8.0;
                 } else {
                     $getTimesheet->work_hours_1 = $workHours;
                 }
                 //TODO: Compute total hours with out overtime - getTotalHours
                 $getTimesheet->total_hours_1 = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                 //LATE/TARDINESS: FALSE
             } else {
                 //echo "LATE/TARDINESS: TRUE \n";
                 //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours
                 $workHours = getWorkHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                 if ($workHours >= 8 || $workHours >= 8.0 || $workHours >= 8.0) {
                     $getTimesheet->work_hours_1 = 8.0;
                 } else {
                     $getTimesheet->work_hours_1 = $workHours;
                 }
                 //TODO: Compute total hours with out overtime - getTotalHours
                 $getTimesheet->total_hours_1 = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
             }
             //GET NIGHTDIFF
             $timeInArr = array();
             $timeOutArr = array();
             $timeInArr = explode(' ', $getTimesheet->time_in_1);
             $timeOutArr = explode(' ', $clockingDateTime);
             $nightDiff['from'] = strtotime(date('Y-m-d H:i', strtotime($timeInArr[0] . ' ' . '22:00:00')));
             $nightDiff['to'] = strtotime(date('Y-m-d H:i', strtotime($timeOutArr[0] . ' ' . '06:00:00')));
             $timesheet['timeIn'] = strtotime(date('Y-m-d H:i', strtotime($getTimesheet->time_in_1)));
             $timesheet['timeOut'] = strtotime(date('Y-m-d H:i', strtotime($clockingDateTime)));
             if ($timesheet['timeIn'] >= $nightDiff['from'] && $timesheet['timeIn'] <= $nightDiff['to']) {
                 if ($timesheet['timeOut'] >= $nightDiff['to']) {
                     // SET IT TO 8.00
                     $getTimesheet->night_differential_1 = 8.0;
                 } else {
                     $getTimesheet->night_differential_1 = $workHours;
                 }
             } elseif ($timesheet['timeOut'] >= $nightDiff['from'] && $timesheet['timeOut'] <= $nightDiff['to']) {
                 if ($timesheet['timeIn'] <= $nightDiff['from']) {
                     $getTimesheet->night_differential_1 = 8.0;
                 } else {
                     $getTimesheet->night_differential_1 = $workHours;
                 }
             }
             /*else {
             
             			        if($timesheet['timeIn'] < $nightDiff['from'] && $timesheet['timeOut'] > $nightDiff['to']) {
             			            
             						$getTimesheet->night_differential_1 = 8.00;
             
             			        }
             		        
             		    	}*/
             //UNDERTIME: TRUE
             if (strtotime($getTimesheet->time_out_1) < strtotime($scheduled['end_time'])) {
                 //echo "UNDERTIME: TRUE \n";
                 $getTimesheet->undertime_1 = getUnderTimeHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['start_time'], $scheduled['end_time']);
                 $getSummary->undertime = getUnderTimeHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['start_time'], $scheduled['end_time']);
             } else {
                 //echo "UNDERTIME: FALSE \n";
                 $getTimesheet->undertime_1 = '';
                 $getSummary->undertime = '';
             }
             //OVERTIME: TRUE
             $isOvertime = false;
             if (date('H:i', strtotime($getTimesheet->time_in_1)) <= date('H:i', strtotime($scheduled['start_time'])) && date('H:i', strtotime($clockingDateTime)) > date('H:i', strtotime($scheduled['end_time']))) {
                 ////echo "OVERTIME: TRUE \n";
                 $isOvertime = true;
                 $getTimesheet->total_overtime_1 = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
             } else {
                 $isOvertime = false;
                 $getTimesheet->total_overtime_1 = '';
             }
             //HOLIDAY: TRUE
             if (hasHoliday($dayDate)) {
                 ////echo "HOLIDAY: TRUE \n";
                 if ('Regular holiday' === $getHolidayByDate->holiday_type) {
                     //Regular holiday
                     //echo "Regular holiday \n";
                     if (!$isOvertime) {
                         //ISOVERTIME: FALSE
                         $getSummary->rest_day_legal_holiday = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                         $getSummary->rest_day_legal_holiday_overtime = '';
                     } else {
                         //ISOVERTIME: TRUE
                         $getSummary->rest_day_legal_holiday_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                         $getSummary->rest_day_legal_holiday = '';
                     }
                 } elseif ('Special non-working day' === $getHolidayByDate->holiday_type) {
                     //Special non-working day
                     //echo "Special non-working day \n";
                     if (!$isOvertime) {
                         //ISOVERTIME: FALSE
                         $getSummary->rest_day_special_holiday = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                         $getSummary->rest_day_special_holiday_overtime = '';
                     } else {
                         //ISOVERTIME: TRUE
                         $getSummary->rest_day_special_holiday_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                         $getSummary->rest_day_special_holiday = '';
                     }
                 }
                 //HOLIDAY: FALSE
             } else {
                 //Regular Day
                 //echo "HOLIDAY: FALSE \n";
                 //echo "Regular Day \n";
                 if (!$isOvertime) {
                     //ISOVERTIME: FALSE
                     $getSummary->rest_day = getTotalHours($getTimesheet->time_in_1, $clockingDateTime, $scheduled['end_time']);
                     $getSummary->rest_day_overtime = '';
                     $getSummary->rest_day_legal_holiday = '';
                     $getSummary->rest_day_special_holiday = '';
                 } else {
                     //ISOVERTIME: TRUE
                     $getSummary->rest_day_overtime = getOvertimeHours($clockingDateTime, $scheduled['end_time']);
                     $getSummary->rest_day = '';
                     $getSummary->rest_day_legal_holiday_overtime = '';
                     $getSummary->rest_day_special_holiday_overtime = '';
                 }
             }
         }
     }
     if ($getTimesheet->save()) {
         $getSummary->save();
         return Redirect::to('/redraw/timesheet');
     }
     //}
 }