Example #1
0
 /**
  * This functions brings forward last year balance for HSA and HRA
  */
 private static function _broughtForwardHspBalance()
 {
     $yearStart = date('Y') . "-01-01";
     $currentDate = date('Y-m-d');
     if ($currentDate >= $yearStart && self::recordsExist(date('Y') - 1) && !Config::getHspBroughtForwadYear("HspBroughtForward" . date('Y'))) {
         $selectTable = "`" . parent::DB_TABLE_HSP_SUMMARY . "`";
         $selectFields[0] = "`" . parent::DB_FIELD_EMPLOYEE_ID . "`";
         $selectFields[1] = "`" . parent::DB_FIELD_HSP_PLAN_ID . "`";
         $selectFields[2] = "`" . parent::DB_FIELD_TOTAL_ACCRUED . "`";
         $selectFields[3] = "`" . parent::DB_FIELD_TOTAL_USED . "`";
         $year = date('Y') - 1;
         $selectConditions[0] = "`" . parent::DB_FIELD_HSP_PLAN_YEAR . "` = '{$year}'";
         $selectConditions[1] = "`" . parent::DB_FIELD_HSP_PLAN_ID . "` != '3'";
         $sqlBuilder = new SQLQBuilder();
         $query = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions);
         $dbConnection = new DMLFunctions();
         $result = $dbConnection->executeQuery($query);
         if ($dbConnection->dbObject->numberOfRows($result) > 0) {
             while ($row = $dbConnection->dbObject->getArray($result)) {
                 $updateTable = "`" . self::DB_TABLE_HSP_SUMMARY . "`";
                 $updateFields[0] = "`" . parent::DB_FIELD_TOTAL_ACCRUED . "`";
                 $updateValues[0] = "`" . parent::DB_FIELD_TOTAL_ACCRUED . "`" + ($row[2] - $row[3]);
                 $updateConditions[0] = "`" . parent::DB_FIELD_EMPLOYEE_ID . "` = '" . $row[0] . "'";
                 $updateConditions[1] = "`" . parent::DB_FIELD_HSP_PLAN_ID . "` = '" . $row[1] . "'";
                 $updateConditions[2] = "`" . parent::DB_FIELD_HSP_PLAN_YEAR . "` = '" . date('Y') . "'";
                 $sqlBuilder2 = new SQLQBuilder();
                 $query2 = $sqlBuilder2->simpleUpdate($updateTable, $updateFields, $updateValues, $updateConditions);
                 $dbConnection2 = new DMLFunctions();
                 $dbConnection2->executeQuery($query2);
             }
         }
         Config::setHspBroughtForwadYear("set", "HspBroughtForward" . date('Y'));
     }
 }