Esempio n. 1
0
 /**
  * get Leave Request
  * @return LeaveRequest
  */
 public function getLeaveRequest()
 {
     $posts = $this->getValues();
     $leaveRequest = new LeaveRequest();
     $leaveRequest->setLeaveTypeId($posts['txtLeaveType']);
     $leaveRequest->setDateApplied($posts['txtFromDate']);
     $leaveRequest->setLeavePeriodId($this->getLeavePeriod($posts['txtFromDate']));
     $leaveRequest->setEmpNumber($posts['txtEmpID']);
     $leaveRequest->setLeaveComments($posts['txtComment']);
     return $leaveRequest;
 }
 /**
  *
  * @param LeaveParameterObject $leaveAssignmentData
  * @return LeaveRequest 
  */
 protected function generateLeaveRequest(LeaveParameterObject $leaveAssignmentData)
 {
     $leavePeriodId = null;
     $leavePeriod = $this->getLeavePeriodService()->getLeavePeriod(strtotime($leaveAssignmentData->getFromDate()));
     if (!is_null($leavePeriod) && $leavePeriod instanceof LeavePeriod) {
         $leavePeriodId = $leavePeriod->getLeavePeriodId();
     }
     $leaveRequest = new LeaveRequest();
     $leaveRequest->setLeaveTypeId($leaveAssignmentData->getLeaveType());
     $leaveRequest->setDateApplied($leaveAssignmentData->getFromDate());
     $leaveRequest->setLeavePeriodId($leavePeriodId);
     $leaveRequest->setEmpNumber($leaveAssignmentData->getEmployeeNumber());
     $leaveRequest->setLeaveComments($leaveAssignmentData->getComment());
     return $leaveRequest;
 }
 /**
  * Modify Overlap leave request
  * @param LeaveRequest $leaveRequest
  * @return boolean
  */
 public function xmodifyOverlapLeaveRequest(LeaveRequest $leaveRequest, $leaveList, $leavePeriod = null)
 {
     try {
         $nextLeavePeriod = false;
         $nextLeaveRequest = false;
         if ($leavePeriod == null) {
             $leavePeriod = Doctrine::getTable('LeavePeriod')->find($leaveRequest->getLeavePeriodId());
         }
         foreach ($leaveList as $leave) {
             if ($leave->getLeaveDate() > $leavePeriod->getEndDate()) {
                 if (!$nextLeavePeriod instanceof LeavePeriod) {
                     $leavePeriodService = new LeavePeriodService();
                     $leavePeriodService->setLeavePeriodDao(new LeavePeriodDao());
                     $nextLeavePeriod = $leavePeriodService->createNextLeavePeriod($leave->getLeaveDate());
                     $nextLeaveRequest = new LeaveRequest();
                     $idGenService = new IDGeneratorService();
                     $idGenService->setEntity($leaveRequest);
                     $nextLeaveRequest->setLeaveRequestId($idGenService->getNextID());
                     $nextLeaveRequest->setLeaveTypeId($leaveRequest->getLeaveTypeId());
                     $nextLeaveRequest->setDateApplied($leaveRequest->getDateApplied());
                     $nextLeaveRequest->setLeavePeriodId($nextLeavePeriod->getLeavePeriodId());
                     $nextLeaveRequest->setLeaveTypeName($leaveRequest->getLeaveTypeName());
                     $nextLeaveRequest->setEmpNumber($leaveRequest->getEmpNumber());
                     $nextLeaveRequest->setLeaveComments($leaveRequest->getLeaveComments());
                     $nextLeaveRequest->save();
                 }
                 $q = Doctrine_Query::create()->update('Leave l')->set('l.leave_request_id=', $nextLeaveRequest->getLeaveRequestId())->where('l.leave_id = ?', $leave->getLeaveId());
                 $q->execute();
             }
         }
         return true;
     } catch (Exception $e) {
         throw new DaoException($e->getMessage());
     }
 }
 public function xtestModifyOverlapLeaveRequest()
 {
     /* Preparing required data */
     $leaveRequest = new LeaveRequest();
     $leaveRequest->setLeavePeriodId(1);
     $leaveRequest->setLeaveTypeId('LTY001');
     $leaveRequest->setLeaveTypeName('Casual');
     $leaveRequest->setDateApplied('2010-12-01');
     $leaveRequest->setEmpNumber(1);
     $leave[0] = new Leave();
     $leave[0]->setLeaveLengthHours(8);
     $leave[0]->setLeaveLengthDays(1);
     $leave[0]->setLeaveDate('2010-12-30');
     $leave[0]->setLeaveStatus(1);
     $leave[1] = new Leave();
     $leave[1]->setLeaveLengthHours(8);
     $leave[1]->setLeaveLengthDays(1);
     $leave[1]->setLeaveDate('2010-12-31');
     $leave[1]->setLeaveStatus(1);
     $leave[2] = new Leave();
     $leave[2]->setLeaveLengthHours(8);
     $leave[2]->setLeaveLengthDays(1);
     $leave[2]->setLeaveDate('2011-01-01');
     $leave[2]->setLeaveStatus(1);
     $leave[3] = new Leave();
     $leave[3]->setLeaveLengthHours(8);
     $leave[3]->setLeaveLengthDays(1);
     $leave[3]->setLeaveDate('2011-01-02');
     $leave[3]->setLeaveStatus(1);
     $leavePeriod = TestDataService::fetchObject('LeavePeriod', 1);
     /* Executing tests */
     /* At use, modifyOverlapLeaveRequest() is called after calling
      * saveLeaveRequest()
      */
     $leaveRequest = $this->leaveRequestDao->saveLeaveRequest($leaveRequest, $leave);
     $this->assertTrue($leaveRequest instanceof LeaveRequest);
     $this->assertTrue($this->leaveRequestDao->modifyOverlapLeaveRequest($leaveRequest, $leave, $leavePeriod));
     $leaveRequestList = TestDataService::fetchLastInsertedRecords('LeaveRequest', 2);
     $this->assertEquals(21, $leaveRequestList[0]->getLeaveRequestId());
     $this->assertEquals('LTY001', $leaveRequestList[0]->getLeaveTypeId());
     $this->assertEquals('Casual', $leaveRequestList[0]->getLeaveTypeName());
     $this->assertEquals('2010-12-01', $leaveRequestList[0]->getDateApplied());
     $this->assertEquals(1, $leaveRequestList[0]->getEmpNumber());
     $this->assertEquals(22, $leaveRequestList[1]->getLeaveRequestId());
     $this->assertEquals('LTY001', $leaveRequestList[1]->getLeaveTypeId());
     $this->assertEquals('Casual', $leaveRequestList[1]->getLeaveTypeName());
     $this->assertEquals('2010-12-01', $leaveRequestList[1]->getDateApplied());
     $this->assertEquals(1, $leaveRequestList[1]->getEmpNumber());
     $leaveList = TestDataService::fetchLastInsertedRecords('Leave', 4);
     $this->assertEquals(36, $leaveList[0]->getId());
     $this->assertEquals(8, $leaveList[0]->getLengthHours());
     $this->assertEquals(1, $leaveList[0]->getLengthDays());
     $this->assertEquals(21, $leaveList[0]->getLeaveRequestId());
     $this->assertEquals('LTY001', $leaveList[0]->getLeaveTypeId());
     $this->assertEquals(1, $leaveList[0]->getEmpNumber());
     $this->assertEquals('2010-12-30', $leaveList[0]->getDate());
     $this->assertEquals(1, $leaveList[0]->getStatus());
     $this->assertEquals(37, $leaveList[1]->getId());
     $this->assertEquals(8, $leaveList[1]->getLengthHours());
     $this->assertEquals(1, $leaveList[1]->getLengthDays());
     $this->assertEquals(21, $leaveList[1]->getLeaveRequestId());
     $this->assertEquals('LTY001', $leaveList[1]->getLeaveTypeId());
     $this->assertEquals(1, $leaveList[1]->getEmpNumber());
     $this->assertEquals('2010-12-31', $leaveList[1]->getDate());
     $this->assertEquals(1, $leaveList[1]->getStatus());
     $this->assertEquals(38, $leaveList[2]->getId());
     $this->assertEquals(8, $leaveList[2]->getLengthHours());
     $this->assertEquals(1, $leaveList[2]->getLengthDays());
     $this->assertEquals(22, $leaveList[2]->getLeaveRequestId());
     $this->assertEquals('LTY001', $leaveList[2]->getLeaveTypeId());
     $this->assertEquals(1, $leaveList[2]->getEmpNumber());
     $this->assertEquals('2011-01-01', $leaveList[2]->getDate());
     $this->assertEquals(1, $leaveList[2]->getStatus());
     $this->assertEquals(39, $leaveList[3]->getId());
     $this->assertEquals(8, $leaveList[3]->getLengthHours());
     $this->assertEquals(1, $leaveList[3]->getLengthDays());
     $this->assertEquals(22, $leaveList[3]->getLeaveRequestId());
     $this->assertEquals('LTY001', $leaveList[3]->getLeaveTypeId());
     $this->assertEquals(1, $leaveList[3]->getEmpNumber());
     $this->assertEquals('2011-01-02', $leaveList[3]->getDate());
     $this->assertEquals(1, $leaveList[3]->getStatus());
 }