Esempio n. 1
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}");
 }
Esempio n. 2
0
 public function testFetchSummary()
 {
     $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_hsp_summary`"), mysql_error());
     // Add 3 records to `hs_hr_hsp_summary`
     $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (1, 1, 1, " . date('Y') . ", 0, 1200.00, 0.00, 0.00, 0.00, 0.00)"), mysql_error());
     $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (2, 2, 1, " . date('Y') . ", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"), mysql_error());
     $this->assertTrue(mysql_query("INSERT INTO `hs_hr_hsp_summary` VALUES (3, 3, 1, " . date('Y') . ", 0, 0.00, 0.00, 0.00, 0.00, 0.00)"), mysql_error());
     //Add 3 employees to `hs_hr_employee`
     $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ({$this->employeeFields}) VALUES (1, '001', 'Bauer', 'Jack', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"), mysql_error());
     $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ({$this->employeeFields}) VALUES (2, '002', 'Bond', 'James', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"), mysql_error());
     $this->assertTrue(mysql_query("INSERT INTO `hs_hr_employee` ({$this->employeeFields}) VALUES (3, '003', 'Owen', 'David', '', '', 0, NULL, NULL, NULL, NULL, NULL, '', '', '', '', NULL, '', NULL, NULL, NULL, NULL, '', '', '', '', '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)"), mysql_error());
     $hspSummary = new HspSummary();
     $summary = $hspSummary->fetchHspSummary(date('Y'), 1);
     $this->assertTrue(is_array($summary));
     $this->assertTrue(is_object($summary[0]));
     $this->assertEquals(count($summary), 3);
     $this->assertEquals($summary[0]->getAnnualLimit(), 1200);
 }