コード例 #1
0
 public static function viewHspSummary($year, $employeeId = null, $saveSuccess = null)
 {
     $authorizeObj = new authorize($_SESSION['empID'], $_SESSION['isAdmin']);
     if (!$authorizeObj->isAdmin()) {
         // Check whether the Admin
         if ($employeeId != $_SESSION['empID']) {
             //$error['notAdmin'] = "You are not authorised";
             self::searchHspSummary($_SESSION['empID'], $year);
             exit(0);
         }
     }
     if (Config::getHspCurrentPlan() == 0) {
         // Check whether the HSP plan has been defined
         $error['hspPlanNotDefined'] = true;
     }
     if ($employeeId == "leftNull") {
         $error['nonExistedEmployeeSearch'] = true;
     }
     if (isset($error)) {
         // If errors found
         $path = "/templates/benefits/hspSummary.php";
         $template = new TemplateMerger($error, $path);
         $template->setError(true);
         $template->display();
     } else {
         // If no errors found, fetching summary is tried.
         try {
             // Saving initial summary. Exception is thrown if `hs_hr_employee` table is empty
             switch (Config::getHspCurrentPlan()) {
                 case 1:
                     self::_saveInitialRecords($year, 1);
                     break;
                 case 2:
                     self::_saveInitialRecords($year, 2);
                     break;
                 case 3:
                     self::_saveInitialRecords($year, 3);
                     break;
                 case 4:
                     self::_saveInitialRecords($year, 1);
                     self::_saveInitialRecords($year, 3);
                     break;
                 case 5:
                     self::_saveInitialRecords($year, 2);
                     self::_saveInitialRecords($year, 3);
                     break;
                 case 6:
                     self::_saveInitialRecords($year, 1);
                     self::_saveInitialRecords($year, 2);
                     break;
             }
             // Setting the Page No
             if (isset($_POST['pageNo'])) {
                 $pageNo = $_POST['pageNo'];
             } else {
                 $pageNo = 1;
             }
             // Setting records that are used in /templates/benefits/hspSummary.php
             $tmpOb[0] = "hspSummary";
             $tmpOb[1] = HspSummary::fetchHspSummary($year, $pageNo);
             $tmpOb[2] = $year;
             $tmpOb[3] = $pageNo;
             $tmpOb[4] = HspSummary::recordsCount($year, Config::getHspCurrentPlan());
             if (isset($saveSuccess)) {
                 $tmpOb[5] = $saveSuccess;
             } else {
                 $tmpOb[5] = null;
             }
             $tmpOb[6] = EmpInfo::getEmployeeMainDetails();
             $tmpOb[7] = HspSummary::getYears();
         } catch (Exception $e) {
             $error['noEmployeeRecords'] = true;
         }
         // Setting template paths
         if (isset($_GET['printPdf']) && $_GET['printPdf'] == 1) {
             $tmpOb[1] = HspSummary::fetchHspSummary($year, -1);
             if ($_GET['pdfName'] == "All-Employees-HSP-Summary") {
                 $path = "/plugins/printBenefits/pdfHspSummary.php";
             } elseif ($_GET['pdfName'] == "Personal-HSP-Summary") {
                 if (!isset($employeeId)) {
                     $empId = $_GET['empId'];
                 }
                 $tmpOb[1] = HspSummary::fetchPersonalHspSummary($year, $empId);
                 $path = "/plugins/printBenefits/pdfPersonalHspSummary.php";
             }
         } else {
             $path = "/templates/benefits/hspSummary.php";
         }
         if (isset($employeeId) && !isset($_GET['printPdf'])) {
             $path = "/templates/benefits/personalHspSummary.php";
         }
         if (isset($_GET['printPdf']) && $_GET['printPdf'] == 1) {
             $template = new TemplateMerger($tmpOb, $path, 'pdfHeader.php', 'pdfFooter.php');
         } else {
             if (isset($error)) {
                 $template = new TemplateMerger($error, $path);
                 $template->setError(true);
             } else {
                 $template = new TemplateMerger($tmpOb, $path);
             }
         }
         $template->display();
     }
     // If no errors found, fetching summary is tried. Code ends.
 }
コード例 #2
0
ファイル: HspSummaryTest.php プロジェクト: noikiy/owaspbwa
 public function testFetchPersonalSummary()
 {
     $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->fetchPersonalHspSummary(date('Y'), 1);
     $this->assertTrue(is_array($summary));
     $this->assertTrue(is_object($summary[0]));
     $this->assertEquals(count($summary), 1);
     $this->assertEquals($summary[0]->getAnnualLimit(), 1200);
     $summary = $hspSummary->fetchPersonalHspSummary(date('Y'), 5);
     $this->assertNull($summary);
 }