Exemplo n.º 1
0
 /**
  * Saves Leave Request and Sends Notification
  * 
  * @param LeaveParameterObject $leaveAssignmentData 
  * 
  */
 protected function saveLeaveRequest(LeaveParameterObject $leaveAssignmentData)
 {
     $leaveRequest = $this->generateLeaveRequest($leaveAssignmentData);
     $leaveType = $this->getLeaveTypeService()->readLeaveType($leaveAssignmentData->getLeaveType());
     $leaveRequest->setLeaveTypeName($leaveType->getLeaveTypeName());
     if (is_null($leaveRequest->getLeavePeriodId())) {
         if ($this->getLeavePeriodService()->isWithinNextLeavePeriod(strtotime($leaveRequest->getDateApplied()))) {
             $nextLeavePeriod = $this->getLeavePeriodService()->createNextLeavePeriod($leaveRequest->getDateApplied());
             $leaveRequest->setLeavePeriodId($nextLeavePeriod->getLeavePeriodId());
         }
     }
     $leaveDays = $this->createLeaveObjectListForAppliedRange($leaveAssignmentData);
     $holidayCount = 0;
     $holidays = array(Leave::LEAVE_STATUS_LEAVE_WEEKEND, Leave::LEAVE_STATUS_LEAVE_HOLIDAY);
     foreach ($leaveDays as $k => $leave) {
         if (in_array($leave->getLeaveStatus(), $holidays)) {
             $holidayCount++;
         }
     }
     /* This is to see whether employee applies leave only during weekends or standard holidays */
     if ($holidayCount != count($leaveDays)) {
         if ($this->isEmployeeAllowedToApply($leaveType)) {
             try {
                 $this->getLeaveRequestService()->saveLeaveRequest($leaveRequest, $leaveDays);
                 if ($this->isOverlapLeaveRequest($leaveAssignmentData)) {
                     $this->getLeaveRequestService()->modifyOverlapLeaveRequest($leaveRequest, $leaveDays);
                 }
                 /* Send notification to the when leave is assigned; TODO: Move to action? */
                 $leaveAssignmentMailer = new LeaveAssignmentMailer($leaveRequest, $leaveDays, $_SESSION['empNumber']);
                 $leaveAssignmentMailer->send();
                 return true;
             } catch (Exception $e) {
                 throw new LeaveAllocationServiceException('Leave Period Does Not Exist');
             }
         }
     } else {
         throw new LeaveAllocationServiceException('Failed to Submit: No Working Days Selected');
     }
 }
Exemplo n.º 2
0
 protected function sendEmail($leaveRequest, $leaveDays, $employeeNumber)
 {
     $leaveAssignmentMailer = new LeaveAssignmentMailer($leaveRequest, $leaveDays, $employeeNumber);
     $leaveAssignmentMailer->send();
 }