function computeTaxTotalAmounDue($depth = 0) { if ($depth == 1) { return 0; } // terminate recursive call on comutetax // load the tax/fee record with its attached formula $clsTaxFeeRef = new EBPLTaxFeeSysRef($this->m_dbLink, false); $res_formula = $clsTaxFeeRef->select($this->getData(TF_TAX_FEE_CODE)); if (is_array($res_formula)) { $clsTaxFormula = $res_formula["result"][0]->getData(EBPLS_TAX_FORMULA); if ($clsTaxFormula) { // pass paramters to formula before computation for ($i = 1; $i <= TF_TAX_MAX_PARAMS; $i++) { $clsTaxFormula->setParameterValue($i, $this->getData(constant("TF_TAX_TAXABLE_AMOUNT{$i}")) + 0.0); } // process prerequisite tax/fees if there are any $arr_parameters = $clsTaxFormula->getParameterDescription(null, true); $this->debug("param cnt : " . count($arr_parameters)); foreach ($arr_parameters as $key => $value) { if (eregi("^\\[TF=(.*)\\]\$", $value, $arrTaxFeeCode) && eregi("^x([0-9]+)\$", $key, $arrIndex)) { $clsTaxFeeTmp = new EBPLSTransactionFee($this->m_dbLink, false); $res_formula = $clsTaxFeeTmp->view($this->getData(TF_TRANS_ID), $arrTaxFeeCode[1]); if ($res_formula) { $clsTaxFeeTmp->computeTaxTotalAmounDue(1); $this->debug("Tax/Fee Amount: " . $clsTaxFeeTmp->getData(TF_TAX_TOTAL_AMOUNT_DUE) . "!"); $this->setData(constant("TF_TAX_TAXABLE_AMOUNT" . $arrIndex[1]), $clsTaxFeeTmp->getData(TF_TAX_TOTAL_AMOUNT_DUE)); $clsTaxFormula->setParameterValue($arrIndex[1], floatval($clsTaxFeeTmp->getData(TF_TAX_TOTAL_AMOUNT_DUE))); } else { $this->setError(-6, "Unable to load prerequisite tax/fee " . $arrTaxFeeCode[1] . "!"); $this->debug("Unable to load prerequisite tax/fee " . $arrTaxFeeCode[1] . "!"); return -6; } } else { $this->debug("no match on {$value}"); } } $clsTaxFormula->setParameterTagValue("[CAPITAL]", $this->m_BusTaxCapital); $clsTaxFormula->setParameterTagValue("[LAST_GROSS]", $this->m_BusTaxLastGross); $index1 = $clsTaxFormula->getParameterTagValueIndex("[CAPITAL]"); if ($index1) { $this->setData(constant("TF_TAX_TAXABLE_AMOUNT" . $index1), $this->m_BusTaxCapital); } $index2 = $clsTaxFormula->getParameterTagValueIndex("[LAST_GROSS]"); if ($index2) { $this->setData(constant("TF_TAX_TAXABLE_AMOUNT" . $index2), $this->m_BusTaxLastGross); } $this->debug("FORMULA {$index1}=" . $this->m_BusTaxCapital . ",{$index2}=" . $this->m_BusTaxLastGross . "<BR>"); // compute $tax_amount = $clsTaxFormula->computeTax($this->m_BusTaxCapital, $this->m_BusTaxLastGross); if ($tax_amount >= 0) { $this->data_elems[TF_TAX_TOTAL_AMOUNT_DUE] = $tax_amount; $this->debug("FORMULA compuation OK<BR>"); return 1; } else { $this->setError(-1, $clsTaxFormula->getError()); return $tax_amount; } } else { $this->setError(-5, "Unable to load formula of tax/fee " . $this->getData(TF_TAX_FEE_CODE) . "!"); $this->debug("Unable to load formula of tax/fee " . $this->getData(TF_TAX_FEE_CODE) . "!"); return -5; } } else { $this->data_elems[TF_TAX_TOTAL_AMOUNT_DUE] = 0; $this->debug("FORMULA ERROR (cant find tax/fee code : " . $this->getData(TF_TAX_FEE_CODE) . "<BR>"); return -4; } }
function _createRetireLOBTransaction($nature_code, $creator, $user_level) { $clsTrans = new EBPLSTransaction($this->m_dbLink); // insert to transaction table $clsTrans->data_elems[TRANS_TYPE] = TRANS_TYPE_RETIREMENT; $clsTrans->data_elems[TRANS_PAYMENT_STATUS] = TPS_PAYMENT_STATE_UNPAID; $clsTrans->data_elems[TRANS_OWNER_ID] = $this->getData(TRANS_OWNER_ID); $clsTrans->data_elems[TRANS_BUSINESS_ID] = $this->getData(TRANS_BUSINESS_ID); $clsTrans->data_elems[TRANS_PERMIT_TYPE] = "BUS"; $this->debug("BUS ID : " . $clsTrans->data_elems[TRANS_BUSINESS_ID]); ebpls_start_transaction($clsTrans->m_dbLink); // get next transaction code $app_code = get_next_system_code($this->m_dbLink, CODES_APP_COL); $clsTrans->data_elems[TRANS_APPLICATION_CODE] = $app_code; $clsTrans->data_elems[TRANS_TRANSACTION_DATE] = date("Y-m-d H:i:s"); $clsTrans->data_elems[TRANS_APPLICATION_DATE] = date("Y-m-d H:i:s"); $clsTrans->data_elems[TRANS_ADMIN_USER] = $creator; $clsTrans->data_elems[TRANS_TRANSACTION_STATUS] = TRANS_STATUS_APPLICATION; $clsTrans->data_elems[TRANS_APPLICATION_CODE] = $app_code; $strValues = $clsTrans->data_elems; $ret = ebpls_insert_data($this->m_dbLink, EBPLS_TRANSACTION_TABLE, $strValues); if ($ret > 0) { $clsTrans->data_elems[TRANS_ID] = $ret; // create default application requirements $req_create = create_permit_requirements($this->m_dbLink, $ret, 0, "BUS", $creator, "APP", TRANS_TYPE_RETIREMENT); if ($req_create < 0) { $this->setError(-1, get_db_error()); } // create default fees $fee_create = create_permit_requirements($this->m_dbLink, $ret, 0, "BUS", $creator, "FEE", TRANS_TYPE_RETIREMENT); if ($fee_create < 0) { $this->setError(-1, get_db_error()); } // create default payable taxes $tax_nature_create = create_permit_requirements($this->m_dbLink, $ret, 0, "BUS", $creator, "TAX", TRANS_TYPE_RETIREMENT); if ($tax_nature_create < 0) { $this->setError(-1, get_db_error()); } if (!is_array($nature_code)) { $nature_code = array($nature_code); } for ($i = 0; $i < count($nature_code); $i++) { // check if there are already pending retirement business nature of this kind $clsExistNature = new EBPLSTransactionBusinessNature($clsTrans->m_dbLink, false); if ($clsExistNature->exist($this->data_elems[TRANS_BUSINESS_ID], $this->data_elems[TRANS_OWNER_ID], $nature_code[$i], "RETIREMENT") > 0) { $this->debug("_createRetireLOBTransaction : retirement of " . $nature_code[$i] . " already exist."); $this->setError(-19, "_createRetireLOBTransaction : retirement of " . $nature_code[$i] . " already exist."); ebpls_rollback_transaction($this->m_dbLink); return -19; } $clsNatureView = new EBPLSTransactionBusinessNature($this->m_dbLink, false); if ($clsNatureView->view($this->data_elems[TRANS_ID], $nature_code[$i]) > 0) { $clsFee = new EBPLSTransactionFee($this->m_dbLink, false); if ($clsFee->view($this->data_elems[TRANS_ID], NULL, $nature_code[$i]) > 0) { $clsPayables = new EBPLSTransactionPaymentSchedule($this->m_dbLink, false); $payables_due = $clsPayables->getTotalAmountDue($this->data_elems[TRANS_ID], $clsFee->getData(TF_TAX_FEE_CODE)); if ($payables_due > 0) { $this->debug("_createRetireLOBTransaction : retirement of " . $nature_code[$i] . " failed, current line of bus have pending payables."); $this->setError(-21, "_createRetireLOBTransaction : retirement of " . $nature_code[$i] . " failed, current line of bus have pending payables."); ebpls_rollback_transaction($this->m_dbLink); return -21; } } else { $this->debug("_createRetireLOBTransaction : retirement of " . $nature_code[$i] . " failed, nature code not linked to current transaction."); $this->setError(-21, "_createRetireLOBTransaction : retirement of " . $nature_code[$i] . " failed, nature code not linked to current transaction."); ebpls_rollback_transaction($this->m_dbLink); return -21; } $clsNature = new EBPLSTransactionBusinessNature($clsTrans->m_dbLink, false); $clsNature->setData(TRANS_BUSNATURE_TRANS_ID, $clsTrans->data_elems[TRANS_ID]); $clsNature->setData(TRANS_BUSNATURE_BUSINESS_ID, $clsTrans->data_elems[TRANS_BUSINESS_ID]); $clsNature->setData(TRANS_BUSNATURE_OWNER_ID, $clsTrans->data_elems[TRANS_OWNER_ID]); $clsNature->setData(TRANS_BUSNATURE_STATUS, "RETIREMENT"); $clsNature->setData(TRANS_BUSNATURE_CAPITAL_INVESTMENT, "0.0"); $clsNature->setData(TRANS_BUSNATURE_LAST_GROSS, "0.0"); $clsNature->setData(TRANS_BUSNATURE_BUSINESS_NATURE_CODE, $clsNatureView->getData(TRANS_BUSNATURE_BUSINESS_NATURE_CODE)); $clsNature->setData(TRANS_BUSNATURE_BUSINESS_DESCRIPTION, $clsNatureView->getData(TRANS_BUSNATURE_BUSINESS_DESCRIPTION)); $fee_nature_create = $clsNature->add(); if ($fee_nature_create < 0) { $this->setError($ret, $clsNature->getError()); $fee_nature_create = -12; } else { $clsNatureView2 = new EBPLSTransactionBusinessNature($this->m_dbLink, false); $clsNatureView2->setData(TRANS_BUSNATURE_STATUS, "RETIRED"); if (($fee_nature_create = $clsNatureView2->update($this->data_elems[TRANS_ID], $clsNatureView->getData(TRANS_BUSNATURE_BUSINESS_NATURE_CODE))) < 0) { //print_r( $clsNatureView2->getError() ); $this->setError($ret, $clsNatureView2->getError()); ebpls_rollback_transaction($this->m_dbLink); $fee_nature_create = -11; } // remove LOB from enterprise nature records // delete line of business from business nature list $clsBus = new EBPLSEnterprise($this->m_dbLink); $clsBus->deleteBusinessNature($nature_code[$i]); if ($clsBus->update($this->getData(TRANS_BUSINESS_ID), $admin, $user_level) < 0) { $this->debug("deleteLineOfBusiness : error on deleting line of business {$nature_code[$i]} on enterprise table."); $this->setError(-15, "deleteLineOfBusinessdeleteLineOfBusiness : error on deleting line of business {$nature_code[$i]} on enterprise table."); ebpls_rollback_transaction($this->m_dbLink); return $retAddFee; } // update trans $clsNature2 = new EBPLSTransactionBusinessNature($clsTrans->m_dbLink, false); $ret1 = $clsNature2->getList($this->data_elems[TRANS_ID], "PENDING"); $ret2 = $clsNature2->getList($this->data_elems[TRANS_ID], "PROCESSED"); if ($ret1 < 0 && $ret2 < 0) { $this->_setTransToRetire($admin); } } } else { // unable to find nature code $this->setError(-10, "Unable to find nature code {$nature_code[$i]} on current transaction!"); $fee_nature_create = -10; break; } } // update application system code $ret_app_code = update_system_code($this->m_dbLink, CODES_APP_COL, $app_code); if ($ret_app_code < 0) { $this->setError(-1, "FATAL ERROR : failed to update app code on codes table. [ret_app_code = {$ret_app_code}, req_create = {$req_create}, fee_create= {$fee_create}, fee_nature_create = {$fee_nature_create} ]"); } if ($ret_app_code < 0 || $req_create < 0 || $fee_create < 0 || $fee_nature_create < 0) { $this->debug("FATAL ERROR : failed to create transaction child records. [ret_app_code = {$ret_app_code}, req_create = {$req_create}, fee_create= {$fee_create}, fee_nature_create = {$fee_nature_create} ]"); $call_ret = -1; } else { $this->debug("Create transaction record ok.[trans_id={$ret}]"); $clsTrans->data_elems[TRANS_ID] = $ret; $call_ret = 1; } } else { $this->debug("FATAL ERROR : failed to create transaction record."); $this->setError(-1, get_db_error()); $call_ret = -1; } if ($call_ret < 0) { // rollback caused by error return on any of the sql executed above... ebpls_rollback_transaction($this->m_dbLink); return -1; } ebpls_commit_transaction($this->m_dbLink); return $clsTrans; }