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 clockingStatusForgotToClockOut($clockingDateTime = '', $tardiness = false) { $employeeId = Session::get('userEmployeeId'); $userId = Session::get('userId'); $dayOfTheWeek = date('l'); $schedule = new Schedule(); $getSchedule = $schedule->getSchedule($employeeId, date('Y-m-d')); $workShift = new Workshift(); //$getWorkShiftByEmployeeId = $workShift->getWorkShiftByEmployeeId($employeeId); $getWorkShiftByDayOfTheWeek = $workShift->getWorkShiftByDayOfTheWeek($employeeId, $dayOfTheWeek, 1); $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)) { $scheduled['start_time'] = $getSchedule[0]->start_time; $scheduled['end_time'] = $getSchedule[0]->end_time; } elseif (!empty($getWorkShiftByDayOfTheWeek)) { //$getWorkShiftByEmployeeId->name_of_day; $scheduled['start_time'] = $getWorkShiftByDayOfTheWeek[0]->start_time; $scheduled['end_time'] = $getWorkShiftByDayOfTheWeek[0]->end_time; } else { return 'Check default schedule and Scheduled table for this employee'; } $employeeClocking->time_in_2 = $clockingDateTime; $employeeClocking->clocking_status = 'clock_in_2'; if ($tardiness) { $clockingIn = $clockingDateTime; //$getClockingDateTime; if (!empty($getSchedule)) { $startTime = $schedule['start_time']; } elseif (!empty($getWorkShiftByDayOfTheWeek)) { $startTime = $scheduled['start_time']; } $tardinessTime = getTardinessTime($clockingIn, $startTime); if (!empty($tardinessTime)) { $employeeClocking->tardiness_2 = $tardinessTime; $employeeSummary->lates = $tardinessTime; } } if ($employeeClocking->save()) { if (!empty($tardinessTime)) { $employeeSummary->save(); } return Redirect::to('/redraw/timesheet'); } }
public function updateTimesheetTimeIn2($data = '', $column = NULL) { //return dd($data); //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(); /** * if !empty time in 1 and empty time in 1 * or * if clocking status = clock_in_1 * * check tardiness * compute tardiness update timesheet/summary tardiness/lates */ /*if ( !empty($clockingIn) && empty($clockingOut) && $clockingStatus === 'clock_in_1' ) { $clockingDateTime = date('Y-m-d', strtotime($dayDate)).' '.date('H:i:s', strtotime($data['value'])); $getTimesheet->time_in_1 = $clockingDateTime; $getTimesheet->clocking_status = 'clock_in_1'; $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 = $holiday->getHolidayByDate($dayDate); 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($clockingDateTime) ).' '.$getWorkShiftByDayOfTheWeek->start_time; // From 01:00:00 change to 2015-04-30 01:00:00 $scheduled['end_time'] = date( 'Y-m-d', strtotime($getTimesheet->time_out_1) ).' '.$getWorkShiftByDayOfTheWeek->end_time; $scheduled['rest_day'] = $getWorkShiftByDayOfTheWeek->rest_day; $startTime = $scheduled['start_time']; } if( strtotime(date('H:i', strtotime($clockingDateTime))) === strtotime(date('H:i', strtotime($scheduled['start_time']))) ) { //WITHOUT TARDINESS $getTimesheet->tardiness_1 = ''; $getSummary->lates = ''; //return dd('//WITHOUT TARDINESS'); } elseif( strtotime(date('H:i', strtotime($clockingDateTime))) > strtotime(date('H:i', strtotime($scheduled['start_time']))) ) { //WITH TARDINESS $clockingIn = date('Y-m-d', strtotime($dayDate)).' '.date('H:i:s', strtotime($data['value'])); $tardinessTime = getTardinessTime($clockingIn, $startTime, true); if( !empty($tardinessTime) ) { $getTimesheet->tardiness_1 = $tardinessTime; $getSummary->lates = $tardinessTime; } } if ( $getTimesheet->save() ) { $getSummary->save(); return Redirect::to('/redraw/timesheet'); } }*/ //elseif ( !empty($clockingIn) && !empty($clockingOut) && // $clockingStatus === 'clock_out_1' ) { //return dd($data); //die(); $clockingDateTime = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($data['value'])); $getTimesheet->time_in_1 = $clockingDateTime; $getTimesheet->clocking_status = 'clock_out_1'; $getTimesheet->time_in_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($clockingDateTime)) . ' ' . $getWorkShiftByDayOfTheWeek->start_time; // From 01:00:00 change to 2015-04-30 01:00:00 $scheduled['end_time'] = date('Y-m-d', strtotime($getTimesheet->time_out_1)) . ' ' . $getWorkShiftByDayOfTheWeek->end_time; $scheduled['rest_day'] = $getWorkShiftByDayOfTheWeek->rest_day; $startTime = $scheduled['start_time']; } $clockingIn = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($data['value'])); if (strtotime(date('H:i', strtotime($clockingDateTime))) === strtotime(date('H:i', strtotime($scheduled['start_time'])))) { //WITHOUT TARDINESS $getTimesheet->tardiness_1 = ''; $getSummary->lates = ''; //return dd('//WITHOUT TARDINESS'); } elseif (strtotime(date('H:i', strtotime($clockingDateTime))) > strtotime(date('H:i', strtotime($scheduled['start_time'])))) { //WITH TARDINESS $tardinessTime = getTardinessTime($clockingIn, $startTime, true); if (!empty($tardinessTime)) { $getTimesheet->tardiness_1 = $tardinessTime; $getSummary->lates = $tardinessTime; } } //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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $scheduled['end_time']); } //GET NIGHTDIFF $timeInArr = array(); $timeOutArr = array(); $timeInArr = explode(' ', $clockingDateTime); $timeOutArr = explode(' ', $getTimesheet->time_out_1); $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($clockingDateTime))); $timesheet['timeOut'] = strtotime(date('Y-m-d H:i', strtotime($getTimesheet->time_out_1))); 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($clockingDateTime) < strtotime($scheduled['end_time'])) { //echo "UNDERTIME: TRUE \n"; $getTimesheet->undertime_1 = getUnderTimeHours($clockingDateTime, $getTimesheet->time_out_1, $scheduled['start_time'], $scheduled['end_time']); $getSummary->undertime = getUnderTimeHours($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime)) <= date('H:i', strtotime($scheduled['start_time'])) && date('H:i', strtotime($getTimesheet->time_out_1)) > 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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $scheduled['end_time']); } //GET NIGHTDIFF $timeInArr = array(); $timeOutArr = array(); $timeInArr = explode(' ', $clockingDateTime); $timeOutArr = explode(' ', $getTimesheet->time_out_1); $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($clockingDateTime))); $timesheet['timeOut'] = strtotime(date('Y-m-d H:i', strtotime($getTimesheet->time_out_1))); 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.0; } } //UNDERTIME: TRUE if (strtotime($clockingDateTime) < strtotime($scheduled['end_time'])) { //echo "UNDERTIME: TRUE \n"; $getTimesheet->undertime_1 = getUnderTimeHours($clockingDateTime, $getTimesheet->time_out_1, $scheduled['start_time'], $scheduled['end_time']); $getSummary->undertime = getUnderTimeHours($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime)) <= date('H:i', strtotime($scheduled['start_time'])) && date('H:i', strtotime($getTimesheet->time_out_1)) > 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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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($clockingDateTime, $getTimesheet->time_out_1, $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'); } //} }