/** * 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')); } }
public function testCountCheckDates() { $this->assertTrue(mysql_query("TRUNCATE TABLE `hs_hr_pay_period`")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(1, '2007-12-01', '2007-12-31', '2007-12-31', '2007-12-25', '2007-12-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(2, '2008-01-01', '2008-01-31', '2008-01-31', '2008-01-25', '2008-01-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(3, '2008-02-01', '2008-02-29', '2008-02-29', '2008-02-25', '2008-02-20')")); $this->assertTrue(mysql_query("INSERT INTO hs_hr_pay_period VALUES(4, '2008-03-01', '2008-03-31', '2008-03-31', '2008-03-25', '2008-03-20')")); $this->assertEquals(HspPayPeriod::countCheckDates("2008-01-01", "2008-04-01"), 3); $this->assertEquals(HspPayPeriod::countCheckDates("2007-12-01", "2008-04-01"), 3); $this->assertEquals(HspPayPeriod::countCheckDates("2005-12-01", "2008-04-01"), 3); $this->assertEquals(HspPayPeriod::countCheckDates("2008-01-25", "2008-03-31"), 2); $this->assertEquals(HspPayPeriod::countCheckDates("2008-03-31", "2008-05-31"), 0); }