예제 #1
0
 /**
  * Send email with given parameters
  *
  * @param mixed $to Array of email address, or single email address
  * @param String $subject Email subject
  * @param String $body Email body
  * @param int $notificationType Notification type, used to fetch other emails subscribed to this type
  *
  * @return boolean True if mail sent, false otherwise
  */
 private function _sendMail($to, $subject, $body, $notificationType, $attachments = null)
 {
     $mailer = $this->_getMailer();
     $mailer->setBodyText($body);
     if (!empty($attachments) && is_array($attachments)) {
         foreach ($attachments as $attachment) {
             $mailer->addAttachment($attachment);
         }
     }
     // Trim newlines, carriage returns from subject.
     $subject = $this->_removeNewLines($subject);
     $mailer->setSubject($subject);
     if (empty($notificationType)) {
         $notificationAddresses = null;
     } else {
         $mailNotificationObj = new EmailNotificationConfiguration();
         $notificationAddresses = $mailNotificationObj->fetchMailNotifications($notificationType);
     }
     $logMessage = date('r') . " Sending {$subject} ";
     /*
      * Check if at least one receipient available.
      * If no 'to' receipients are available, one of the cc emails is used as the to address.
      */
     if (empty($to)) {
         if (empty($notificationAddresses)) {
             $logMessage .= " - FAILED \r\nReason: No receipients";
             $this->_log($logMessage);
             return false;
         } else {
             $to = array(array_shift($notificationAddresses));
         }
     } else {
         if (!is_array($to)) {
             $to = array($to);
         }
     }
     /* Setting to addresses */
     foreach ($to as $toAdd) {
         $mailer->addTo($toAdd);
         $logMessage .= "\r\n" . $toAdd;
     }
     /* Setting cc addresses */
     if (is_array($notificationAddresses)) {
         foreach ($notificationAddresses as $toCc) {
             $mailer->addCc($toCc);
             $logMessage .= "\r\n" . $toCc;
         }
     }
     $mailResult = true;
     try {
         $mailer->send();
         $logMessage .= " - SUCCEEDED";
     } catch (Exception $e) {
         $mailResult = false;
         $errorMsg = $e->getMessage();
         if (isset($errorMsg)) {
             $logMessage .= " - FAILED \r\nReason: {$errorMsg}";
         }
     }
     $this->_log($logMessage);
     return $mailResult;
 }
예제 #2
0
 /**
  * builds leave applied notification
  *
  */
 private function _applyMail()
 {
     $this->notificationTypeId = EmailNotificationConfiguration::EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_LEAVE_PENDING_APPROVAL;
     $this->templateFile = file_get_contents(ROOT_PATH . "/templates/leave/mails/" . self::MAILNOTIFICATIONS_TEMPLATE_APPLY);
     $txt = $this->templateFile;
     $leaveObjs = $this->getLeaveObjs();
     $txtArr = preg_split('/#\\{(.*)\\}/', $txt, null, PREG_SPLIT_DELIM_CAPTURE);
     $recordTxt = $txtArr[1];
     $recordArr = null;
     $fulldays = 0;
     if (is_array($leaveObjs)) {
         foreach ($leaveObjs as $leaveObj) {
             if ($leaveObj->getLeaveStatus() == Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL) {
                 $leaveLength = $leaveObj->getLeaveLengthHours();
                 $fulldays += $leaveObj->getLeaveLengthDays();
                 $duration = $leaveObj->getLeaveLengthHours();
                 $date = $leaveObj->getLeaveDate();
                 $type = $leaveObj->getLeaveTypeName();
                 $comments = $leaveObj->getLeaveComments();
                 $recordArr[] = preg_replace(array('/#date/', '/#type/', '/#duration/', '/#comments/'), array($date, $type, $duration, $comments), $recordTxt);
             }
         }
     }
     $recordTxt = "";
     if (isset($recordArr)) {
         $recordTxt = join("\r\n", $recordArr);
     }
     $txt = $txtArr[0] . $recordTxt . $txtArr[2];
     if (isset($leaveObjs[0])) {
         $employeeName = $leaveObjs[0]->getEmployeeName();
         $employeeId = $leaveObjs[0]->getEmployeeId();
         $this->_getAddresses($employeeId);
         $txt = preg_replace('/#' . self::MAILNOTIFICATIONS_VARIABLE_SUBORDINATE . '/', $employeeName, $txt);
         $this->subject = $this->_getMailSubject(self::MAILNOTIFICATIONS_TEMPLATE_APPLY_SUBJECT, $employeeName, $fulldays);
         $this->to = $this->supervisorMail;
         if (empty($this->supervisorMail)) {
             $mailNotificationObj = new EmailNotificationConfiguration();
             $this->to = $mailNotificationObj->fetchMailNotifications($this->notificationTypeId);
         }
     }
     $this->mail = $txt;
 }
예제 #3
0
 public static function saveHspRequest($hspReqest)
 {
     try {
         $empId = $hspReqest->getEmployeeId();
         $year = date('Y', strtotime($hspReqest->getDateIncurred()));
         $amount = $hspReqest->getExpenseAmount();
         $hspId = $hspReqest->getHspId();
         switch ($hspId) {
             case 1:
                 if ($year != date('Y')) {
                     throw new HspPaymentRequestException('Requests for the previous year are not allowed under the current health savings plan', HspPaymentRequestException::INVALID_DATE_PREVIOUS_YEAR);
                 }
                 $personalHspSummary = HspSummary::fetchHspSummary($year, 1, $empId);
                 if (is_null($personalHspSummary)) {
                     throw new HspPaymentRequestException('HSP Summary details not defined by HR Admins', HspPaymentRequestException::NO_HSP);
                 }
                 $amountLimit = $personalHspSummary[0]->getTotalAccrued() - $personalHspSummary[0]->getTotalUsed();
                 break;
             case 2:
                 if ($year != date('Y')) {
                     throw new HspPaymentRequestException('Requests for the previous year are not allowed under the current health savings plan', HspPaymentRequestException::INVALID_DATE_PREVIOUS_YEAR);
                 }
                 $personalHspSummary = HspSummary::fetchHspSummary($year, 1, $empId);
                 if (is_null($personalHspSummary)) {
                     throw new HspPaymentRequestException('HSP Summary details not defined by HR Admins', HspPaymentRequestException::NO_HSP);
                 }
                 if (count($personalHspSummary) == 2) {
                     $index = $personalHspSummary[0]->getHspPlanName() == 'HRA' ? 0 : 1;
                 } else {
                     $index = 0;
                 }
                 $amountLimit = $personalHspSummary[$index]->getTotalAccrued() - $personalHspSummary[$index]->getTotalUsed();
                 break;
             case 3:
                 $reqError = BenefitsController::_validateFSARequest($year);
                 if (is_null($reqError)) {
                     $personalHspSummary = HspSummary::fetchHspSummary($year, 1, $empId);
                     if (is_null($personalHspSummary)) {
                         throw new HspPaymentRequestException('HSP Summary details not defined by HR Admins', HspPaymentRequestException::NO_HSP);
                     }
                     $index = count($personalHspSummary) == 2 ? 1 : 0;
                     if ($year == date('Y') - 1) {
                         $amountLimit = HspSummary::_fetchLastYearFsaBalance($empId, $year);
                     } else {
                         $amountLimit = $personalHspSummary[$index]->getAnnualLimit() - $personalHspSummary[$index]->getTotalUsed();
                     }
                 } else {
                     throw $reqError;
                 }
                 break;
         }
         if ($amount > $amountLimit) {
             throw new HspPaymentRequestException('Request amount cannot exceed the annual limit', HspPaymentRequestException::EXCEED_LIMIT);
         }
         $msg = 'SAVE_SUCCESS';
         $hspReqest->addHspRequest();
         $server = $_SERVER['HTTP_HOST'];
         $path = str_replace(__FILE__, '', $_SERVER['REQUEST_URI']);
         $link = 'http://' . $server . $path . '&benefitcode=Benefits&action=View_Edit_Hsp_Request&id=' . $hspReqest->getId();
         /* Informing HR Admin: Begins */
         $notificationObj = new EmailNotificationConfiguration();
         $mailAddress = $notificationObj->fetchMailNotifications(EmailNotificationConfiguration::EMAILNOTIFICATIONCONFIGURATION_NOTIFICATION_TYPE_HSP);
         if (isset($mailAddress)) {
             $hspMailNotification = new HspMailNotification();
             $hspMailNotification->sendHspPaymentRequestNotifications($hspReqest, $link);
         }
         /* Informing HR Admin: Ends */
     } catch (HspPaymentRequestException $e) {
         switch ($e->getCode()) {
             case HspPaymentRequestException::INVALID_ROW_COUNT:
                 $msg = 'SAVE_FAILURE';
                 break;
             case HspPaymentRequestException::HSP_TERMINATED:
                 $msg = 'SAVE_TERMINATED_FAILURE';
                 break;
             case HspPaymentRequestException::HSP_NOT_ENOUGH_BALANCE_REMAINING:
                 $msg = 'SAVE_LOWBALANCE_FAILURE';
                 break;
             case HspPaymentRequestException::EXCEED_LIMIT:
                 $msg = 'SAVE_REQUEST_LIMIT_EXCEED_FAILURE';
                 break;
             case HspPaymentRequestException::INVALID_YEAR:
                 $msg = 'SAVE_REQUEST_INVALID_YEAR_FAILURE';
                 break;
             case HspPaymentRequestException::INVALID_DATE:
                 $msg = 'SAVE_REQUEST_INVALID_DATE_FAILURE';
                 break;
             case HspPaymentRequestException::NO_HSP:
                 $msg = 'SAVE_REQUEST_NO_HSP_SUMMARY_DEFINED_FAILURE';
                 break;
             case HspPaymentRequestException::INVALID_DATE_PREVIOUS_YEAR:
                 $msg = 'SAVE_REQUEST_INVALID_DATE_PREVIOUS_YEAR_FAILURE';
                 break;
             default:
                 $msg = 'UNKNOWN_ERROR_FAILURE';
                 break;
         }
     }
     self::redirect($msg, '?benefitcode=Benefits&action=Hsp_Request_Add_View');
 }