コード例 #1
0
 function getSystemDueDay()
 {
     $system_due_date = get_next_system_code($this->m_dbLink, CODES_PAYMENT_DUE);
     if (($tm = strtotime($system_due_date)) === -1) {
         $due_day = 20;
         // default is 20th of the month depending on payment mode
     } else {
         $due_day = date("d", $tm);
     }
     return $due_day;
 }
コード例 #2
0
ファイル: ebpls.ctc.class.php プロジェクト: laiello/ebpls
 /**
  * Creats a CTC entry, will automatically validate data set ( data is set using setData( key, value) method ).
  *
  */
 function create()
 {
     if ($this->m_dbLink) {
         mysql_query("LOCK TABLES", $this->m_dbLink);
         $this->computeTax();
         if (($error_num = $this->validateData()) > 0) {
             if ($this->m_ctcType == CTC_TYPE_INDIVIDUAL) {
                 $m_strLastCode = get_next_system_code($this->m_dbLink, CODES_CTC_IND_COL);
             } else {
                 $m_strLastCode = get_next_system_code($this->m_dbLink, CODES_CTC_BUS_COL);
             }
             $this->data_elems[CTC_CODE] = $m_strLastCode;
             $this->data_elems[CTC_DATE_ISSUED] = date("Y-m-d H:i:s");
             $this->data_elems[CTC_ACCT_CODE] = "CTC PAYMENT";
             $strValues = $this->data_elems;
             $ret = ebpls_insert_data($this->m_dbLink, $this->m_strTable, $strValues);
             if ($ret < 0) {
                 $this->debug("CREATE CTC FAILED [error:{$ret},msg=" . get_db_error() . "]");
                 $this->m_arrError["err_code"] = $ret;
                 $this->m_arrError["err_mesg"] = get_db_error();
             } else {
                 $this->debug("CREATE CTC SUCCESSFULL [{$m_strLastCode}]");
                 $this->data_elems[CTC_CODE] = $m_strLastCode;
                 if ($this->m_ctcType == CTC_TYPE_INDIVIDUAL) {
                     $ret_ctc_code = update_system_code($this->m_dbLink, CODES_CTC_IND_COL, $m_strLastCode);
                 } else {
                     $ret_ctc_code = update_system_code($this->m_dbLink, CODES_CTC_BUS_COL, $m_strLastCode);
                 }
             }
         } else {
             $this->debug("CREATE CTC FAILED DUE TO INVALID DATA INPUT");
             $ret = $error_num;
         }
         mysql_query("UNLOCK TABLES", $this->m_dbLink);
         return $ret;
     } else {
         $this->setError(-1, "CREATE CTC FAILED DUE TO INVALID DB LINK");
         $this->debug("CREATE CTC FAILED DUE TO INVALID DB LINK");
         return -1;
     }
 }
コード例 #3
0
 function addCashPayment($trans_obj, $amount, $admin, $bCommit)
 {
     // retrieve payment schedule list which are not yet fully paid
     $clsTPS = new EBPLSTransactionPaymentSchedule($this->m_dbLink, false);
     $tps_records = $clsTPS->listPaymentSchedule($trans_obj->getData(TRANS_ID), TPS_PAYMENT_STATE_UNPAID, TPS_PAYMENT_DUE_DATE, false);
     if (is_array($tps_records)) {
         // check first if payment exceeds the balance (code assumes that payment schedules are update!)
         $tmp_amount_due = $clsTPS->getTotalAmountDue($trans_obj->getData(TRANS_ID));
         if ($tmp_amount_due <= 0) {
             $this->setError(-2, "All tax/fee payables are paid.");
             return -3;
         }
         $this->debug("The current users balance is P" . number_format($tmp_amount_due, 2) . " < {$amount}!");
         if (round($tmp_amount_due, 2) < round($amount, 2)) {
             // return error if payment amount given exceeds balance
             $this->debug("The current users balance is P" . number_format($tmp_amount_due, 2) . ", please indicate specified amount as cash payment.");
             $this->setError(-2, "The current users balance is P" . number_format($tmp_amount_due, 2) . ", please indicate specified amount as cash payment.");
             return -2;
         }
         $tmp_amount = $amount;
         $tmp_tps_included_records = NULL;
         // ----- START TRANSACTION HERE -----
         $or_code = get_next_system_code($this->m_dbLink, CODES_OR_COL);
         $payment_code = get_next_system_code($this->m_dbLink, CODES_PAY_COL);
         $clsAccounts = new EBPLChartOfAccountsSysRef($this->m_dbLink, false);
         $cash_account_code = $clsAccounts->getCashAccountCode();
         if ($cash_account_code < 0) {
             $this->debug("Unable to load cash account code, return {$cash_account_code}!");
             $this->setError(-5, "Unable to load cash account code, return {$cash_account_code}!");
             // roll back
             return -5;
         }
         $this->debug("OR CODE:{$or_code}, CASH ACCT CODE:{$cash_account_code}, PAYMENT:{$amount}");
         unset($this->or_details);
         for ($i = 0; $i < count($tps_records); $i++) {
             // ---- LOAD TRANSACTION RECORD DATA
             $payment_id = $tps_records[$i]->getData(TPS_PAYMENT_ID);
             $fee_id = $tps_records[$i]->getData(TPS_PAYMENT_FEE_ID);
             $tax_fee_code = $tps_records[$i]->getData(TPS_PAYMENT_TAX_FEE_CODE);
             $tps_amount_due = $tps_records[$i]->getData(TPS_PAYMENT_TOTAL_AMOUNT_DUE);
             $tps_amount_paid = $tps_records[$i]->getData(TPS_PAYMENT_AMOUNT_PAID);
             $tps_penalty_amount = $tps_records[$i]->getData(TPS_PAYMENT_PENALTY_AMOUNT);
             $tps_penalty_amount_paid = $tps_records[$i]->getData(TPS_PAYMENT_PENALTY_AMOUNT_PAID);
             $tps_interest_amount = $tps_records[$i]->getData(TPS_PAYMENT_INTEREST_AMOUNT);
             $tps_interest_amount_paid = $tps_records[$i]->getData(TPS_PAYMENT_INTEREST_AMOUNT_PAID);
             $total_amount_paid = $tps_records[$i]->getData(TPS_PAYMENT_TOTAL_AMOUNT_PAID);
             // ---- RETRIEVE TAX/FEE DATA
             $clsTaxFee = new EBPLTaxFeeSysRef($this->m_dbLink, false);
             $clsTaxFeePayable = $clsTaxFee->loadTaxFee($tax_fee_code);
             $clsTaxFeeSurcharge = $clsTaxFee->loadTaxFee($clsTaxFeePayable->getData(EBPLS_SURCHARGE_TAX_FEE_CODE));
             $clsTaxFeeInterest = $clsTaxFee->loadTaxFee($clsTaxFeePayable->getData(EBPLS_INTEREST_TAX_FEE_CODE));
             if ($clsTaxFeePayable == -1 || $clsTaxFeeSurcharge == -1 || $clsTaxFeeInterest == -1) {
                 $this->debug("Unable to load tax fee code {$tax_fee_code}," . $clsTaxFeePayable->getData(EBPLS_SURCHARGE_TAX_FEE_CODE) . "," . $clsTaxFeePayable->getData(EBPLS_INTEREST_TAX_FEE_CODE));
                 $this->setError(-1, "Unable to load tax fee code {$tax_fee_code}," . $clsTaxFeePayable->getData(EBPLS_SURCHARGE_TAX_FEE_CODE) . "," . $clsTaxFeePayable->getData(EBPLS_INTEREST_TAX_FEE_CODE));
                 // roll back
                 return -1;
             }
             // retrieve account codes
             $tax_fee_account_code = $clsTaxFeePayable->getData(EBPLS_TAX_ACCOUNT_CODE);
             $surcharge_account_code = $clsTaxFeeSurcharge->getData(EBPLS_TAX_ACCOUNT_CODE);
             $interest_account_code = $clsTaxFeeInterest->getData(EBPLS_TAX_ACCOUNT_CODE);
             // ---- COMPUTE BALANCE
             // formula = ( Total Amount Due = (Payable Amount - Paid Amount) + ( Surcharge - Surcharge Paid ) + ( Interest - Interest Paid ) - ( Total Paid Amount )
             // compute raw tax mount due less the raw tax amount paid
             $raw_tax_difference = $tps_amount_due - $tps_amount_paid;
             $total_amount_due = $raw_tax_difference;
             $this->debug("COMPUTE BALANCE : {$raw_tax_difference} = ( {$tps_amount_due} - {$tps_amount_paid} )");
             // compute penalty incurred not yet paid on previous payment
             $penalty_tax_difference = $tps_penalty_amount - $tps_penalty_amount_paid;
             $total_amount_due += $penalty_tax_difference;
             $this->debug("COMPUTE PENALTY : {$penalty_tax_difference} = ( {$tps_penalty_amount} - {$tps_penalty_amount_paid} )");
             // compute interest incurred not yet paid on previous payment
             $interest_tax_difference = $tps_interest_amount - $tps_interest_amount_paid;
             $total_amount_due += $interest_tax_difference;
             $this->debug("COMPUTE INTEREST : {$interest_tax_difference} = ( {$tps_interest_amount} - {$tps_interest_amount_paid} )");
             // compute total balance payable
             // this will be used to calculate interest/surcharge, since these items requires balance amount
             $total_amount_payable = $total_amount_due - $total_amount_paid;
             //$this->debug("COMPUTE TOTAL : $total_amount_payable = $total_amount_due - $total_amount_paid");
             // --------------------------------------------------------------------------
             // ---- PROCESS PAYMENT
             // pay balance on raw tax amount
             if ($raw_tax_difference > 0) {
                 if ($amount > $raw_tax_difference) {
                     // deduct cash in hand with the raw tax amount paid
                     $amount -= $raw_tax_difference;
                     $tax_paid_set = $raw_tax_difference;
                     $tps_amount_paid += $raw_tax_difference;
                 } else {
                     // deduct cash in hand with the raw tax amount paid
                     $tps_amount_paid += $amount;
                     $tax_paid_set = $amount;
                     $amount = 0;
                 }
             }
             // pay surcharge
             if ($penalty_tax_difference > 0 && $amount > 0) {
                 if ($amount > $penalty_tax_difference) {
                     // deduct cash in hand with the penalty tax unpaid
                     $amount -= $penalty_tax_difference;
                     $surcharge_paid_set = $penalty_tax_difference;
                     $tps_penalty_amount_paid += $penalty_tax_difference;
                 } else {
                     // add penalty to tps_penalty_amount
                     $tps_penalty_amount_paid += $amount;
                     $surcharge_paid_set = $amount;
                     $amount = 0;
                 }
                 $tps_penalty_amount_paid += $surcharge_paid_set;
             }
             // pay interest
             if ($interest_tax_difference > 0 && $amount > 0) {
                 if ($amount > $interest_tax_difference) {
                     // deduct cash in hand with the penalty tax unpaid
                     $amount -= $interest_tax_difference;
                     $interest_paid_set = $interest_tax_difference;
                     $tps_interest_amount_paid += $interest_tax_difference;
                 } else {
                     // add interest to tps_interest_amount
                     $tps_interest_amount_paid += $amount;
                     $interest_paid_set = $amount;
                     $amount = 0;
                 }
             }
             // --------------------------------------------------------------------------
             // ---- UPDATE PAYMENT SCHEDULE RECORD
             unset($tps_records[$i]->data_elems);
             $tps_records[$i]->data_elems[TPS_PAYMENT_AMOUNT_PAID] = $tps_amount_paid;
             $tps_records[$i]->data_elems[TPS_PAYMENT_PENALTY_AMOUNT_PAID] = $tps_penalty_amount_paid;
             $tps_records[$i]->data_elems[TPS_PAYMENT_INTEREST_AMOUNT_PAID] = $tps_interest_amount_paid;
             $tps_records[$i]->data_elems[TPS_PAYMENT_TOTAL_AMOUNT_PAID] = $tps_amount_paid + $tps_penalty_amount_paid + $tps_interest_amount_paid;
             $tps_records[$i]->data_elems[TPS_PAYMENT_LAST_UPDATED_BY] = $admin;
             $tps_records[$i]->data_elems[TPS_PAYMENT_LAST_UPDATE_TS] = date("Y-m-d H:i:s");
             $this->debug("{$tps_amount_paid} == {$tps_amount_due} && {$tps_penalty_amount} == {$tps_penalty_amount_paid} && {$tps_interest_amount} == {$tps_interest_amount_paid} ");
             if ($tps_amount_paid == $tps_amount_due && $tps_penalty_amount == $tps_penalty_amount_paid && $tps_interest_amount == $tps_interest_amount_paid) {
                 $tps_records[$i]->data_elems[TPS_PAYMENT_STATUS] = TPS_PAYMENT_STATE_PAID;
                 $tps_records[$i]->data_elems[TPS_PAYMENT_DATE] = date("Y-m-d H:i:s");
             }
             if ($bCommit) {
                 $retUpdate = $tps_records[$i]->_update($trans_obj, $payment_id, $admin);
             } else {
                 $retUpdate = 1;
             }
             if ($retUpdate > 0) {
                 $this->debug("Adding OR Details [tps={$tax_paid_set},sps={$surcharge_paid_set},ips={$interest_paid_set}]");
                 if ($tax_paid_set > 0) {
                     $ret1 = $this->addORDetails($or_code, $trans_obj->getData(TRANS_ID), $payment_id, $fee_id, $tax_fee_code, $cash_account_code, $tax_fee_account_code, $tax_paid_set, "CASH", $bCommit);
                     if ($ret1 < 0) {
                         $this->setError(-1, "error on execute of addORDetails params( {$or_code}, " . $trans_obj->getData(TRANS_ID) . ", {$payment_id}, {$fee_id}, {$tax_fee_code}, {$cash_account_code}, {$tax_fee_account_code}, {$tax_paid_set}, CASH, {$bCommit} )!");
                         // roll back here
                         return -1;
                     }
                 } else {
                     $ret2 = 1;
                 }
                 if ($surcharge_paid_set > 0) {
                     $ret2 = $this->addORDetails($or_code, $trans_obj->getData(TRANS_ID), $payment_id, $fee_id, $tax_fee_code, $cash_account_code, $interest_account_code, $surcharge_paid_set, "SURCHARGE", $bCommit);
                     if ($ret2 < 0) {
                         $this->setError(-2, "error on execute of addORDetails params( {$or_code}, " . $trans_obj->getData(TRANS_ID) . ", {$payment_id}, {$fee_id}, {$tax_fee_code}, {$cash_account_code}, {$interest_account_code}, {$surcharge_paid_set}, SURCHARGE, {$bCommit} )!");
                         // roll back here
                         return -2;
                     }
                 } else {
                     $ret2 = 1;
                 }
                 if ($interest_paid_set > 0) {
                     $ret3 = $this->addORDetails($or_code, $trans_obj->getData(TRANS_ID), $payment_id, $fee_id, $tax_fee_code, $cash_account_code, $surcharge_account_code, $interest_paid_set, "INTEREST", $bCommit);
                     if ($ret3 < 0) {
                         $this->setError(-3, "error on execute of addORDetails params( {$or_code}, " . $trans_obj->getData(TRANS_ID) . ", {$payment_id}, {$fee_id}, {$tax_fee_code}, {$cash_account_code}, {$surcharge_account_code}, {$interest_paid_set}, INTEREST, {$bCommit} )!");
                         // roll back here
                         return -3;
                     }
                 } else {
                     $ret3 = 1;
                 }
                 $this->debug("Adding OR Details [r1={$ret1},r2={$ret2},r3={$ret3}]");
             }
             if ($amount <= 0) {
                 $this->debug("Payment done!");
                 break;
             }
         }
         $this->debug("CREATE OR Payment done LEFT = {$amount}!");
         if ($bCommit) {
             $retCreateOR = $this->create($or_code, $payment_code, $trans_obj->getData(TRANS_ID), $tmp_amount, $bCommit);
             if ($retCreateOR < 0) {
                 // roll back here
                 $this->debug("Error on create of OR header, return {$retCreateOR}!");
                 $this->setError(-6, "Error on create of OR header, return {$retCreateOR}!");
                 return -6;
             }
             $ret_or_code = update_system_code($this->m_dbLink, CODES_OR_COL, $or_code);
             $ret_payment_code = update_system_code($this->m_dbLink, CODES_PAY_COL, $payment_code);
             $tmp_amount_due = $clsTPS->getTotalAmountDue($trans_obj->getData(TRANS_ID));
             if ($tmp_amount_due > 0) {
                 $trans_obj->_setTransPaymentStatusINTERNAL($payment_code, $amount, 'PARTIAL', $admin);
             } else {
                 $trans_obj->_setTransPaymentStatusINTERNAL($payment_code, $amount, 'PAID', $admin);
             }
         }
         // commit here
         return 1;
     } else {
         $this->setError(-1, "All payables have been paid.");
         return -1;
     }
 }
コード例 #4
0
 function setTransactionStatus($trans_id, $status, $creator, $user_level)
 {
     switch ($status) {
         case TRANS_STATUS_ASSESSMENT:
             if ($user_level != TRANS_LEVEL_APPLICATION_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("setTransactionStatus Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "setTransactionStatus Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("setTransactionStatus Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "setTransactionStatus Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_APPLICATION) {
                 $this->debug("setTransactionStatus Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "setTransactionStatus Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             // NOTE : additional checking should be done here if all requirements have been submitted
             $pen_req_list = $this->getRequirementList(REQUIREMENT_STATUS_PENDING);
             //print_r($pen_req_list);
             if ($pen_req_list != -1 && count($pen_req_list) > 0) {
                 $this->debug("setTransactionStatus Failed, pending requirements not yet submitted.");
                 $this->setError(-1, "setTransactionStatus Failed, pending requirements not yet submitted.");
                 return -1;
             }
             ebpls_start_transaction($this->m_dbLink);
             $ass_code = get_next_system_code($this->m_dbLink, CODES_ASS_COL);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_ASSESSMENT;
             $strValue[TRANS_ASSESSMENT_CODE] = $ass_code;
             $strValue[TRANS_ASSESSMENT_DATE] = date("Y-m-d H:i:s");
             $strValue[TRANS_APPLICATION_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
             if ($ret < 0) {
                 $this->debug("Promotion of transaction to ASSESSMENT stage failed.");
                 $this->setError(-1, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to ASSESSMENT stage ok.");
                 $ret_app_code = update_system_code($this->m_dbLink, CODES_ASS_COL, $ass_code);
             }
             ebpls_commit_transaction($this->m_dbLink);
             break;
         case TRANS_STATUS_PAYMENT:
             if ($user_level != TRANS_LEVEL_ASSESSMENT_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("assessTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "assessTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("assessTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "assessTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_ASSESSMENT) {
                 $this->debug("assessTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "assessTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             // NOTE : check if payment mode have beens set
             if (!$this->isPaymentModeSet()) {
                 $this->setError(-1, "Payment not yet set, please set payment mode before setting transaction for payment status.");
                 return -1;
             }
             ebpls_start_transaction($this->m_dbLink);
             $pay_code = get_next_system_code($this->m_dbLink, CODES_PAY_COL);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_PAYMENT;
             $strValue[TRANS_PAYMENT_CODE] = $pay_code;
             $strValue[TRANS_PAYMENT_DATE] = date("Y-m-d H:i:s");
             $strValue[TRANS_ASSESSMENT_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
             if ($ret < 0) {
                 $this->debug("Promotion of transaction to ASSESSMENT stage failed.");
                 $this->setError(-1, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to ASSESSMENT stage ok.");
                 $ret_app_code = update_system_code($this->m_dbLink, CODES_PAY_COL, $pay_code);
             }
             ebpls_commit_transaction($this->m_dbLink);
             break;
         case TRANS_STATUS_APPROVAL:
             if ($user_level != TRANS_LEVEL_PAYMENT_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("paymentTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "paymentTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("paymentTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "paymentTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_PAYMENT) {
                 $this->debug("paymentTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "paymentTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             //
             ebpls_start_transaction($this->m_dbLink);
             $apr_code = get_next_system_code($this->m_dbLink, CODES_APR_COL);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_APPROVAL;
             $strValue[TRANS_APPROVAL_CODE] = $apr_code;
             $strValue[TRANS_APPROVAL_DATE] = date("Y-m-d H:i:s");
             $strValue[TRANS_PAYMENT_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
             if ($ret < 0) {
                 $this->debug("Promotion of transaction to ASSESSMENT stage failed.");
                 $this->setError(-1, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to ASSESSMENT stage ok.");
                 $ret_app_code = update_system_code($this->m_dbLink, CODES_APR_COL, $apr_code);
             }
             ebpls_commit_transaction($this->m_dbLink);
             break;
         case TRANS_STATUS_RELEASING:
             if ($user_level != TRANS_LEVEL_APPROVAL_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("approveTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "approveTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("approveTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "approveTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_APPROVAL) {
                 $this->debug("setStatusForReleasing Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "setStatusForReleasing Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             ebpls_start_transaction($this->m_dbLink);
             $rel_code = get_next_system_code($this->m_dbLink, CODES_REL_COL);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_RELEASING;
             $strValue[TRANS_RELEASE_CODE] = $rel_code;
             $strValue[TRANS_RELEASE_DATE] = date("Y-m-d H:i:s");
             $strValue[TRANS_APPROVAL_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
             if ($ret < 0) {
                 $this->debug("Promotion of transaction to ASSESSMENT stage failed.");
                 $this->setError(-1, get_db_error());
                 ebpls_rollback_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to ASSESSMENT stage ok.");
                 $ret_app_code = update_system_code($this->m_dbLink, CODES_REL_COL, $rel_code);
             }
             ebpls_commit_transaction($this->m_dbLink);
             break;
         case TRANS_STATUS_RELEASED:
         case TRANS_STATUS_REJECTED:
             if ($user_level != TRANS_LEVEL_RELEASING_OFFICER && $user_level != TRANS_LEVEL_ADMIN_OFFICER && $user_level != TRANS_LEVEL_ROOT_OFFICER) {
                 $this->debug("releaseTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 $this->setError(-1, "releaseTransaction Failed, user level {$user_level} of {$admin} is not allowed.");
                 return -1;
             }
             if (!is_numeric($this->getData(TRANS_ID))) {
                 $this->debug("releaseTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 $this->setError(-1, "releaseTransaction Failed, transaction not loaded, load by invoking loadTransaction.");
                 return -1;
             }
             if ($this->getData(TRANS_TRANSACTION_STATUS) != TRANS_STATUS_RELEASING) {
                 $this->debug("releaseTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 $this->setError(-1, "releaseTransaction Failed, transaction status already " . $this->getData(TRANS_TRANSACTION_STATUS));
                 return -1;
             }
             // get permit no
             $permit_type = $this->getPermitType();
             $permit_id = $this->getPermitId();
             switch ($permit_type) {
                 case PERMIT_TYPE_BUSINESS:
                     $key = CODES_PERMIT_BUS_COL;
                     break;
                 case PERMIT_TYPE_OCCUPATIONAL:
                     $key = CODES_PERMIT_OCCUPATIONAL_COL;
                     break;
                 case PERMIT_TYPE_PEDDLER:
                     $key = CODES_PERMIT_PEDDLER_COL;
                     break;
                 case PERMIT_TYPE_FRANCHISE:
                     $key = CODES_PERMIT_FRANCHISE_BUS_COL;
                     break;
                 case PERMIT_TYPE_MOTORIZED:
                     $key = CODES_PERMIT_MOTORIZED_COL;
                     break;
                 case PERMIT_TYPE_FISHERY:
                     $key = CODES_PERMIT_FISHERY_COL;
                     break;
                 default:
                     $this->debug("Invalid Transaction permit type {$permit_type}, can't process release of transaction.");
                     return -1;
                     break;
             }
             ebpls_start_transaction($this->m_dbLink);
             $strWhere[TRANS_ID] = $trans_id;
             $strValue[TRANS_TRANSACTION_STATUS] = $status;
             $strValue[TRANS_RELEASE_DATE_PROCESSED] = date("Y-m-d H:i:s");
             $strValue[TRANS_ADMIN_USER] = $creator;
             if ($status == TRANS_STATUS_RELEASED && ($this->getData(TRANS_TYPE) == TRANS_TYPE_NEW || $this->getData(TRANS_TYPE) == TRANS_TYPE_RENEW)) {
                 $permit_code = get_next_system_code($this->m_dbLink, $key);
                 $strValue[TRANS_PERMIT_CODE] = $permit_code;
             }
             // use ebplsPermit as a factory class to retrieve proper class reference with the right type
             // of EBPLSPermit subclass
             $clsPermit = new EBPLSPermit($this->m_dbLink, false);
             $clsPermitToUpdate = $clsPermit->createPermit($this->m_dbLink, $permit_id, $permit_type, false);
             if ($clsPermitToUpdate != null) {
                 // update transaction with permit code of permit
                 $ret = ebpls_update_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValue, $strWhere);
                 if ($ret < 0) {
                     $this->debug("Promotion of transaction to {$status} stage failed.");
                     $this->setError(-1, get_db_error());
                     ebpls_rollback_transaction($this->m_dbLink);
                 } else {
                     // update permit of table
                     $clsPermitToUpdate->assignPermitCode($permit_code);
                     if ($status == TRANS_STATUS_RELEASED && ($this->getData(TRANS_TYPE) == TRANS_TYPE_NEW || $this->getData(TRANS_TYPE) == TRANS_TYPE_RENEW)) {
                         $ret_app_code = update_system_code($this->m_dbLink, $key, $permit_code);
                     }
                     $this->debug("Promotion of transaction to {$status} stage ok.");
                 }
                 // set permit status
                 if ($permit_type == PERMIT_TYPE_BUSINESS) {
                     $clsBus = new EBPLSEnterprise($this->m_dbLink);
                     $clsBus->_updateBusinessNatureApplication($nature_code, NULL, NULL, NULL, "PROCESSED");
                 }
                 ebpls_commit_transaction($this->m_dbLink);
             } else {
                 $this->debug("Promotion of transaction to {$status} stage failed, unable to create class permit to assigne permit code.");
                 ebpls_rollback_transaction($this->m_dbLink);
             }
             break;
         default:
             $this->debug("Unrecognized status {$status} value passed.");
             break;
     }
     $this->data_elem[TRANS_TRANSACTION_STATUS] = $status;
     return $ret;
 }