/**
  *
  * @param array $leaveAssignmentData
  * @return bool
  */
 public function assignLeave(LeaveParameterObject $leaveAssignmentData)
 {
     $employeeId = $leaveAssignmentData->getEmployeeNumber();
     /* Check whether employee exists */
     if (empty($employeeId)) {
         throw new LeaveAllocationServiceException('Invalid Employee');
     }
     if ($this->applyMoreThanAllowedForADay($leaveAssignmentData)) {
         throw new LeaveAllocationServiceException('Failed to Assign: Work Shift Length Exceeded');
     } else {
         if (!$this->hasOverlapLeave($leaveAssignmentData)) {
             return $this->saveLeaveRequest($leaveAssignmentData);
             //                return true;
         }
     }
 }
 /**
  *
  * @param LeaveParameterObject $leaveAssignmentData
  * @param bool $isWeekend
  * @param bool $isHoliday
  * @param bool $isHalfday
  * @param bool $isHalfDayHoliday
  * @return int 
  */
 public function calculateTimeDeference(LeaveParameterObject $leaveAssignmentData, $isWeekend, $isHoliday, $isHalfday, $isHalfDayHoliday)
 {
     if ($isWeekend) {
         $timeDeference = 0;
     } elseif ($isHoliday) {
         if ($isHalfDayHoliday) {
             if ($leaveAssignmentData->getToDate() == $leaveAssignmentData->getFromDate()) {
                 if ($leaveAssignmentData->getWorkShiftLength() / 2 <= $leaveAssignmentData->getLeaveTotalTime()) {
                     $timeDeference = number_format($leaveAssignmentData->getWorkShiftLength() / 2, 3);
                 } else {
                     $timeDeference = $leaveAssignmentData->getLeaveTotalTime();
                 }
             } else {
                 $timeDeference = number_format($leaveAssignmentData->getWorkShiftLength() / 2, 3);
             }
         } else {
             $timeDeference = 0;
         }
     } elseif ($isHalfday) {
         if ($leaveAssignmentData->getToDate() == $leaveAssignmentData->getFromDate() && $leaveAssignmentData->getLeaveTotalTime() > 0) {
             if ($leaveAssignmentData->getWorkShiftLength() / 2 <= $leaveAssignmentData->getLeaveTotalTime()) {
                 $timeDeference = number_format($leaveAssignmentData->getWorkShiftLength() / 2, 3);
             } else {
                 $timeDeference = $leaveAssignmentData->getLeaveTotalTime();
             }
         } else {
             $timeDeference = number_format($leaveAssignmentData->getWorkShiftLength() / 2, 3);
         }
     } else {
         if ($leaveAssignmentData->getToDate() == $leaveAssignmentData->getFromDate()) {
             $timeDeference = $leaveAssignmentData->getLeaveTotalTime();
         } else {
             $timeDeference = $this->getWorkShiftLengthOfEmployee($leaveAssignmentData->getEmployeeNumber());
         }
     }
     return $timeDeference;
 }
 protected function getWorkflowItemForApplyAction(LeaveParameterObject $leaveAssignmentData)
 {
     if (is_null($this->applyWorkflowItem)) {
         $empNumber = $leaveAssignmentData->getEmployeeNumber();
         $workFlowItems = $this->getUserRoleManager()->getAllowedActions(WorkflowStateMachine::FLOW_LEAVE, 'INITIAL', array(), array(), array('Employee' => $empNumber));
         // get apply action
         foreach ($workFlowItems as $item) {
             if ($item->getAction() == 'APPLY') {
                 $this->applyWorkflowItem = $item;
                 break;
             }
         }
     }
     if (is_null($this->applyWorkflowItem)) {
         $this->getLogger()->error("No workflow item found for APPLY leave action!");
     }
     return $this->applyWorkflowItem;
 }