case 'Hsp_Expenditures': BenefitsController::listHspExpenditures($_GET['year'], $_GET['employeeId']); break; case 'Hsp_Used_Select_Year': BenefitsController::selectYearAndEmployee('Used_Select_Year'); break; case 'Hsp_Used': BenefitsController::listHspUsed($_GET['year'], $_GET['employeeId']); break; case 'View_Hsp_Request': BenefitsController::viewHspRequestView($_GET['id']); break; case 'View_Hsp_Request': BenefitsController::viewHspRequestView($_GET['id']); break; case 'Terminate_Hsp_Plan': BenefitsController::terminateEmployment($_GET['id'], $_GET['year'], $_GET['enddate']); break; case 'print': BenefitsController::printHspSummary(); break; case 'Define_Health_Savings_Plans': BenefitsController::defineHsp(); break; case 'Save_Health_Savings_Plans': $saveHsp = EXTRACTOR_DefineHsp::parseSaveDataHsp($_POST['HspType']); BenefitsController::checkHspState($saveHsp); break; } break; }
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'); }