/** * Get resulting state when given action is performed on the given timesheet * * @param Timesheet $timesheet * @param int $action Action * @param bool $self true if operating on own timesheet * @return string */ protected function getResultingState($timesheet, $action, $self) { $resultingState = $timesheet->getState(); $excludeRoles = array(); $includeRoles = array(); $entities = array('Employee' => $timesheet->getEmployeeId()); if ($self) { $includeRoles[] = 'ESS'; } $userRoleManager = $this->getContext()->getUserRoleManager(); $allowedActions = $userRoleManager->getAllowedActions(PluginWorkflowStateMachine::FLOW_TIME_TIMESHEET, $timesheet->getState(), $excludeRoles, $includeRoles, $entities); if (isset($allowedActions[$action])) { $resultingState = $allowedActions[$action]->getResultingState(); } return $resultingState; }
/** * Testing for saving a timesheet for newly made timesheets */ public function testSaveTimesheetWithNewTimesheet() { TestDataService::truncateTables(array('Timesheet')); $timesheet = new Timesheet(); $timesheet->setState("CREATED"); $timesheet->setEmployeeId(200); $timesheet->setStartDate("2011-04-07"); $timesheet->setEndDate("2011-04-14"); $savedNewTimesheet = $this->timesheetDao->saveTimesheet($timesheet); $this->assertNotNull($savedNewTimesheet->getTimesheetId()); $this->assertEquals($savedNewTimesheet->getState(), "CREATED"); $this->assertEquals($savedNewTimesheet->getStartDate(), "2011-04-07"); }
/** * Add or Save Timesheet * @param Timesheet $timesheet * @return Timesheet */ public function saveTimesheet(Timesheet $timesheet) { try { if ($timesheet->getTimesheetId() == '') { $idGenService = new IDGeneratorService(); $idGenService->setEntity($timesheet); $timesheet->setTimesheetId($idGenService->getNextID()); } $timesheet->save(); return $timesheet; } catch (Exception $ex) { throw new DaoException($ex->getMessage()); } }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Timesheet::create([]); } }
function getCheckInEntry($userid, $date = '') { $where_query = ""; if (!isEmptyString($date)) { $where_query = " AND TO_DAYS(t.datein) = TO_DAYS('" . $date . "') "; } $conn = Doctrine_Manager::connection(); $query = "SELECT * FROM timesheet AS t where t.`userid` = '" . $userid . "' order by t.timesheetdate desc, t.id desc limit 1 "; // debugMessage($query); $result = $conn->fetchRow($query); if (!$result) { $timesheet = new Timesheet(); $result = $timesheet->toArray(); } // debugMessage($result); return $result; }
public function getEmployeeNightDiffClocking($employeeId, $yesterDayDate) { $employeeId = Session::get('userEmployeeId'); return Timesheet::where('employee_id', '=', $employeeId)->where('daydate', '=', $yesterDayDate)->first(); }
/** * @return \yii\db\ActiveQuery */ public function getTimesheets() { return $this->hasMany(Timesheet::className(), ['user_id' => 'id']); }
if (!empty($employeeClocking->total_overtime_1) && !empty($employeeClocking->total_overtime_3)) { $totalOvertime = $employeeClocking->total_overtime_1 + $employeeClocking->total_overtime_3; } elseif (!empty($employeeClocking->total_overtime_2) && !empty($employeeClocking->total_overtime_3)) { $totalOvertime = $employeeClocking->total_overtime_2 + $employeeClocking->total_overtime_3; } elseif (!empty($employeeClocking->total_overtime_1) && empty($employeeClocking->total_overtime_3)) { $totalOvertime = $employeeClocking->total_overtime_1; } elseif (!empty($employeeClocking->total_overtime_2) && empty($employeeClocking->total_overtime_3)) { $totalOvertime = $employeeClocking->total_overtime_2; } elseif (empty($employeeClocking->total_overtime_1) && !empty($employeeClocking->total_overtime_3) || empty($employeeClocking->total_overtime_2) && !empty($employeeClocking->total_overtime_3)) { $totalOvertime = $employeeClocking->total_overtime_3; } else { $totalOvertime = ''; } $hasNightDiff = false; if ($overtimeById->seq_no === 1) { $getTimesheetById = Timesheet::where('id', '=', $overtimeById->timesheet_id)->first(); DB::table('employee_timesheet')->where('id', $overtimeById->timesheet_id)->update(array('overtime_status_1' => $data["action"])); DB::table('overtime')->where('id', $overtimeById->id)->where('seq_no', 1)->update(array('overtime_status' => $data["action"])); //$totalOvertime = $employeeClocking->total_overtime_1; if (strtotime($employeeClocking->total_time_in_1) >= $nightDiff['from'] || strtotime($employeeClocking->total_time_out_1) <= $nightDiff['to']) { $hasNightDiff = true; } } elseif ($overtimeById->seq_no === 2) { //$getTimesheetById = Timesheet::where('id', '=', $overtimeById->timesheet_id)->first(); DB::table('employee_timesheet')->where('id', $overtimeById->timesheet_id)->update(array('overtime_status_2' => $data["action"])); DB::table('overtime')->where('id', $overtimeById->id)->where('seq_no', 2)->update(array('overtime_status' => $data["action"])); //$totalOvertime = $employeeClocking->total_overtime_1; if (strtotime($employeeClocking->total_time_in_2) >= $nightDiff['from'] || strtotime($employeeClocking->total_time_out_2) <= $nightDiff['to']) { $hasNightDiff = true; } } elseif ($overtimeById->seq_no === 3) {
public function checkPermission($entryId, $userId) { $entry = \Timesheet::find($entryId); if ($entry->user_id == $userId) { return true; } else { return false; } }
} } if ($currentCutoff === 1) { ////1st CutOff - e.g 11-25 $cutOffDateFrom = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_1; $cutOffDateTo = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_1; Session::put('cutOffDateFrom', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_1); Session::put('cutOffDateTo', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_1); } elseif ($currentCutoff === 2) { ////1st CutOff - e.g 26-10 $cutOffDateFrom = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2; $cutOffDateTo = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2; Session::put('cutOffDateFrom', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2); Session::put('cutOffDateTo', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2); } $getTimesheetperCutoff = Timesheet::where('employee_id', $employeeId)->whereBetween('daydate', array($cutOffDateFrom, $cutOffDateTo))->paginate(5); ?> <div class="page-container"> <?php //echo $cutOffDateFrom; //echo $cutOffDateTo; /*foreach($getTimesheetperCutoff as $timesheet) { echo $timesheet->daydate; }*/ ?> <div class="row" style="padding-bottom:20px;">
public function updateTimesheetTimeOut3($data = '', $column = NULL) { //Settings $nightDiff['from'] = strtotime('22:00:00'); $nightDiff['to'] = strtotime('06:00:00'); $breakTime = date('H:i:s', strtotime('01:00:00')); $shift = 2; $hasNightDiff = false; $getTimesheet = Timesheet::where('id', (int) trim($data["row_id"]))->first(); $clockingIn = $getTimesheet->time_in_3; $clockingOut = $getTimesheet->time_out_3; $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_3; $dayOfTheWeek = date('l', strtotime($dayDate)); $getSummary = Summary::where('employee_id', $employeeId)->where('daydate', trim($dayDate))->first(); $hourNeedle = date('G', strtotime(trim($data['value']))); $hourHaystack = array(0, 1, 2, 3, 4, 5, 6); if (in_array($hourNeedle, $hourHaystack)) { $nightdiff = true; } else { $nightdiff = false; } $dayDateModify = new DateTime($dayDate); //Todo Add a condition here if (!empty($data['value']) && !empty($getTimesheet->time_in_3)) { if (!$nightdiff) { $clockingDateTime = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($data['value'])); } else { //$dayDateModify = new DateTime($dayDate); $dayDateModify->modify('+1 day'); //$dayDateModify->format('Y-m-d'); $clockingDateTime = date('Y-m-d', strtotime($dayDateModify->format('Y-m-d'))) . ' ' . date('H:i:s', strtotime($data['value'])); } $getTimesheet->time_out_3 = $clockingDateTime; $getTimesheet->clocking_status = 'clock_out_3'; } elseif (!empty($data['value']) && empty($getTimesheet->time_in_3)) { if (!$nightdiff) { $clockingDateTime = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($data['value'])); } else { //$dayDateModify = new DateTime($dayDate); $dayDateModify->modify('+1 day'); //$dayDateModify->format('Y-m-d'); $clockingDateTime = date('Y-m-d', strtotime($dayDateModify->format('Y-m-d'))) . ' ' . date('H:i:s', strtotime($data['value'])); } $getTimesheet->time_out_3 = $clockingDateTime; $getTimesheet->clocking_status = 'clock_out_3'; //close } elseif (empty($data['value']) && !empty($getTimesheet->time_in_3)) { $clockingDateTime = ''; $getTimesheet->time_out_3 = $clockingDateTime; $getTimesheet->clocking_status = 'clock_in_3'; } elseif (empty($data['value']) && empty($getTimesheet->time_in_3)) { $clockingDateTime = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($data['value'])); if (!$nightdiff) { $clockingDateTime = date('Y-m-d', strtotime($dayDate)) . ' ' . date('H:i:s', strtotime($data['value'])); } else { //$dayDateModify = new DateTime($dayDate); $dayDateModify->modify('+1 day'); //$dayDateModify->format('Y-m-d'); $clockingDateTime = date('Y-m-d', strtotime($dayDateModify->format('Y-m-d'))) . ' ' . date('H:i:s', strtotime($data['value'])); } $getTimesheet->time_out_3 = ''; $getTimesheet->clocking_status = 'close'; } $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_3)) . ' ' . $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']; } //return dd($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'] !== '')) { //REST DAY: FALSE if ($scheduled['rest_day'] !== 1) { $datetime1 = $getTimesheet->time_in_3; $datetime2 = $clockingDateTime; //$interval = getDateTimeDiffInterval($getTimesheet->time_in_3, $getTimesheet->time_out_3) { //Used $datetime1 = new DateTime($datetime1); $datetime2 = new DateTime($datetime2); $interval = $datetime1->diff($datetime2); $hh = $interval->format('%H'); $mm = $interval->format('%I'); $ss = $interval->format('%S'); $overtime = getTimeToDecimalHours($hh, $mm, $ss); //number_format($hours, 2);*/ //OVERTIME: TRUE $isOvertime = true; $getTimesheet->total_overtime_3 = $overtime; $getTimesheet->total_hours_3 = $overtime; /* //echo "LATE/TARDINESS: TRUE \n"; //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours $workHours = $getTimesheet->total_overtime_3; if ( $workHours >= 8 || $workHours >= 8.00 || $workHours >= 8.0 ) { $getTimesheet->work_hours_3 = 8.00; } else { $getTimesheet->work_hours_3 = $workHours; } */ //TODO: Compute total hours with out overtime - getTotalHours $getTimesheet->total_hours_3 = $getTimesheet->total_overtime_3; //GET NIGHTDIFF $timeInArr = array(); $timeOutArr = array(); $timeInArr = explode(' ', $getTimesheet->time_in_3); $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_3))); $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_3 = 8.00; $getTimesheet->night_differential_3 = ($nightDiff['to'] - $timesheet['timeIn']) / 3600; } else { //$getTimesheet->night_differential_3 = $overtime; $getTimesheet->night_differential_3 = ($timesheet['timeOut'] - $timesheet['timeIn']) / 3600; } } elseif ($timesheet['timeOut'] >= $nightDiff['from'] && $timesheet['timeOut'] <= $nightDiff['to']) { if ($timesheet['timeIn'] <= $nightDiff['from']) { //$getTimesheet->night_differential_3 = 8.00; $getTimesheet->night_differential_3 = ($timesheet['timeOut'] - $nightDiff['from']) / 3600; } else { //$getTimesheet->night_differential_3 = $overtime; $getTimesheet->night_differential_3 = ($timesheet['timeOut'] - $timesheet['timeIn']) / 3600; } } /*else { if($timesheet['timeIn'] < $nightDiff['from'] && $timesheet['timeOut'] > $nightDiff['to']) { //$getTimesheet->night_differential_3 = 8.00; $getTimesheet->night_differential_3 = ($nightDiff['from'] - $nightDiff['to']) / 3600; } }*/ //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_3, $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_3, $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_3, $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) { $datetime1 = $getTimesheet->time_in_3; $datetime2 = $clockingDateTime; //$interval = getDateTimeDiffInterval($getTimesheet->time_in_3, $getTimesheet->time_out_3) { //Used $datetime1 = new DateTime($datetime1); $datetime2 = new DateTime($datetime2); $interval = $datetime1->diff($datetime2); $hh = $interval->format('%H'); $mm = $interval->format('%I'); $ss = $interval->format('%S'); $overtime = getTimeToDecimalHours($hh, $mm, $ss); //number_format($hours, 2);*/ //OVERTIME: TRUE $isOvertime = true; $getTimesheet->total_overtime_3 = $overtime; $getTimesheet->total_hours_3 = $overtime; /* //echo "LATE/TARDINESS: TRUE \n"; //TODO: check employee setting if has_break is true and break time is set. - function getWorkHours $workHours = $getTimesheet->total_overtime_3; if ( $workHours >= 8 || $workHours >= 8.00 || $workHours >= 8.0 ) { $getTimesheet->work_hours_3 = 8.00; } else { $getTimesheet->work_hours_3 = $workHours; } */ //TODO: Compute total hours with out overtime - getTotalHours $getTimesheet->total_hours_3 = $getTimesheet->total_overtime_3; //GET NIGHTDIFF $timeInArr = array(); $timeOutArr = array(); $timeInArr = explode(' ', $getTimesheet->time_in_3); $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_3))); $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_3 = 8.0; } else { $getTimesheet->night_differential_3 = $overtime; } } elseif ($timesheet['timeOut'] >= $nightDiff['from'] && $timesheet['timeOut'] <= $nightDiff['to']) { if ($timesheet['timeIn'] <= $nightDiff['from']) { $getTimesheet->night_differential_3 = 8.0; } else { $getTimesheet->night_differential_3 = $overtime; } } /*else { if($timesheet['timeIn'] < $nightDiff['from'] && $timesheet['timeOut'] > $nightDiff['to']) { $getTimesheet->night_differential_3 = 8.00; } }*/ //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_3, $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_3, $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_3, $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'); } //} }
/** * Create and return a timesheet object with given parameters. */ private function _getTimesheet($timesheetId, $employeeId, $timesheetPeriodId, $startDate, $endDate, $status) { $timesheet = new Timesheet(); $timesheet->setTimesheetId($timesheetId); $timesheet->setTimesheetId($timesheetPeriodId); $timesheet->setEmployeeId($employeeId); $timesheet->setStartDate($startDate); $timesheet->setEndDate($endDate); $timesheet->setStatus($status); return $timesheet; }
/** * Validates the timeevent against the given timesheet. * * @param TimeEvent $timeEvent Time event to validate * @param Timesheet $timesheet Time sheet * @return mixed true if validate success, error string if not. */ public function validateTimeEvent($timeEvent, $timesheet) { $eventStartTime = $timeEvent->getStartTime(); $eventEndTime = $timeEvent->getEndTime(); $eventStart = strtotime($eventStartTime); $eventEnd = strtotime($eventEndTime); $periodStartDate = $timesheet->getStartDate(); $periodEndDate = $timesheet->getEndDate(); $periodStart = strtotime($periodStartDate); $periodEnd = strtotime($periodEndDate); $periodEnd = strtotime("+1 day", $periodEnd); // strtotime returns false (-1 before php 5.1.0) on error if (!($periodStart > 0) || !($periodEnd > 0) || $periodStart >= $periodEnd) { return self::INVALID_TIMESHEET_PERIOD_ERROR; } $reportedDate = $timeEvent->getReportedDate(); $reported = strtotime($reportedDate); $eventId = $timeEvent->getTimeEventId(); $newEvent = empty($eventId); if (!CommonFunctions::IsValidId($timeEvent->getProjectId())) { return self::ProjectNotSpecified_ERROR; } if (!CommonFunctions::IsValidId($timeEvent->getActivityId())) { return self::ActivityNotSpecified_ERROR; } if (!empty($eventStartTime) && !($eventStart > 0)) { return self::InvalidStartTime_ERROR; } if (!empty($eventEndTime) && !($eventEnd > 0)) { return self::InvalidEndTime_ERROR; } if (empty($reportedDate)) { return self::ReportedDateNotSpecified_ERROR; } else { if (!($reported > 0)) { return self::InvalidReportedDate_ERROR; } } $duration = $timeEvent->getDuration(); $duration = $duration === "" ? null : $duration; // 0 not allowed for duration in last row. if (!is_null($duration) && ($duration < 0 || $newEvent && $duration == 0)) { return self::InvalidDuration_ERROR; } // Validate period/interval if (empty($eventStartTime) && empty($eventEndTime) && !empty($duration)) { // reported date + duration if ($reported < $periodStart || $reported + $duration > $periodEnd) { return self::EVENT_OUTSIDE_PERIOD_FAILURE; } } else { if (!empty($eventStartTime) && empty($eventEndTime) && is_null($duration)) { // start time only if ($eventStart < $periodStart || $eventStart > $periodEnd) { return self::EVENT_OUTSIDE_PERIOD_FAILURE; } } else { if (!empty($eventStartTime) && !empty($eventEndTime)) { if (!empty($duration) && $newEvent) { return self::NotAllowedToSpecifyDurationAndInterval_ERROR; } // start and end time if ($eventStart >= $eventEnd) { return self::ZeroOrNegativeIntervalSpecified_ERROR; } if ($eventStart < $periodStart || $eventEnd > $periodEnd) { return self::EVENT_OUTSIDE_PERIOD_FAILURE; } $timeEvent->setDuration($eventEnd - $eventStart); } else { if (!empty($eventStartTime) && !empty($duration) && empty($eventEndTime)) { // start time and duration if ($eventStart < $periodStart || $eventStart + $duration > $periodEnd) { return self::EVENT_OUTSIDE_PERIOD_FAILURE; } $timeEvent->setEndTime(date("Y-m-d H:i", $eventStart + $duration)); } else { return self::NoValidDurationOrInterval_ERROR; } } } } return true; }
public function testCheckDateInApprovedTimesheet() { $timesheetObj = $this->classTimesheet; $timesheetObj->setTimesheetId(14); $timesheets = $timesheetObj->fetchTimesheets(); $res = $timesheets[0]->approveTimesheet(); $statusResult = Timesheet::checkDateInApprovedTimesheet(date('Y-m-d'), 10); $this->assertTrue($statusResult); $statusResult1 = Timesheet::checkDateInApprovedTimesheet(date('Y-m-d', time() + 3600 * 24 * 7), 10); $this->assertTrue($statusResult1); $statusResult3 = Timesheet::checkDateInApprovedTimesheet(date('Y-m-d', time() + 3600 * 24 * 7 * 6), 10); $this->assertFalse($statusResult3); }
/** * Saves information about a timesheet in the database table * @param Timesheet $timesheet The timesheet to save in the database */ private function saveDatabase(Timesheet $timesheet) { $db = $this->getDB(); $userID = $timesheet->getTutorID(); $dateCreated = $timesheet->getDateCreated(); $filename = $timesheet->getFilename(); // Deletes duplicate timesheets generated the same day by the same user $query = "DELETE FROM " . self::TABLE_TIMESHEET . " WHERE userID = '" . $userID . "' AND dateCompleted = '" . $dateCreated . "'"; $db->query($query); $save = array(); $save['userID'] = $userID; $save['dateCompleted'] = $dateCreated; $save['filename'] = $filename; $db->insert(self::TABLE_TIMESHEET, $save); }
////1st CutOff - e.g 26-10 //$cutoff['dateFrom'][2] = strtotime('-1 month' , strtotime($cutoff['dateFrom'][2])); //$cutoff['dateFrom'][2] = date('Y-m-d' , $cutoff['dateFrom'][2]); //$cutoff['dateTo'][2] = strtotime('-1 month' , strtotime($cutoff['dateTo'][2])); //$cutoff['dateTo'][2] = date('Y-m-d' , $cutoff['dateTo'][2]); $cutOffDateFrom = $cutoff['dateFrom'][2]; $cutOffDateTo = $cutoff['dateTo'][2]; Session::put('cutOffDateFrom', $cutOffDateFrom); Session::put('cutOffDateTo', $cutOffDateTo); /*$cutOffDateFrom = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2; $cutOffDateTo = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2; Session::put('cutOffDateFrom', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2); Session::put('cutOffDateTo', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2); */ } $getTimesheetperCutoff = Timesheet::where('employee_id', $searchEmployeeId)->whereBetween('daydate', array($cutOffDateFrom, $cutOffDateTo))->get(); //$getTimesheetperCutoff = Timesheet::where('employee_id', $searchEmployeeId)->whereBetween('daydate', array($cutOffDateFrom, $cutOffDateTo))->paginate(15); //$getTimesheetperCutoff = Timesheet::where('employee_id', $searchEmployeeId)->orderBy('daydate', 'asc')->paginate(15); ?> <div class="page-container"> <?php //echo $cutOffDateFrom; //echo $cutOffDateTo; /*foreach($getTimesheetperCutoff as $timesheet) { echo $timesheet->daydate; }*/ ?>
$hasOvertime = true; $overTime1 = '02:00:00'; $overTime2 = '01:00:00';*/ /*$emplooyeeSetting = new Setting; $getEmployeeSettingByEmployeeId = $emplooyeeSetting->getEmployeeSettingByEmployeeId(); return dd($getEmployeeSettingByEmployeeId); //If no setting found the result will be NULL break;*/ //Todo: Refactoring the code //Find the employee timesheet record for this day $employeeClocking = Timesheet::where('employee_id', '=', $employeeId)->where('daydate', '=', date('Y-m-d'))->first(); $otherDayDate = date("Y-m-d", strtotime('-2 days')); $getOtherDayDate = DB::table('employee_timesheet')->where('employee_id', $employeeId)->where('daydate', $otherDayDate)->get(); $yesterDayDate = date("Y-m-d", strtotime('yesterday')); $getYesterDayDate = DB::table('employee_timesheet')->where('employee_id', $employeeId)->where('daydate', $yesterDayDate)->get(); $employeeNightDiffClocking = Timesheet::where('employee_id', '=', $employeeId)->where('daydate', '=', $yesterDayDate)->first(); $employeeSummary = Summary::where('employee_id', '=', $employeeId)->where('daydate', '=', date('Y-m-d'))->first(); $employeeSummaryNightDiffClocking = Summary::where('employee_id', '=', $employeeId)->where('daydate', '=', $yesterDayDate)->first(); //Get Other day clocking if (!empty($getOtherDayDate[0])) { $otherday['time_in_1'] = $getOtherDayDate[0]->time_in_1; $otherday['time_in_2'] = $getOtherDayDate[0]->time_in_2; $otherday['time_in_3'] = $getOtherDayDate[0]->time_in_3; $otherday['time_out_1'] = $getOtherDayDate[0]->time_out_1; $otherday['time_out_2'] = $getOtherDayDate[0]->time_out_2; $otherday['time_out_3'] = $getOtherDayDate[0]->time_out_3; } if (!empty($getYesterDayDate[0])) { //Get Yesterday clocking $yesterday['time_in_1'] = $getYesterDayDate[0]->time_in_1; $yesterday['time_in_2'] = $getYesterDayDate[0]->time_in_2;
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'); } }
/** * Build the object with fetched records * * @access private * @return Timesheet[] array of timesheets */ private function _buildObjArr($result) { $objArr = null; while ($row = mysql_fetch_assoc($result)) { $tmpTimeArr = new Timesheet(); $tmpTimeArr->setTimesheetId($row[self::TIMESHEET_DB_FIELD_TIMESHEET_ID]); $tmpTimeArr->setEmployeeId($row[self::TIMESHEET_DB_FIELD_EMPLOYEE_ID]); $tmpTimeArr->setTimesheetPeriodId($row[self::TIMESHEET_DB_FIELD_TIMESHEET_PERIOD_ID]); $tmpTimeArr->setStartDate(date('Y-m-d', strtotime($row[self::TIMESHEET_DB_FIELD_START_DATE]))); $tmpTimeArr->setEndDate(date('Y-m-d', strtotime($row[self::TIMESHEET_DB_FIELD_END_DATE]))); $tmpTimeArr->setStatus($row[self::TIMESHEET_DB_FIELD_STATUS]); $tmpTimeArr->setComment($row[self::TIMESHEET_DB_FIELD_COMMENT]); $objArr[] = $tmpTimeArr; } return $objArr; }
} if ($currentCutoff === 1) { ////1st CutOff - e.g 11-25 $cutOffDateFrom = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_1; $cutOffDateTo = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_1; Session::put('cutOffDateFrom', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_1); Session::put('cutOffDateTo', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_1); } elseif ($currentCutoff === 2) { ////1st CutOff - e.g 26-10 $cutOffDateFrom = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2; $cutOffDateTo = $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2; Session::put('cutOffDateFrom', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_from_2); Session::put('cutOffDateTo', $adminCutoff->getCutoffbyYearMonth()->cutoff_date_to_2); } //$getTimesheetperCutoff = Timesheet::where('employee_id', $searchEmployeeId)->whereBetween('daydate', array($cutOffDateFrom, $cutOffDateTo))->paginate(5); $getTimesheetperCutoff = Timesheet::where('employee_id', $searchEmployeeId)->paginate(15); ?> <div class="page-container"> <?php //echo $cutOffDateFrom; //echo $cutOffDateTo; /*foreach($getTimesheetperCutoff as $timesheet) { echo $timesheet->daydate; }*/ ?> <div class="row" style="padding-bottom:20px;">
public function resolveTimesheet($submissionPeriodId = null) { if ($this->getTimesheetId() == null) { $timesheetObj = new Timesheet(); $timesheetSubmissionPeriodObj = new TimesheetSubmissionPeriod(); if ($submissionPeriodId != null) { $timesheetSubmissionPeriodObj->setTimesheetPeriodId($submissionPeriodId); } $timesheetSubmissionPeriods = $timesheetSubmissionPeriodObj->fetchTimesheetSubmissionPeriods(); $startTime = $this->getStartTime(); if (!isset($startTime)) { $startTime = $this->getReportedDate(); } $currTime = strtotime($startTime); $day = date('N', $currTime); $diff = $timesheetSubmissionPeriods[0]->getStartDay() - $day; if ($diff > 0) { $diff = $diff - 7; } $sign = $diff < 0 ? "" : "+"; $timesheetObj->setStartDate(date('Y-m-d', strtotime("{$sign}{$diff} day", $currTime))); $diff = $timesheetSubmissionPeriods[0]->getEndDay() - $day; if (0 > $diff) { $diff = $diff + 7; } $sign = $diff < 0 ? "" : "+"; $timesheetObj->setEndDate(date('Y-m-d', strtotime("{$sign}{$diff} day", $currTime)) . " 23:59:59"); $timesheetObj->setTimesheetPeriodId($timesheetSubmissionPeriods[0]->getTimesheetPeriodId()); $timesheetObj->setEmployeeId($this->getEmployeeId()); $timesheets = $timesheetObj->fetchTimesheets(); if (!$timesheets || !$timesheets[0]) { $timesheetObj->setStatus(Timesheet::TIMESHEET_STATUS_NOT_SUBMITTED); $timesheetObj->addTimesheet(); $timesheetObj->setTimesheetId(null); $timesheets = $timesheetObj->fetchTimesheets(); } $this->setTimesheetId($timesheets[0]->getTimesheetId()); } }
public function createTimesheets($startDate, $employeeId) { $datesInTheCurrenTimesheetPeriod = $this->getTimesheetPeriodService()->getDefinedTimesheetPeriod($startDate); $timesheetStartingDate = $datesInTheCurrenTimesheetPeriod[0]; $endDate = end($datesInTheCurrenTimesheetPeriod); $timesheet = $this->getTimesheetByStartDateAndEmployeeId($timesheetStartingDate, $employeeId); if ($timesheet == null) { if ($this->checkForOverlappingTimesheets($timesheetStartingDate, $endDate, $employeeId) == 0) { $statusValuesArray['state'] = 1; } else { $accessFlowStateMachineService = new AccessFlowStateMachineService(); $tempNextState = $accessFlowStateMachineService->getNextState(WorkflowStateMachine::FLOW_TIME_TIMESHEET, Timesheet::STATE_INITIAL, "SYSTEM", WorkflowStateMachine::TIMESHEET_ACTION_CREATE); $timesheet = new Timesheet(); $timesheet->setState($tempNextState); $timesheet->setStartDate($timesheetStartingDate); $timesheet->setEndDate($endDate); $timesheet->setEmployeeId($employeeId); $timesheet = $this->saveTimesheet($timesheet); $statusValuesArray['state'] = 2; $statusValuesArray['startDate'] = $timesheetStartingDate; } } else { $statusValuesArray['state'] = 3; } return $statusValuesArray; }
Route::get('users/logout', array('uses' => 'UsersController@doLogout')); Route::get('/employee/servertime', array('before' => 'auth', 'as' => 'updateServerTime', 'uses' => 'EmployeesController@updateServerTime')); Route::get('/employee/serverdatetime', array('before' => 'auth', 'as' => 'getServerDateTime', 'uses' => 'EmployeesController@getServerDateTime')); Route::get('/employee/clocking', array('before' => 'auth', 'as' => 'employeeTimesheet', 'uses' => 'EmployeesController@showEmployeeTimesheet')); Route::post('/employee/clocking', array('as' => 'timeClocking', 'uses' => function () { $data = Input::all(); echo Session::put('timeclocking', $data['timeclocking']); $workShift = new Workshift(); $getWorkShift = $workShift->getWorkShiftByEmployeeId(Auth::user()->employee_id); $todayDate = date('Y-m-d'); $holiday = new Holiday(); $getHolidayByDate = $holiday->getHolidayByDate($todayDate); //var_dump($employeeClocking); //$employeeId = Auth::user()->employee_id; //$workShift = DB::table('work_shift')->where('employee_id', $employeeId)->get(); $timesheet = new Timesheet(); $getTimesheetById = $timesheet->getTimesheetById(Auth::user()->employee_id, date('Y-m-d')); $schedule = new Schedule(); $hasSchedule = $schedule->checkSchedule(Auth::user()->employee_id, date('Y-m-d')); $getSchedule = $schedule->getSchedule(Auth::user()->employee_id, date('Y-m-d')); //Deduction Model $deduction = new Deduction(); $hasNightShiftStartTimeThreshold = true; $nightShiftStartTimeThreshold = 5; //It should be bigger; //get schedule //Check if there is assign schedule today //if ( $hasSchedule && strtotime($getSchedule[0]->start_time) !== strtotime('00:00:00')) { if ($hasSchedule && strtotime($getSchedule[0]->start_time) !== '') { $hasTodaySchedule = true; } else {
public static function userTimeForProject($projectId) { try { $users; $userIdList = \Projectcollabs::where('project_id', $projectId)->lists('user_id'); $taskIdList = \Task::where('project_id', $projectId)->lists('id'); foreach ($userIdList as $userId) { $tempUserData; $timeList = \Timesheet::whereIn('task_id', $taskIdList)->where('user_id', $userId)->lists('total_time_spent'); $totalTime = 0; foreach ($timeList as $time) { $totalTime = $totalTime + $time; } $user = \User::find($userId); $tempUserData['userName'] = $user->first_name . $user->last_name; $tempUserData['userId'] = $userId; $tempUserData['totalTime'] = \DateAndTime::convertTime($totalTime); $users[] = $tempUserData; } return $users; } catch (\Exception $e) { \Log::error('Something Went Wrong in Report Repository - userTimeForProject():' . $e->getMessage()); throw new SomeThingWentWrongException(); } }
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"; } }
function approveAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $this->_translate = Zend_Registry::get("translate"); $formvalues = $this->_getAllParams(); debugMessage($formvalues); // exit; if (!isArrayKeyAnEmptyString('id', $formvalues)) { if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 3; } $timesheet = new Timesheet(); $timesheet->populate(decode($formvalues['id'])); $timesheet->setStatus($formvalues['status']); if (!isEmptyString($timesheet->getDateIn()) && !isEmptyString($timesheet->getDateOut())) { $timesheet->setHours($timesheet->getComputedHours()); } $timesheet->setDateApproved(DEFAULT_DATETIME); $timesheet->setApprovedByID($session->getVar('userid')); if (!isArrayKeyAnEmptyString('reason', $formvalues)) { $timesheet->setComments("<br/>Rejected with remarks: " . $formvalues['reason']); } // debugMessage($timesheet->toArray()); try { if ($timesheet->save()) { $session->setVar(SUCCESS_MESSAGE, "Successfully Approved"); } $timesheet->afterApprove(); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } // exit; if (!isArrayKeyAnEmptyString('ids', $formvalues)) { $idsarray = array_remove_empty(explode(',', $formvalues['ids'])); // debugMessage($idsarray); if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 3; } $timesheet_collection = new Doctrine_Collection(Doctrine_Core::getTable("Timesheet")); if (count($idsarray) > 0) { $hrs = 0; foreach ($idsarray as $key => $id) { $timesheet = new Timesheet(); $timesheet->populate($id); $timesheet->setStatus($formvalues['status']); $timesheet->setHours($timesheet->getComputedHours()); // debugMessage($timesheet->getComputedHours()); $timesheet->setDateApproved(DEFAULT_DATETIME); $timesheet->setApprovedByID($session->getVar('userid')); $timesheet_collection->add($timesheet); // debugMessage($timesheet->toArray()); } try { if ($timesheet_collection->save()) { $msg = "Successfully Approved"; if ($formvalues['status'] == 4) { $msg = "Successfully Rejected"; } $session->setVar(SUCCESS_MESSAGE, $msg); foreach ($timesheet_collection as $timesheet) { $timesheet->afterApprove(); } } } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } } $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS))); }