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 createPaymentSchedule(&$trans_obj, $payment_mode, $bSeparateTaxesFromFees, $bIsUpdate, $admin) { $arrayDivisor = array(TRANS_PAYMENT_MODE_MONTHLY => 12, TRANS_PAYMENT_MODE_QUARTERLY => 4, TRANS_PAYMENT_MODE_SEMIANNUAL => 2, TRANS_PAYMENT_MODE_ANNUAL => 1); $divisor = $arrayDivisor[$payment_mode]; if ($divisor == "") { $this->setError(-1, "Payment mode invalid {$payment_mode}!"); $this->debug("Payment mode invalid {$payment_mode}!"); return -1; } $this->debug("createPaymentSchedule( &{$trans_obj}, {$payment_mode}, {$bSeparateTaxesFromFees}, {$bIsUpdate}, {$admin} )"); $clsPayables = new EBPLSTransactionFee($this->m_dbLink, false); $i = 0; if ($bSeparateTaxesFromFees) { // group all fee records payments as one payment $fee_records = $clsPayables->listFee($trans_obj->getData(TRANS_ID), array(PAYABLE_TYPE_FEE, PAYABLE_TYPE_TAX)); $i = $this->_createPaymentSchedule($trans_obj, $payment_mode, $fee_records, 1, $bIsUpdate); $this->debug("created payment sched for fees {$i}"); $payable_amount = 0; if (is_array($fee_records) && count($fee_records)) { for ($fee_index = 0; $fee_index < count($fee_records); $fee_index++) { $payable_amount += $fee_records[$fee_index]->getData(TF_TAX_TOTAL_AMOUNT_DUE); } } // distribute tax payments to the opted payment schedule $tax_records = $clsPayables->listFee($trans_obj->getData(TRANS_ID), PAYABLE_TYPE_BUSTAX); $i += $this->_createPaymentSchedule($trans_obj, $payment_mode, $tax_records, $divisor, $bIsUpdate); if (is_array($tax_records) && count($tax_records)) { for ($fee_index = 0; $fee_index < count($tax_records); $fee_index++) { $payable_amount += $tax_records[$fee_index]->getData(TF_TAX_TOTAL_AMOUNT_DUE); } } $this->debug("created payment sched for taxes {$i}, pay = {$payable_amount}"); } else { // distribute taxes/fees payments to the opted payment schedule $fee_records = $clsPayables->listFee($trans_obj->getData(TRANS_ID)); $i = $this->_createPaymentSchedule($trans_obj, $payment_mode, $fee_records, $divisor, $bIsUpdate); $payable_amount = 0; if (is_array($fee_records) && count($fee_records)) { for ($fee_index = 0; $fee_index < count($fee_records); $fee_index++) { $payable_amount += $fee_records[$fee_index]->getData(TF_TAX_TOTAL_AMOUNT_DUE); } } $this->debug("created payment sched for taxes/fees {$i}, pay = {$payable_amount}"); } if ($i > 0) { $this->debug("_setTransPaymentModeINTERNAL {$payable_amount}"); // update parent table payment mode and payment mode $trans_obj->_setTransPaymentModeINTERNAL($payment_mode, $payable_amount, NULL, $bSeparateTaxesFromFees, $admin); } return $i; }
function getFeesList() { if (!is_numeric($this->getData(TRANS_ID))) { $this->debug("getFeesListt Failed, transaction not loaded, load by invoking loadTransaction."); $this->setError(-1, "getFeesListt Failed, transaction not loaded, load by invoking loadTransaction."); return -1; } $clsTransReq = new EBPLSTransactionFee($this->m_dbLink); $fees_list = $clsTransReq->listFee($this->getData(TRANS_ID)); return $fees_list; }