From 68399771603d9a2d084a9eaca480f17016801fe6 Mon Sep 17 00:00:00 2001 From: tetragon Date: Sun, 8 Oct 2006 20:47:38 +0000 Subject: 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 --- bin/mozilla/aa.pl | 120 +++++++++++++---------------------------------------- bin/mozilla/am.pl | 20 +++++++-- bin/mozilla/ic.pl | 4 +- bin/mozilla/io.pl | 9 +++- bin/mozilla/ir.pl | 20 ++++++--- bin/mozilla/is.pl | 30 +++++++------- bin/mozilla/oe.pl | 22 ++++++---- bin/mozilla/pos.pl | 30 ++++++++------ 8 files changed, 115 insertions(+), 140 deletions(-) (limited to 'bin') diff --git a/bin/mozilla/aa.pl b/bin/mozilla/aa.pl index 4f6665dc..6e0b09ac 100755 --- a/bin/mozilla/aa.pl +++ b/bin/mozilla/aa.pl @@ -44,6 +44,8 @@ # #====================================================================== +use LedgerSMB::Tax; + # any custom scripts for this one if (-f "$form->{path}/custom_aa.pl") { eval { require "$form->{path}/custom_aa.pl"; }; @@ -257,7 +259,8 @@ sub create_links { if ($form->{taxincluded}) { $diff = 0; - # add tax to individual amounts + # add tax to individual amounts + # XXX needs alteration for conditional taxes for $i (1 .. $form->{rowcount}) { if ($netamount) { $amount = $form->{"amount_$i"} * (1 + $tax / $netamount); @@ -272,53 +275,26 @@ sub create_links { # taxincluded is terrible to calculate # this works only if all taxes are checked - @taxaccounts = split / /, $form->{taxaccounts}; + @taxaccounts = Tax::init_taxes($form, $form->{taxaccounts}); if ($form->{id}) { if ($form->{taxincluded}) { - $ml = 1; + $amount = Tax::calculate_taxes(\@taxaccounts, $form, + $form->{invtotal}, 1); + $tax = $form->round_amount($amount, 2); - for (0 .. 1) { - $taxrate = 0; - $diff = 0; - - for (@taxaccounts) { $taxrate += $form->{"${_}_rate"} if ($form->{"${_}_rate"} * $ml) > 0 } - $taxrate *= $ml; - - foreach $item (@taxaccounts) { - - if (($form->{"${item}_rate"} * $ml) > 0) { - if ($taxrate) { - $amount = $form->{invtotal} * $form->{"${item}_rate"} / (1 + $taxrate); - $tax = $form->round_amount($amount, 2); - $tax{$item} = $form->round_amount($amount - $diff, 2); - $diff = $tax{$item} - ($amount - $diff); - - if ($tax) { - if ($form->{"tax_$item"} == $tax{$item}) { - $form->{"calctax_$item"} = 1; - } - } - } - } - } - $ml *= -1; + } else { + $tax = $form->round_amount(Tax::calculate_taxes(\@taxaccounts, + $form, $netamount, 0)); } - - } else { - for (@taxaccounts) { - $tax = $form->round_amount($netamount * $form->{"${_}_rate"}, 2); - if ($tax) { - if ($form->{"tax_$_"} == $tax) { - $form->{"calctax_$_"} = 1; - } + foreach $item (@taxaccounts) { + $tax{$item->account} = $form->round_amount($item->value, 2); + $form->{"calctax_".$item->account} = 1 if $item->value and ( + $tax{$item->account} == $form->{"tax_".$item->account}); } - } - } - } else { - for (@taxaccounts) { $form->{"calctax_$_"} = 1 } + for (@taxaccounts) { $form->{"calctax_".$_->account} = 1 } } @@ -830,61 +806,21 @@ sub update { for (@taxaccounts) { $form->{"tax_$_"} = $form->parse_amount(\%myconfig, $form->{"tax_$_"}) } + @taxaccounts = Tax::init_taxes($form, $form->{taxaccounts}); if ($form->{taxincluded}) { - - $ml = 1; - - for (0 .. 1) { - $taxrate = 0; - $diff = 0; - - for (@taxaccounts) { - if (($form->{"${_}_rate"} * $ml) > 0) { - if ($form->{"calctax_$_"}) { - $taxrate += $form->{"${_}_rate"}; - } else { - if ($form->{checktax}) { - if ($form->{"tax_$_"}) { - $taxrate += $form->{"${_}_rate"}; - } - } - } - } - } - - $taxrate *= $ml; - - foreach $item (@taxaccounts) { - if (($form->{"${item}_rate"} * $ml) > 0) { - - if ($taxrate) { - $a = $form->{invtotal} * $form->{"${item}_rate"} / (1 + $taxrate); - $b = $form->round_amount($a, 2); - $tax = $form->round_amount($a - $diff, 2); - $diff = $b - ($a - $diff); - } - $form->{"tax_$item"} = $tax if $form->{"calctax_$item"}; - - $form->{"select$form->{ARAP}_tax_$item"} = qq|