Example #1
0
 public function punchTime($punchIn)
 {
     $tmpObj = $this->getObjTime();
     if ($tmpObj == null) {
         $this->redirect('INVALID_TIME_FAILURE', "?timecode=Time&action=Show_Punch_Time");
     }
     $tmpObj->resolveTimesheet();
     $_GET['message'] = 'SUBMIT_SUCCESS';
     try {
         if ($punchIn) {
             if (Timesheet::checkDateInApprovedTimesheet($tmpObj->getReportedDate(), $tmpObj->getEmployeeId())) {
                 throw new TimeEventException("Failed to add time event", 1);
             }
             $res = $tmpObj->addTimeEvent();
             if (!$res) {
                 throw new TimeEventException("Failed to add time event", 0);
             }
         } else {
             $startTimeStr = $tmpObj->getStartTime();
             $endTimeStr = $tmpObj->getEndTime();
             $startTime = strtotime($startTimeStr);
             $endTime = strtotime($endTimeStr);
             $dateEndTime = strtotime(date("Y-m-d 23:59", strtotime($startTimeStr)));
             $dateEndTimeStr = date("Y-m-d H:i", $dateEndTime);
             if ($endTime > $dateEndTime) {
                 $tmpObj->setEndTime($dateEndTimeStr);
                 $tmpObj->setDuration($dateEndTime - $startTime);
                 $res = $tmpObj->editTimeEvent();
                 if (!$res) {
                     throw new TimeEventException("Failed to update time event", 0);
                 }
                 $tmpObj->setTimeEventId(null);
                 $tmpObj->setTimesheetId(null);
                 $tmpObj->setStartTime(date("Y-m-d H:i", $dateEndTime + 60));
                 $dateEndTime += 3600 * 24;
                 $dateEndTimeStr = date("Y-m-d H:i", $dateEndTime);
                 while ($endTime > $dateEndTime) {
                     $tmpObj->setEndTime($dateEndTimeStr);
                     $tmpObj->setDuration($dateEndTime - strtotime($tmpObj->getStartTime()));
                     $tmpObj->resolveTimesheet();
                     $res = $tmpObj->addTimeEvent();
                     if (!$res) {
                         throw new TimeEventException("Failed to add time event", 0);
                     }
                     $tmpObj->setStartTime(date("Y-m-d H:i", $dateEndTime + 60));
                     $dateEndTime += 3600 * 24;
                     $dateEndTimeStr = date("Y-m-d H:i", $dateEndTime);
                     $tmpObj->setTimesheetId(null);
                 }
                 $tmpObj->setEndTime($endTimeStr);
                 $tmpObj->setDuration($endTime - strtotime($tmpObj->getStartTime()));
                 $tmpObj->resolveTimesheet();
                 $res = $tmpObj->addTimeEvent();
                 if (!$res) {
                     throw new TimeEventException("Failed to add time event", 0);
                 }
             } else {
                 $res = $tmpObj->editTimeEvent();
                 if (!$res) {
                     throw new TimeEventException("Failed to update time event", 0);
                 }
             }
         }
     } catch (TimeEventException $exception) {
         if ($exception->getCode() == 0) {
             $_GET['message'] = 'SUBMIT_FAILURE';
         } elseif ($exception->getCode() == 1) {
             $_GET['message'] = 'APPROVED_TIMESHEET_FAILURE';
         } else {
             $_GET['message'] = 'EXCEPTION_THROWN_WARNING';
         }
     }
     $this->redirect($_GET['message'], "?timecode=Time&action=Show_Punch_Time");
     return $res;
 }
Example #2
0
 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);
 }