Example #1
0
 public function testSetLeaveBroughtForward()
 {
     Config::setLeaveBroughtForward(date('Y'));
     $result = mysql_query("SELECT `key`, `value` FROM `hs_hr_config` WHERE `key` = 'LeaveBroughtForward" . date('Y') . "'");
     $row = mysql_fetch_array($result);
     $this->assertEquals("LeaveBroughtForward" . date('Y'), $row['key'], "Key is incorrect");
     $this->assertEquals("set", $row['value'], "Value is incorrect");
     // Setting LeaveBroughtForward should not be allowed more than once
     try {
         Config::setLeaveBroughtForward(date('Y'));
         $this->fail("Setting LeaveBroughtForward is allowed more than once");
     } catch (Exception $e) {
     }
 }
Example #2
0
 /**
  * Copy leave_brought_forward from last year to this year
  * check $toYear = date('Y'), $currentDate >= date('Y')."-01-01", fromYear = toYear - 1
  *
  */
 public function copyLeaveBroughtForward($fromYear, $toYear)
 {
     $currentDate = strtotime(date('Y-m-d'));
     $CurrentJanuaryFirst = date('Y-m-d', strtotime(date('Y') . "-01-01"));
     if (date('Y') > $toYear) {
         throw new LeaveQuotaException("Leave can only be brought forward to years upto current year", LeaveQuotaException::CANNOT_CARRY_LEAVE_FORWARD_YEAR_IN_THE_FUTURE);
     } else {
         if ($fromYear !== $toYear - 1) {
             throw new LeaveQuotaException("Leave can only be carried forward from the immediately preceeding year", LeaveQuotaException::CANNOT_CARRY_LEAVE_FORWARD_NON_CONSECUTIVE_YEARS);
         } else {
             if ($currentDate < $CurrentJanuaryFirst) {
                 throw new LeaveQuotaException("Can not copy Leave Brought Forward until the year ends!", LeaveQuotaException::CANNOT_CARRY_LEAVE_FORWARD_YEAR_NOT_OVER);
             } else {
                 $sqlBuilder = new SQLQBuilder();
                 $selectTable = "`" . self::LEAVEQUOTA_DB_TABLE_EMPLOYEE_LEAVE_QUOTA . "`";
                 $selectFields[0] = "`" . self::LEAVEQUOTA_DB_FIELD_YEAR . "`";
                 $selectFields[1] = "`" . self::LEAVEQUOTA_DB_FIELD_LEAVE_TYPE_ID . "`";
                 $selectFields[2] = "`" . self::LEAVEQUOTA_DB_FIELD_EMPLOYEE_ID . "`";
                 $selectFields[3] = "`" . self::LEAVEQUOTA_DB_FIELD_NO_OF_DAYS_ALLOTED . "`";
                 $selectFields[4] = "`" . self::LEAVEQUOTA_DB_FIELD_LEAVE_TAKEN . "`";
                 $selectConditions[0] = "`" . self::LEAVEQUOTA_DB_FIELD_YEAR . "` = '{$fromYear}'";
                 $selectQuery = $sqlBuilder->simpleSelect($selectTable, $selectFields, $selectConditions);
                 $dbConnection = new DMLFunctions();
                 $result = $dbConnection->executeQuery($selectQuery);
                 if ($dbConnection->dbObject->numberOfRows($result) > 0) {
                     while ($row = $dbConnection->dbObject->getArray($result)) {
                         $updateTable = "`" . self::LEAVEQUOTA_DB_TABLE_EMPLOYEE_LEAVE_QUOTA . "`";
                         $updateFields[0] = "`" . self::LEAVEQUOTA_DB_FIELD_LEAVE_BROUGHT_FORWARD . "`";
                         $broughtForward = $row[self::LEAVEQUOTA_DB_FIELD_NO_OF_DAYS_ALLOTED] - $row[self::LEAVEQUOTA_DB_FIELD_LEAVE_TAKEN];
                         $updateValues[0] = "'" . $broughtForward . "'";
                         $updateConditions[0] = "`" . self::LEAVEQUOTA_DB_FIELD_YEAR . "` = '{$toYear}'";
                         $updateConditions[1] = "`" . self::LEAVEQUOTA_DB_FIELD_LEAVE_TYPE_ID . "` = '" . $row[self::LEAVEQUOTA_DB_FIELD_LEAVE_TYPE_ID] . "'";
                         $updateConditions[2] = "`" . self::LEAVEQUOTA_DB_FIELD_EMPLOYEE_ID . "` = '" . $row[self::LEAVEQUOTA_DB_FIELD_EMPLOYEE_ID] . "'";
                         $updateQuery = $sqlBuilder->simpleUpdate($updateTable, $updateFields, $updateValues, $updateConditions);
                         $dbConnection->executeQuery($updateQuery);
                     }
                     Config::setLeaveBroughtForward(date('Y'));
                     return true;
                 } else {
                     throw new LeaveQuotaException("No record to update", LeaveQuotaException::NOTHING_TO_UPDATE);
                 }
             }
         }
     }
 }