diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-10-08 20:47:38 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-10-08 20:47:38 +0000 |
commit | 68399771603d9a2d084a9eaca480f17016801fe6 (patch) | |
tree | 02859ae3e2743f8b141a9837f703c21d77651759 /LedgerSMB/IR.pm | |
parent | 7376ef357ac4dce6bf30548c773774dddd2ea033 (diff) |
First round of tax code replacement, adds cumulative tax support
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@195 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/IR.pm')
-rwxr-xr-x | LedgerSMB/IR.pm | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/LedgerSMB/IR.pm b/LedgerSMB/IR.pm index 92e2c964..9f2da830 100755 --- a/LedgerSMB/IR.pm +++ b/LedgerSMB/IR.pm @@ -32,6 +32,7 @@ #====================================================================== package IR; +use LedgerSMB::Tax; use LedgerSMB::PriceMatrix; sub post_invoice { @@ -172,33 +173,24 @@ sub post_invoice { my $linetotal = $form->round_amount($amount, 2); $fxdiff += $amount - $linetotal; - @taxaccounts = split / /, $form->{"taxaccounts_$i"}; + @taxaccounts = Tax::init_taxes($form, $form->{"taxaccounts_$i"}); - $ml = 1; - $tax = 0; - $fxtax = 0; + $tax = Math::BigFloat->bzero(); + $fxtax = Math::BigFloat->bzero(); - for (0 .. 1) { - $taxrate = 0; - - # add tax rates - for (@taxaccounts) { - $taxrate += $form->{"${_}_rate"} if ($form->{"${_}_rate"} * $ml) > 0; - } - - if ($form->{taxincluded}) { - $tax += $amount = $linetotal * ($taxrate / (1 + ($taxrate * $ml))); - $form->{"sellprice_$i"} -= $amount / $form->{"qty_$i"}; - } else { - $tax += $amount = $linetotal * $taxrate; - $fxtax += $fxlinetotal * $taxrate; - } - - for (@taxaccounts) { - $form->{acc_trans}{$form->{id}}{$_}{amount} += $amount * $form->{"${_}_rate"} / $taxrate if ($form->{"${_}_rate"} * $ml) > 0; - } - - $ml = -1; + if ($form->{taxincluded}) { + $tax += $amount = Tax::calculate_taxes(\@taxaccounts, $form, + $linetotal, 1); + $form->{"sellprice_$i"} -= $amount / $form{"qty_$i"}; + } else { + $tax += $amount = Tax::calculate_taxes(\@taxaccounts, $form, + $linetotal, 0); + $fxtax += Tax::calculate_taxes(\@taxaccounts, $form, + $fxlinetotal, 0); + } + + for (@taxaccounts) { + $form->{acc_trans}{$form->{id}}{$_->account}{amount} += $_->value; } $grossamount = $form->round_amount($linetotal, 2); |