function addData($postArr, $index, $object)
 {
     switch ($index) {
         case 'EMP':
             $empinfo = new EmpInfo();
             $empinfo = $object['EmpInfo'];
             $res = $empinfo->addEmpMain();
             /* Get padded empID since most classes expect the empId to
              * be left padded with zeros.
              */
             $id = $empinfo->getPaddedEmpId();
             if (isset($object['EmpPhoto']) && $res) {
                 $empphoto = $object['EmpPhoto'];
                 $empphoto->setEmpId($empinfo->getEmpId());
                 $empphoto->addEmpPic();
             }
             break;
     }
     if ($res) {
         // For adding a new record to `hs_hr_hsp_summary` table.
         if (HspSummary::recordsExist(date('Y'))) {
             HspSummary::saveInitialSummaryForOneEmployee($empinfo->getEmpId());
         }
         $showMsg = "Addition%Successful!";
         //If $message is 1 setting up the
         $reqcode = $index;
         header("Location: ./CentralController.php?reqcode=EMP&id={$id}&capturemode=updatemode");
     } else {
         $errCode = mysql_errno();
         switch ($errCode) {
             case 1062:
                 $showMsg = "DUPLICATE_EMPCODE_FAILURE";
                 break;
             default:
                 $showMsg = "ADD_FAILURE";
                 break;
         }
         $reqcode = $index;
         header("Location: ./CentralController.php?message={$showMsg}&capturemode=addmode&reqcode={$reqcode}");
         //if Adding Data to DB not succeed set msg with showMsg
     }
 }
Exemple #2
0
 public function testGetYearsAndPlans()
 {
     /* DB values are as follows
      * hsp_plan_id	hsp_plan_year
      * 1			date('Y')
      * 3			date('Y')
      * 1			date('Y')+1
      * 3			date('Y')+1
      */
     /* Expected array should be as follows
      * $both[0]['year'] = date('Y');
      * $both[0]['plan'][0] = 1;
      * $both[0]['plan'][1] = 3;
      * $both[1]['year'] = date('Y')+1;
      * $both[1]['plan'][0] = 1;
      * $both[1]['plan'][1] = 3;
      */
     $both = HspSummary::getYearsAndPlans();
     $this->assertEquals(date('Y'), $both[0]['year']);
     $this->assertEquals(date('Y') + 1, $both[1]['year']);
     $this->assertEquals(1, $both[0]['plan'][0]);
     $this->assertEquals(3, $both[0]['plan'][1]);
     $this->assertEquals(1, $both[1]['plan'][0]);
     $this->assertEquals(3, $both[1]['plan'][1]);
 }
 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}");
 }
 public static function parseHspSaveData($postArr)
 {
     for ($i = 0; $i < count($postArr['hidSummaryId']); $i++) {
         $hspSummaryObj = new HspSummary();
         $hspSummaryObj->setSummaryId($postArr['hidSummaryId'][$i]);
         if (!empty($postArr['hidEmployeeId'][$i]) && is_numeric($postArr['hidEmployeeId'][$i])) {
             $hspSummaryObj->setEmployeeId($postArr['hidEmployeeId'][$i]);
         } else {
             $hspSummaryObj->setEmployeeId(null);
         }
         if (!empty($postArr['txtAnnualLimit'][$i]) && is_numeric($postArr['txtAnnualLimit'][$i])) {
             $hspSummaryObj->setAnnualLimit($postArr['txtAnnualLimit'][$i]);
         } else {
             $hspSummaryObj->setAnnualLimit(0);
         }
         if (!empty($postArr['txtEmployerAmount'][$i]) && is_numeric($postArr['txtEmployerAmount'][$i])) {
             $hspSummaryObj->setEmployerAmount($postArr['txtEmployerAmount'][$i]);
         } else {
             $hspSummaryObj->setEmployerAmount(0);
         }
         if (!empty($postArr['txtEmployeeAmount'][$i]) && is_numeric($postArr['txtEmployeeAmount'][$i])) {
             $hspSummaryObj->setEmployeeAmount($postArr['txtEmployeeAmount'][$i]);
         } else {
             $hspSummaryObj->setEmployeeAmount(0);
         }
         if (!empty($postArr['txtTotalAccrued'][$i]) && is_numeric($postArr['txtTotalAccrued'][$i])) {
             $hspSummaryObj->setTotalAccrued($postArr['txtTotalAccrued'][$i]);
         } else {
             $hspSummaryObj->setTotalAccrued(0);
         }
         if (!empty($postArr['txtTotalUsed'][$i]) && is_numeric($postArr['txtTotalUsed'][$i])) {
             $hspSummaryObj->setTotalUsed($postArr['txtTotalUsed'][$i]);
         } else {
             $hspSummaryObj->setTotalUsed(0);
         }
         $summaryObjArr[] = $hspSummaryObj;
     }
     return $summaryObjArr;
 }