Esempio n. 1
0
 public function testCheckTimeOverlap()
 {
     $this->assertFalse(CommonFunctions::checkTimeOverlap('08:00', '09:00', '09:01', '13:00'));
     // start 2 = end 1 -> no overlap
     $this->assertFalse(CommonFunctions::checkTimeOverlap('08:00', '09:00', '09:00', '13:00'));
     $this->assertTrue(CommonFunctions::checkTimeOverlap('13:00', '21:00', '09:00', '14:00'));
     $this->assertTrue(CommonFunctions::checkTimeOverlap('11:00', '15:00', '13:00', '18:00'));
     $this->assertTrue(CommonFunctions::checkTimeOverlap('11:00', '15:00', '10:00', '18:00'));
     $this->assertTrue(CommonFunctions::checkTimeOverlap('17:00', '21:00', '18:00', '18:30'));
 }
Esempio n. 2
0
 public function addLeave()
 {
     $tmpObj = $this->getObjLeave();
     $fromDate = $tmpObj->getLeaveFromDate();
     $toDate = $tmpObj->getLeaveToDate();
     $authorizeObj = $this->authorize;
     if ($authorizeObj->isESS()) {
         $fromDateArray = explode("-", $fromDate);
         $toDateArray = explode("-", $toDate);
         if ($fromDateArray[0] == $toDateArray[0]) {
             $tmpLeaveQuota = new LeaveQuota();
             $tmpLeaveQuota->setEmployeeId($tmpObj->getEmployeeId());
             $tmpLeaveQuota->setYear($fromDateArray[0]);
             $tmpLeaveQuota->setLeaveTypeId($tmpObj->getLeaveTypeId());
             if ($tmpLeaveQuota->isBalanceZero()) {
                 $message = "BALANCE_ZERO";
                 return $message;
             }
         } else {
             $tmpLeaveQuota = new LeaveQuota();
             $tmpLeaveQuota->setEmployeeId($tmpObj->getEmployeeId());
             $tmpLeaveQuota->setYear($fromDateArray[0]);
             $tmpLeaveQuota->setLeaveTypeId($tmpObj->getLeaveTypeId());
             $tmpLeaveQuota1 = new LeaveQuota();
             $tmpLeaveQuota1->setEmployeeId($tmpObj->getEmployeeId());
             $tmpLeaveQuota1->setYear($toDateArray[0]);
             $tmpLeaveQuota1->setLeaveTypeId($tmpObj->getLeaveTypeId());
             if ($tmpLeaveQuota->isBalanceZero() && $tmpLeaveQuota1->isBalanceZero()) {
                 $message = "BALANCE_ZERO";
                 return $message;
             }
         }
     }
     $tmpLeave = new Leave();
     $duplicateList = $tmpLeave->retrieveDuplicateLeave($tmpObj->getEmployeeId(), $fromDate, $toDate);
     $rejects = array();
     $duplicates = array();
     if (!empty($duplicateList)) {
         foreach ($duplicateList as $dup) {
             if ($dup->getLeaveStatus() == Leave::LEAVE_STATUS_LEAVE_REJECTED) {
                 $rejects[] = $dup;
             } else {
                 $duplicates[] = $dup;
             }
         }
         /* Only rejected leave conflicts with current leave request */
         if (count($duplicates) == 0) {
             /* Change status of rejected leave requests to cancelled */
             foreach ($rejects as $rej) {
                 $rej->setLeaveStatus(Leave::LEAVE_STATUS_LEAVE_CANCELLED);
                 $res = $rej->changeLeaveStatus();
                 if (!$res) {
                     return "APPLY_FAILURE";
                 }
             }
         } else {
             /* If multiple day leave request, we don't need to check leave times.
              * Just throw an exception.
              */
             if ($fromDate != $toDate) {
                 throw new DuplicateLeaveException($duplicates);
             } else {
                 /* A single day leave request. We need to check leave times. */
                 // Count total hours and check for greater than workshift hours
                 $shift = Leave::LEAVE_LENGTH_FULL_DAY;
                 $workShift = Workshift::getWorkshiftForEmployee($tmpObj->getEmployeeId());
                 if (isset($workShift)) {
                     $shift = $workShift->getHoursPerDay();
                 }
                 $totalHours = 0;
                 foreach ($duplicates as $dup) {
                     $totalHours += $dup->getLeaveLengthHours();
                 }
                 if ($totalHours + $tmpObj->getLeaveLengthHours() > $shift) {
                     throw new DuplicateLeaveException($duplicates);
                 }
                 /* Check for overlapping leave times*/
                 $startTime = $tmpObj->getStartTime();
                 $endTime = $tmpObj->getEndTime();
                 if (!empty($startTime) && !empty($endTime)) {
                     foreach ($duplicates as $dup) {
                         $dupStartTime = $dup->getStartTime();
                         $dupEndTime = $dup->getEndTime();
                         if (!empty($dupStartTime) && !empty($dupEndTime)) {
                             $overlap = CommonFunctions::checkTimeOverlap($startTime, $endTime, $dupStartTime, $dupEndTime);
                             if ($overlap) {
                                 throw new DuplicateLeaveException($duplicates);
                             }
                         }
                     }
                 }
                 /* Show warning (Only if we haven't shown the warning before (in previous requst) for this date')*/
                 if (!isset($_POST['confirmDate']) || $_POST['confirmDate'] != $fromDate) {
                     throw new DuplicateLeaveException($duplicates, true);
                 }
             }
         }
     }
     $res = $tmpObj->applyLeaveRequest();
     $mailNotificaton = new MailNotifications();
     $mailNotificaton->setLeaveRequestObj($tmpObj);
     $mailNotificaton->setAction(MailNotifications::MAILNOTIFICATIONS_ACTION_APPLY);
     $mailNotificaton->send();
     $message = $res ? "APPLY_SUCCESS" : "APPLY_FAILURE";
     return $message;
 }