Beispiel #1
0
 /**
  * This function get a database resource as the input and creates a HSP objects array
  * containing the data of the resource.
  */
 private static function _buildSummaryObjects($result)
 {
     $dbConnection = new DMLFunctions();
     $hspObjArr = null;
     while ($row = $dbConnection->dbObject->getArray($result)) {
         $hspObj = new Hsp();
         $empName = EmpInfo::getFullName($row[1]);
         if (isset($empName)) {
             // For excluding deleted employees
             $hspObj->setSummaryId($row[0]);
             $hspObj->setEmployeeId($row[1]);
             $hspObj->setHspPlanId($row[2]);
             $hspObj->setHspPlanName(DefineHsp::getHspPlanName($row[2]));
             $hspObj->setEmployeeName($empName);
             $hspObj->setHspPlanYear($row[3]);
             $hspObj->setHspPlanStatus($row[4]);
             $hspObj->setAnnualLimit($row[5]);
             $hspObj->setEmployerAmount($row[6]);
             $hspObj->setEmployeeAmount($row[7]);
             $hspObj->setTotalAccrued($row[8]);
             $hspObj->setTotalUsed($row[9]);
             $currentHspPlan = Config::getHspCurrentPlan();
             if ($currentHspPlan == 3 || $currentHspPlan == 4 || $currentHspPlan == 5) {
                 // If FSA is avaialbe in current plan
                 if ($row[2] == 3) {
                     $hspObj->setFsaBalance(self::_fetchLastYearFsaBalance($row[1], $row[3] - 1));
                 } else {
                     $hspObj->setFsaBalance("NA");
                 }
             }
             $hspObjArr[] = $hspObj;
         }
     }
     return $hspObjArr;
 }
Beispiel #2
0
 /**
  * This function updates 'total_accrued' field in 'hs_hr_hsp_summary'.
  * It first calls 'hsp_accrued_last_updated' field from 'hs_hr_config' table.
  * If updated date is older than current day, it checks for new 'check_date's from
  * 'hs_hr_pay_period' table. If new check dates of current year are available, it checks current
  * HSP scheme and updates 'total_accrued' only for that scheme.
  */
 public static function updateAccrued($year)
 {
     if (Config::getHspAccruedLastUpdated() < date('Y-m-d')) {
         $checkDates = HspPayPeriod::countCheckDates(Config::getHspAccruedLastUpdated(), date('Y-m-d'));
         if ($checkDates > 0) {
             $selectTable = "`" . self::DB_TABLE_HSP_SUMMARY . "`";
             $selectFields[0] = "`" . self::DB_FIELD_SUMMARY_ID . "`";
             $selectFields[1] = "`" . self::DB_FIELD_HSP_PLAN_STATUS . "`";
             $selectFields[2] = "`" . self::DB_FIELD_EMPLOYER_AMOUNT . "`";
             $selectFields[3] = "`" . self::DB_FIELD_EMPLOYEE_AMOUNT . "`";
             $selectFields[4] = "`" . self::DB_FIELD_TOTAL_ACCRUED . "`";
             $selectFields[5] = "`" . self::DB_FIELD_EMPLOYEE_ID . "`";
             $selectConditions[0] = self::_twoHspPlansCondition(Config::getHspCurrentPlan());
             $selectConditions[1] = "`" . self::DB_FIELD_HSP_PLAN_YEAR . "`= '" . $year . "'";
             $sqlBuilder = new SQLQBuilder();
             $query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions);
             $dbConnection = new DMLFunctions();
             $result = $dbConnection->executeQuery($query);
             $rowCount = $dbConnection->dbObject->numberOfRows($result);
             for ($i = 0; $i < $rowCount; $i++) {
                 $row = $dbConnection->dbObject->getArray($result);
                 if (!Hsp::_isEmployeeTerminated($row[5])) {
                     if ($row[1] == Hsp::HSP_STATUS_ACTIVE || $row[1] == Hsp::HSP_STATUS_PENDING_HALT) {
                         $updatedArray[$i][0] = $row[0];
                         $updatedArray[$i][1] = $row[4] + $checkDates * ($row[2] + $row[3]);
                     } else {
                         $updatedArray[$i][0] = $row[0];
                         $updatedArray[$i][1] = $row[4];
                     }
                 } else {
                     $updatedArray[$i][0] = $row[0];
                     $updatedArray[$i][1] = $row[4];
                 }
             }
             for ($i = 0; $i < count($updatedArray); $i++) {
                 $updateTable = "`" . self::DB_TABLE_HSP_SUMMARY . "`";
                 $updateFields[0] = "`" . self::DB_FIELD_TOTAL_ACCRUED . "`";
                 $updateValues[0] = "'" . $updatedArray[$i][1] . "'";
                 $updateConditions[0] = "`" . self::DB_FIELD_SUMMARY_ID . "` = '" . $updatedArray[$i][0] . "'";
                 $query = $sqlBuilder->simpleUpdate($updateTable, $updateFields, $updateValues, $updateConditions);
                 $dbConnection->executeQuery($query);
             }
         }
         Config::setHspAccruedLastUpdated(date('Y-m-d'));
     }
 }
Beispiel #3
0
 public static function parseSaveData($postArr)
 {
     $hspArr = array();
     for ($i = 0; $i < count($postArr['txtHspId']); $i++) {
         $tmpHsp = new Hsp();
         if (!empty($postArr['txtHspId'][$i])) {
             $tmpHsp->setId($postArr['txtHspId'][$i]);
         }
         $tmpHsp->setEmployeeId($postArr['txtEmployeeId'][$i]);
         $tmpHsp->setHspValue($postArr['txtHspValue'][$i]);
         $tmpHsp->setEditedStatus($postArr['editedStatus'][$i]);
         if (isset($postArr['txtAmountPerDay'][$i])) {
             if ($postArr['txtAmountPerDay'][$i] != $postArr['initialAmountPerDay'][$i]) {
                 $tmpHsp->setEditedStatus(1);
             }
             $tmpHsp->setAmountPerDay($postArr['txtAmountPerDay'][$i]);
         }
         $editedStatus = $tmpHsp->getEditedStatus();
         if (isset($postArr['payDays'][$i]) && $editedStatus == 0) {
             $amountPerDay = ($postArr['txtHspValue'][$i] - $postArr['txtTotalAcrued'][$i]) / $postArr['payDays'][$i];
             $tmpHsp->setAmountPerDay($amountPerDay);
         } else {
             if (isset($postArr['txtAmountPerDay'][$i])) {
                 $tmpHsp->setAmountPerDay($postArr['txtAmountPerDay'][$i]);
             }
         }
         $tmpHsp->setTotalAcrued($postArr['txtTotalAcrued'][$i]);
         $hspArr[] = $tmpHsp;
     }
     return $hspArr;
 }
Beispiel #4
0
 public static function payHspRequest($hspReqest)
 {
     try {
         // Check if sensitive data is changed by admin and write to log
         try {
             $log = Logger::getInstance();
             $exsistingRequest = $hspReqest->getHspRequest($hspReqest->getId());
             $mssg = $exsistingRequest->isDataChangedByAdmin($hspReqest);
             if ($mssg != false) {
                 $log->info($mssg);
             }
         } catch (Exception $e) {
         }
         $hspReqestTemp = $hspReqest->getHspRequest($hspReqest->getId());
         $hspSummary = new HspSummary();
         $empId = $hspReqestTemp->getEmployeeId();
         $year = date('Y', strtotime($hspReqestTemp->getDateIncurred()));
         $hspReqestTemp->setDatePaid($hspReqest->getDatePaid());
         $hspRecordArr = array();
         $amount = $hspReqest->getExpenseAmount();
         $hspId = $hspReqestTemp->getHspId();
         switch ($hspId) {
             case 1:
                 $personalHspSummary = HspSummary::fetchHspSummary($year, 1, $empId);
                 $amountLimit = $personalHspSummary[0]->getTotalAccrued() - $personalHspSummary[0]->getTotalUsed();
                 break;
             case 2:
                 $personalHspSummary = HspSummary::fetchHspSummary($year, 1, $empId);
                 if (count($personalHspSummary) == 2) {
                     $index = $personalHspSummary[0]->getHspPlanName() == 'HRA' ? 0 : 1;
                 } else {
                     $index = 0;
                 }
                 $amountLimit = $personalHspSummary[$index]->getTotalAccrued() - $personalHspSummary[$index]->getTotalUsed();
                 break;
             case 3:
                 $personalHspSummary = HspSummary::fetchHspSummary($year, 1, $empId);
                 $index = count($personalHspSummary) == 2 ? 1 : 0;
                 $amountLimit = $personalHspSummary[$index]->getAnnualLimit() - $personalHspSummary[$index]->getTotalUsed();
                 break;
         }
         if ($amount > $amountLimit) {
             throw new HspPaymentRequestException('Request amount cannot exceed the annual limit', HspPaymentRequestException::EXCEED_LIMIT);
         }
         $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();
         //$log->debug("BC before ter :" . $terminated);
         //$log->debug("BC before hsp :" . $hspValue);
         //$log->debug("BC before total :" . $totalUsed);
         $msg = 'SAVE_SUCCESS';
         $hspReqest->payHspRequest();
         // For updating Total Used in HSP Summary
         Hsp::updateUsedPerPayment($year, $hspReqestTemp->getHspId(), $empId, $hspReqest->getExpenseAmount());
         $hspMailNotification = new HspMailNotification();
         $hspMailNotification->sendHspPaymentAcceptNotification($hspReqestTemp, $link);
     } catch (HspPaymentRequestException $e) {
         switch ($e->getCode()) {
             case HspPaymentRequestException::INVALID_ROW_COUNT:
                 $msg = 'SAVE_FAILURE';
                 break;
             case HspPaymentRequestException::EXCEED_LIMIT:
                 $msg = 'SAVE_REQUEST_LIMIT_EXCEED_FAILURE';
                 break;
             default:
                 $msg = 'UNKNOWN_ERROR_FAILURE';
                 break;
         }
     }
     $_SESSION['paid'] = "Yes";
     $id = $_GET['id'];
     self::redirect($msg, "?benefitcode=Benefits&action=View_Hsp_Request&id={$id}");
 }
Beispiel #5
0
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 *
 */
ob_start();
session_start();
if (!defined('ROOT_PATH')) {
    define('ROOT_PATH', $_SESSION['path']);
}
require_once ROOT_PATH . '/lib/models/benefits/Hsp.php';
require_once ROOT_PATH . '/lib/models/benefits/mail/HspMailNotification.php';
try {
    $hspSummaryId = $_GET['hspSummaryId'];
    $newHspStatus = $_GET['newHspStatus'];
    $empId = $_GET['empId'];
    $hsp = new Hsp();
    $hsp->setEmployeeId($empId);
    $hsp->setSummaryId($hspSummaryId);
    $hsp->setHspPlanStatus($newHspStatus);
    $hspMailNotification = new HspMailNotification();
    if (Hsp::updateStatus($hspSummaryId, $newHspStatus)) {
        switch ($newHspStatus) {
            case Hsp::HSP_STATUS_HALTED:
                $hspMailNotification->sendHspPlanHaltedByHRAdminNotification($hsp);
                break;
            case Hsp::HSP_STATUS_ACTIVE:
                break;
            case Hsp::HSP_STATUS_ESS_HALTED:
                $hspMailNotification->sendHspPlanHaltedByHRAdminOnRequestNotification($hsp);
                break;
            case Hsp::HSP_STATUS_PENDING_HALT:
Beispiel #6
0
 private function _getHsp()
 {
     if ($this->hspId != null) {
         return;
     }
     $hsp = new Hsp();
     $hsp->setEmployeeId($this->getEmployeeId());
     $hsp->setAllotmentId($this->getAllotmentId());
     $hspArr = $hsp->fetchHsps();
     if (is_array($hspArr) && isset($hspArr[0])) {
         $this->hspId = $hspArr[0]->getId();
     } else {
         throw new HspPaymentRequestException("No hsp", HspPaymentRequestException::NO_HSP);
     }
 }
Beispiel #7
0
 public function testUpdateStatus()
 {
     $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"), mysql_error());
     $this->assertNotNull(mysql_query("INSERT INTO `hs_hr_employee` VALUES (1, '001', 'Arnold', 'Subasinghe', '', 'Arnold', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', 'AF', '', '', '', '', '', '', NULL, NULL, '')"));
     $this->assertNotNull(mysql_query("INSERT INTO `hs_hr_employee` VALUES (2, '002', 'Kalum', 'Kumara', '', 'Kal', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', 'AF', '', '', '', '', '', '', NULL, NULL, '')"));
     // For employee1
     $this->assertTrue(mysql_query("INSERT INTO hs_hr_hsp_summary VALUES(1, 1, 1, '" . date('Y') . "', 1, 1500, 50, 50, 0, 22)"), mysql_error());
     $this->assertTrue(mysql_query("INSERT INTO hs_hr_hsp_summary VALUES(2, 2, 1, '" . date('Y') . "', 1, 2500, 75, 75, 0, 0)"), mysql_error());
     $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '" . (date('Y') - 1) . "-12-31' WHERE `key` = 'hsp_Used_last_updated'"));
     Hsp::updateStatus(1, 0);
     $result = mysql_query("SELECT `hsp_plan_status` FROM `hs_hr_hsp_summary` WHERE `summary_id` = 1");
     $resultArray = mysql_fetch_array($result);
     $this->assertEquals($resultArray[0], 0);
     // should be 0 (Halted)
     Hsp::updateStatus(1, 1);
     $result = mysql_query("SELECT `hsp_plan_status` FROM `hs_hr_hsp_summary` WHERE `summary_id` = 1");
     $resultArray = mysql_fetch_array($result);
     $this->assertEquals($resultArray[0], 1);
     // should be 1 (Active)
 }