Example #1
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'));
     }
 }
Example #2
0
 public function testGetHspAccruedLastUpdated()
 {
     // Testing normal usage.
     $this->assertTrue(mysql_query("UPDATE `hs_hr_config` SET `value` = '2008-02-25' WHERE `key` = 'hsp_accrued_last_updated'"));
     $this->assertNotNull(Config::getHspAccruedLastUpdated());
     $this->assertEquals(Config::getHspAccruedLastUpdated(), "2008-02-25");
 }