public function execute($request)
 {
     $form = $this->getForm();
     $saveSuccess = true;
     $logger = Logger::getLogger('saveLeaveEntitlementsAction');
     if ($request->isMethod(sfRequest::POST)) {
         $form->bind($request->getParameter($form->getName()));
         $hdnEmpId = $request->getParameter('hdnEmpId');
         $hdnLeaveTypeId = $request->getParameter('hdnLeaveTypeId');
         $leavePeriodId = $request->getParameter('leavePeriodId');
         $txtLeaveEntitled = $request->getParameter('txtLeaveEntitled');
         $idCount = count($hdnEmpId);
         $leaveTypeCount = count($hdnLeaveTypeId);
         $count = count($txtLeaveEntitled);
         /*
          * Validate we have all input values for all rows.
          */
         if ($count != $idCount || $count != $leaveTypeCount) {
             $logger->error("saveLeaveEntitlements: field count does not match: " . " employee ids={$idCount}, leaveTypeIds={$hdnLeaveTypeId}, entitlements={$txtLeaveEntitled}");
             $logger->error($hdnEmpId);
             $logger->error($hdnLeaveTypeId);
             $logger->error($txtLeaveEntitled);
             $saveSuccess = false;
         } else {
             $leaveEntitlementService = $this->getLeaveEntitlementService();
             $leaveSummaryData = $request->getParameter('leaveSummary');
             if ($count > 0) {
                 $employeeLeaveEntitlementList = $leaveEntitlementService->searchEmployeeLeaveEntitlement($hdnEmpId, $hdnLeaveTypeId, $leavePeriodId, $count);
                 $employeeLeaveEntitlementArray = $this->getEmployeeLeaveEntitlementArray($employeeLeaveEntitlementList);
                 $employeeLeaveEntitlements = array();
                 for ($i = 0; $i < $count; $i++) {
                     $arrayKey = $hdnEmpId[$i] . "_" . $hdnLeaveTypeId[$i];
                     if (array_key_exists($arrayKey, $employeeLeaveEntitlementArray)) {
                         $employeeLeaveEntitlement = $employeeLeaveEntitlementArray[$arrayKey];
                         $employeeLeaveEntitlement->setNoOfDaysAllotted($txtLeaveEntitled[$i]);
                     } else {
                         $employeeLeaveEntitlement = new EmployeeLeaveEntitlement();
                         $employeeLeaveEntitlement->setLeaveTypeId($hdnLeaveTypeId[$i]);
                         $employeeLeaveEntitlement->setEmployeeId($hdnEmpId[$i]);
                         $employeeLeaveEntitlement->setLeavePeriodId($leavePeriodId);
                         $employeeLeaveEntitlement->setNoOfDaysAllotted($txtLeaveEntitled[$i]);
                     }
                     $employeeLeaveEntitlements[] = $employeeLeaveEntitlement;
                 }
                 try {
                     $leaveEntitlementService->saveEmployeeLeaveEntitlementCollection($employeeLeaveEntitlements);
                 } catch (Exception $e) {
                     $logger->error($e);
                     $saveSuccess = false;
                 }
             }
         }
         if ($saveSuccess) {
             $this->getUser()->setFlash('templateMessage', array('SUCCESS', __(TopLevelMessages::SAVE_SUCCESS)), false);
         } else {
             $this->getUser()->setFlash('templateMessage', array('FAILURE', __(TopLevelMessages::SAVE_FAILURE)), false);
         }
         $this->forwardToLeaveSummary();
     }
 }
 public function testSaveEmployeeLeaveEntitlementCollection()
 {
     $employeeLeaveEntitlementCollection = new Doctrine_Collection('EmployeeLeaveEntitlement');
     $employeeLeaveEntitlementList = array();
     $employeeLeaveEntitlement = new EmployeeLeaveEntitlement();
     $employeeLeaveEntitlement->setLeaveTypeId(1);
     $employeeLeaveEntitlement->setLeavePeriodId(1);
     $employeeLeaveEntitlement->setEmployeeId(1);
     $employeeLeaveEntitlement->setNoOfDaysAllotted(14);
     $employeeLeaveEntitlement->setLeaveBroughtForward(2);
     $employeeLeaveEntitlement->setLeaveCarriedForward(5);
     $employeeLeaveEntitlementCollection->add($employeeLeaveEntitlement);
     $employeeLeaveEntitlementList[] = $employeeLeaveEntitlement;
     $employeeLeaveEntitlement = new EmployeeLeaveEntitlement();
     $employeeLeaveEntitlement->setLeaveTypeId(1);
     $employeeLeaveEntitlement->setLeavePeriodId(1);
     $employeeLeaveEntitlement->setEmployeeId(2);
     $employeeLeaveEntitlement->setNoOfDaysAllotted(20);
     $employeeLeaveEntitlement->setLeaveBroughtForward(3);
     $employeeLeaveEntitlement->setLeaveCarriedForward(4);
     $employeeLeaveEntitlementCollection->add($employeeLeaveEntitlement);
     $employeeLeaveEntitlementList[] = $employeeLeaveEntitlement;
     $leaveEntitlementDao = $this->getMock('LeaveEntitlementDao', array('saveEmployeeLeaveEntitlementCollection'));
     $leaveEntitlementDao->expects($this->once())->method('saveEmployeeLeaveEntitlementCollection')->with($employeeLeaveEntitlementList)->will($this->returnValue($employeeLeaveEntitlementCollection));
     $leaveEntitlementService = new LeaveEntitlementService();
     $leaveEntitlementService->setLeaveEntitlementDao($leaveEntitlementDao);
     $results = $leaveEntitlementService->saveEmployeeLeaveEntitlementCollection($employeeLeaveEntitlementList);
     $this->assertEquals($employeeLeaveEntitlementCollection, $results);
 }
Пример #3
0
 /**
  * Save employee leave brought forward for given period
  * @param int $employeeId
  * @param int $leaveTypeId
  * @param int $leavePeriodId
  * @param float $broughtForwardLeaveLength
  * @return boolean
  */
 public function saveEmployeeLeaveBroughtForward($employeeId, $leaveTypeId, $leavePeriodId, $broughtForwardLeaveLength)
 {
     try {
         $leaveEntitlement = $this->readEmployeeLeaveEntitlement($employeeId, $leaveTypeId, $leavePeriodId);
         if (!$leaveEntitlement instanceof EmployeeLeaveEntitlement) {
             $leaveEntitlement = new EmployeeLeaveEntitlement();
             $leaveEntitlement->setLeaveTypeId($leaveTypeId);
             $leaveEntitlement->setLeavePeriodId($leavePeriodId);
             $leaveEntitlement->setEmployeeId($employeeId);
             $leaveEntitlement->setNoOfDaysAllotted(0);
         }
         $leaveEntitlement->setLeaveBroughtForward($broughtForwardLeaveLength);
         $leaveEntitlement->save();
         return true;
     } catch (Exception $e) {
         throw new DaoException($e->getMessage());
     }
 }
Пример #4
0
 public function testSaveEmployeeLeaveEntitlementCollection()
 {
     $leaveEntitilementFixture = sfConfig::get('sf_plugins_dir') . '/orangehrmCoreLeavePlugin/test/fixtures/leaveEntitlement.yml';
     TestDataService::populate($leaveEntitilementFixture);
     $leaveEntitlementList = array();
     $employeeLeaveEntitlement = new EmployeeLeaveEntitlement();
     $employeeLeaveEntitlement->setLeaveTypeId('LTY002');
     $employeeLeaveEntitlement->setEmployeeId(2);
     $employeeLeaveEntitlement->setLeavePeriodId(1);
     $employeeLeaveEntitlement->setNoOfDaysAllotted(40);
     $leaveEntitlementList[] = $employeeLeaveEntitlement;
     $employeeLeaveEntitlement = TestDataService::fetchObject('EmployeeLeaveEntitlement', array('LTY001', 1, 1));
     //$employeeLeaveEntitlement = $this->leaveEntitlementDao->getEmployeeLeaveEntitlement(1, 'LTY001', 1);
     $employeeLeaveEntitlement->setNoOfDaysAllotted(50);
     $leaveEntitlementList[] = $employeeLeaveEntitlement;
     $results = $this->leaveEntitlementDao->saveEmployeeLeaveEntitlementCollection($leaveEntitlementList);
     $employeeLeaveEntitlement = TestDataService::fetchObject('EmployeeLeaveEntitlement', array('LTY001', 1, 1));
     //$employeeLeaveEntitlement = $this->leaveEntitlementDao->getEmployeeLeaveEntitlement(1, 'LTY001', 1);
     $this->assertEquals(50.0, $employeeLeaveEntitlement->getNoOfDaysAllotted());
     $employeeLeaveEntitlement = TestDataService::fetchObject('EmployeeLeaveEntitlement', array('LTY002', 2, 1));
     //$employeeLeaveEntitlement = $this->leaveEntitlementDao->getEmployeeLeaveEntitlement(2, 'LTY002', 1);
     $this->assertEquals(40.0, $employeeLeaveEntitlement->getNoOfDaysAllotted());
 }
Пример #5
0
 public function fetchRawLeaveSummaryRecords($clues, $offset, $limit)
 {
     $includeTerminated = false;
     if ($clues['cmbWithTerminated'] != 0) {
         $includeTerminated = true;
     }
     $recordsResult = $this->getLeaveSummaryDao()->fetchRawLeaveSummaryRecords($clues, $offset, $limit, $includeTerminated);
     $recordsCount = $this->fetchRawLeaveSummaryRecordsCount($clues, $includeTerminated);
     $leaveEntitlementService = new LeaveEntitlementService();
     $leaveEntitlementService->setLeaveEntitlementDao(new LeaveEntitlementDao());
     $leavePeriodService = new LeavePeriodService();
     $leavePeriodService->setLeavePeriodDao(new LeavePeriodDao());
     $summaryListArray = array();
     if ($recordsCount > 0) {
         $i = 0;
         while ($row = $recordsResult->fetch()) {
             $employeeName = $row['empFirstName'] . ' ' . $row['empLastName'];
             $employeeId = $row['empNumber'];
             $employeeStatus = $row['empStatus'];
             $leaveType = $row['leaveTypeName'];
             $leaveTypeId = $row['leaveTypeId'];
             $leavePeriodId = $clues['cmbLeavePeriod'] ? $clues['cmbLeavePeriod'] : $leavePeriodService->getCurrentLeavePeriod();
             $leaveEntitlementObj = $leaveEntitlementService->readEmployeeLeaveEntitlement($employeeId, $leaveTypeId, $leavePeriodId);
             if ($leaveEntitlementObj instanceof EmployeeLeaveEntitlement) {
                 $leaveEntitled = $leaveEntitlementObj->getNoOfDaysAllotted();
                 $leaveBroughtForward = $leaveEntitlementObj->getLeaveBroughtForward();
                 $leaveCarryForward = $leaveEntitlementObj->getLeaveCarriedForward();
             } else {
                 $leaveEntitled = '0.00';
                 $leaveBroughtForward = '0.00';
                 $leaveCarryForward = '0.00';
             }
             $leaveRequestService = new LeaveRequestService();
             $leaveRequestService->setLeaveRequestDao(new LeaveRequestDao());
             $leaveTaken = $leaveRequestService->getTakenLeaveSum($employeeId, $leaveTypeId, $leavePeriodId);
             $leaveTaken = empty($leaveTaken) ? '0.00' : $leaveTaken;
             //$leaveScheduled = $this->_getLeaveScheduled($employeeId, $leaveTypeId, $leavePeriodId);
             $leaveScheduled = $leaveRequestService->getScheduledLeavesSum($employeeId, $leaveTypeId, $leavePeriodId);
             $leaveScheduled = empty($leaveScheduled) ? '0.00' : $leaveScheduled;
             $leaveRemaining = $leaveEntitled + $leaveBroughtForward - ($leaveTaken + $leaveScheduled + $leaveCarryForward);
             $leaveRemaining = number_format($leaveRemaining, 2);
             $rowDisplayFlag = false;
             $deletedFlag = false;
             //show active leave types
             if ($row['availableFlag'] == 1) {
                 $rowDisplayFlag = true;
             }
             //show inactive leave types if any leaveEntitled, leaveTaken, leaveScheduled of them above 0
             if ($row['availableFlag'] != 1 && ($leaveEntitled > 0 || $leaveTaken > 0 || $leaveScheduled > 0)) {
                 $rowDisplayFlag = true;
                 $deletedFlag = true;
             }
             if ($rowDisplayFlag) {
                 $summaryListRow = array();
                 $employeeLeaveEntitlementObject = new EmployeeLeaveEntitlement();
                 // If readonly value is 1, force read only
                 if (isset($row['readonly']) && $row['readonly'] == 1) {
                     $employeeLeaveEntitlementObject->setForceReadOnly(true);
                 }
                 $employeeLeaveEntitlementObject->setEmployeeId($employeeId);
                 $employeeLeaveEntitlementObject->setEmployeeStatus($employeeStatus);
                 $employeeLeaveEntitlementObject->setLeaveTypeId($leaveTypeId);
                 $employeeLeaveEntitlementObject->setNoOfDaysAllotted($leaveEntitled);
                 $employeeLeaveEntitlementObject->setLeaveBroughtForward($leaveBroughtForward);
                 $employeeLeaveEntitlementObject->setLeaveCarriedForward($leaveCarryForward);
                 $employeeLeaveEntitlementObject->setLeavePeriodId($leavePeriodId);
                 $summaryListArray[] = $employeeLeaveEntitlementObject;
                 $i++;
             }
         }
     }
     return $summaryListArray;
 }
 public function testGetLeaveBalanceExistingRecords()
 {
     $employeeLeaveEntitlement = new EmployeeLeaveEntitlement();
     $employeeLeaveEntitlement->setNoOfDaysAllotted(14);
     $employeeLeaveEntitlement->setLeaveBroughtForward(2);
     $employeeLeaveEntitlement->setLeaveCarriedForward(5);
     $leaveEntitlementService = $this->getMock('LeaveEntitlementService', array('readEmployeeLeaveEntitlement'));
     $leaveEntitlementService->expects($this->once())->method('readEmployeeLeaveEntitlement')->with(1, 'LTY001', 1)->will($this->returnValue($employeeLeaveEntitlement));
     $leaveRequestService = $this->getMock('LeaveRequestService', array('getScheduledLeavesSum', 'getTakenLeaveSum'));
     $leaveRequestService->expects($this->once())->method('getScheduledLeavesSum')->with(1, 'LTY001', 1)->will($this->returnValue(3));
     $leaveRequestService->expects($this->once())->method('getTakenLeaveSum')->with(1, 'LTY001', 1)->will($this->returnValue(2));
     $leaveEntitlementService->setLeaveRequestService($leaveRequestService);
     $this->assertEquals(6, $leaveEntitlementService->getLeaveBalance(1, 'LTY001', 1));
 }