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); }
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; }
/** * Save employee leave carried forward for given period * @param int $employeeId * @param int $leaveTypeId * @param int $leavePeriodId * @param float $carriedForwardLeaveLength * @return boolean */ public function saveEmployeeLeaveCarriedForward($employeeId, $leaveTypeId, $leavePeriodId, $carriedForwardLeaveLength) { try { $leaveEntitlement = $this->readEmployeeLeaveEntitlement($employeeId, $leaveTypeId, $leavePeriodId); if (!$leaveEntitlement instanceof EmployeeLeaveEntitlement) { $leaveEntitlement = new EmployeeLeaveEntitlement(); $leaveEntitlement->setLeaveTypeId($leaveTypeId); $leaveEntitlement->setLeavePeriodId($leavePeriodId); $leaveEntitlement->setEmployeeId($employeeId); } $leaveEntitlement->setLeaveCarriedForward($carriedForwardLeaveLength); $leaveEntitlement->save(); return true; } catch (Exception $e) { throw new DaoException($e->getMessage()); } }
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)); }