Example #1
0
 /**
  * For a give year, this function updates 'total_used' for all employees
  * based on current HSP Scheme and 'hsp_used_last_updated'
  */
 public static function updateUsed($year)
 {
     if (Config::getHspUsedLastUpdated() < date('Y-m-d')) {
         $selectTable = "`" . self::DB_TABLE_HSP_SUMMARY . "`";
         $selectFields[0] = "`" . self::DB_FIELD_SUMMARY_ID . "`";
         $selectFields[1] = "`" . self::DB_FIELD_EMPLOYEE_ID . "`";
         $selectFields[2] = "`" . self::DB_FIELD_HSP_PLAN_ID . "`";
         $selectFields[3] = "`" . self::DB_FIELD_TOTAL_USED . "`";
         $selectConditions[0] = "`" . self::DB_FIELD_HSP_PLAN_YEAR . "` = '" . $year . "'";
         $selectConditions[1] = self::_twoHspPlansCondition(Config::getHspCurrentPlan());
         $sqlBuilder = new SQLQBuilder();
         $query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions);
         $dbConnection = new DMLFunctions();
         $result = $dbConnection->executeQuery($query);
         $rowCount = $dbConnection->dbObject->numberOfRows($result);
         $hspUsedLastUpdated = Config::getHspUsedLastUpdated();
         for ($i = 0; $i < $rowCount; $i++) {
             $row = $dbConnection->dbObject->getArray($result);
             $updatedArray[$i][0] = $row[0];
             $updatedArray[$i][1] = $row[3] + HspPaymentRequest::calculateNewHspUsed($row[1], $row[2], $hspUsedLastUpdated);
         }
         for ($i = 0; $i < count($updatedArray); $i++) {
             $updateTable = "`" . self::DB_TABLE_HSP_SUMMARY . "`";
             $updateFields[0] = "`" . self::DB_FIELD_TOTAL_USED . "`";
             $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::setHspUsedLastUpdated(date('Y-m-d'));
     }
 }
Example #2
0
 public function testSetHspUsedLastUpdated()
 {
     // Testing for invalid date formats.
     try {
         Config::setHspUsedLastUpdated("dsereregg");
         $this->fail("Invalid dates are allowed");
     } catch (Exception $e) {
     }
     // Testing without giving a key, 'key' value already exists.
     Config::setHspUsedLastUpdated("2008-03-18");
     $result = mysql_query("SELECT `value` FROM `hs_hr_config` WHERE `key`='hsp_used_last_updated'");
     $resultArray = mysql_fetch_array($result);
     $this->assertEquals($resultArray[0], "2008-03-18");
     // Testing by giving a key, 'key' value already exists.
     Config::setHspUsedLastUpdated("2008-03-27", "hsp_used_last_updated");
     $result = mysql_query("SELECT `value` FROM `hs_hr_config` WHERE `key`='hsp_used_last_updated'");
     $resultArray = mysql_fetch_array($result);
     $this->assertEquals($resultArray[0], "2008-03-27");
     // Testing by giving a key, 'key' doesn't exist.
     Config::setHspUsedLastUpdated("1000-01-01", "this_should_not_exist");
     $result = mysql_query("SELECT `value` FROM `hs_hr_config` WHERE `key`='this_should_not_exist'");
     $resultArray = mysql_fetch_array($result);
     $this->assertEquals($resultArray[0], "1000-01-01");
     $this->assertTrue(mysql_query("DELETE FROM `hs_hr_config` WHERE `key`='this_should_not_exist'"));
 }