集成在FushionInvoice中

时间:2014-02-21 00:00:51

标签: php calculator invoice

我已经解决了我的问题。有没有人对如何清理代码有任何想法? 它现在有效,我创造了这个。就像我之前说的那样,我刚刚开始并在FusonInvoice系统中集成了一些代码。但它确实有用,但我确信代码可以更清洁,更稳定。任何人吗?

// $invoice_tax_rate_amount = ($invoice_amount->invoice_item_subtotal + $invoice_amount->invoice_item_tax_total) * ($invoice_tax_rate->invoice_tax_rate_percent / 100);

$som = ($invoice_amount->invoice_item_subtotal + $invoice_amount->invoice_item_tax_total);

$rules = array(

    0 => array( 'percent' => 0.15, 'upper' => 2500 ),
    2500 => array( 'percent' => 0.10, 'upper' => 5000 ),
    5000 => array( 'percent' => 0.05, 'upper' => 10000 ),
    10000 => array( 'percent' => 0.01, 'upper' => 200000 ),
    200000 => array( 'percent' => 0.005, 'upper' => null ), 
);

$fee = 0;
$toCalculate = $som;
foreach( $rules as $lower => $rule ) {

    if($toCalculate <= 0) break;
    $current = min($rule['upper'], $toCalculate);
    $fee += $rule['percent'] * $current;
    $toCalculate -= $current;
}
$invoice_tax_rate_amount = $fee;

                }
                else
                {
                    // The invoice tax rate should not include the applied item tax

$som = ($invoice_amount->invoice_item_subtotal);

$rules = array(

    0 => array( 'percent' => 0.15, 'upper' => 2500 ),
    2500 => array( 'percent' => 0.10, 'upper' => 5000 ),
    5000 => array( 'percent' => 0.05, 'upper' => 10000 ),
    10000 => array( 'percent' => 0.01, 'upper' => 200000 ),
    200000 => array( 'percent' => 0.005, 'upper' => null ), 
);

$fee = 0;
$toCalculate = $som;
foreach( $rules as $lower => $rule ) {

    if($toCalculate <= 0) break;
    $current = min($rule['upper'], $toCalculate);
    $fee += $rule['percent'] * $current;
    $toCalculate -= $current;
}
$invoice_tax_rate_amount = $fee;

// $invoice_tax_rate_amount = $invoice_amount->invoice_item_subtotal * ($invoice_tax_rate->invoice_tax_rate_percent / 100);
                }

0 个答案:

没有答案