diff options
Diffstat (limited to 'bin/mozilla')
-rwxr-xr-x | bin/mozilla/aa.pl | 120 | ||||
-rwxr-xr-x | bin/mozilla/am.pl | 20 | ||||
-rwxr-xr-x | bin/mozilla/ic.pl | 4 | ||||
-rwxr-xr-x | bin/mozilla/io.pl | 9 | ||||
-rwxr-xr-x | bin/mozilla/ir.pl | 20 | ||||
-rwxr-xr-x | bin/mozilla/is.pl | 30 | ||||
-rwxr-xr-x | bin/mozilla/oe.pl | 22 | ||||
-rwxr-xr-x | bin/mozilla/pos.pl | 30 |
8 files changed, 115 insertions, 140 deletions
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|<option>$item--$form->{"${item}_description"}|; - $totaltax += $form->{"tax_$item"}; - } - } - $ml *= -1; - } - $totaltax += $form->round_amount($diff, 2); - - $form->{checktax} = 1; - + $totaltax = Tax::calculate_taxes(\@taxaccounts, $form, + $form->{invtotal}, 1); } else { - foreach $item (@taxaccounts) { - $form->{"calctax_$item"} = 1 if $form->{calctax}; - - if ($form->{"calctax_$item"}) { - $form->{"tax_$item"} = $form->round_amount($form->{invtotal} * $form->{"${item}_rate"}, 2); - } - $form->{"select$form->{ARAP}_tax_$item"} = qq|<option>$item--$form->{"${item}_description"}|; - $totaltax += $form->{"tax_$item"}; + $totaltax = Tax::calculate_taxes(\@taxaccounts, $form, + $form->{invtotal}, 0); + } + foreach $item (@taxaccounts) { + $taccno = $item->account; + if ($form->{calctax}) { + $form->{"calctax_$taccno"} = 1; + $form->{"tax_$taccno"} = $form->round_amount($item->value, 2); } + $form->{"select$form->{ARAP}_tax_$taccno"} = qq|<option>$taccno--$form->{"${taccno}_description"}|; } $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index 9be1c020..666b5522 100755 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -1868,7 +1868,9 @@ sub taxes { $form->{"taxrate_$i"} = $form->format_amount(\%myconfig, $ref->{rate}); $form->{"taxdescription_$i"} = $ref->{description}; - for (qw(taxnumber validto)) { $form->{"${_}_$i"} = $ref->{$_} } + for (qw(taxnumber validto pass taxmodulename)) { + $form->{"${_}_$i"} = $ref->{$_}; + } $form->{taxaccounts} .= "$ref->{id}_$i "; } chop $form->{taxaccounts}; @@ -1901,6 +1903,8 @@ sub display_taxes { <th>|.$locale->text('Rate').qq| (%)</th> <th>|.$locale->text('Number').qq|</th> <th>|.$locale->text('Valid To').qq|</th> + <th>|.$locale->text('Order').qq|</th> + <th>|.$locale->text('Tax Rules').qq|</th> </tr> |; @@ -1926,8 +1930,18 @@ sub display_taxes { <td><input name="taxrate_$i" size=6 value=$form->{"taxrate_$i"}></td> <td><input name="taxnumber_$i" value="$form->{"taxnumber_$i"}"></td> <td><input name="validto_$i" size=11 value="$form->{"validto_$i"}" title="$myconfig{dateformat}"></td> - </tr> -|; + <td><input name="pass_$i" size=6 value="$form->{"pass_$i"}"></td> + <td><select name="taxmodule_id_$i" size=1>|; + foreach my $taxmodule (sort keys %$form) { + next if ($taxmodule !~ /^taxmodule_/); + my $modulenum = $taxmodule; + $modulenum =~ s/^taxmodule_//; + print '<option label="'.$form->{$taxmodule}.'" value="'.$modulenum . '"'; + print " SELECTED " if $form->{$taxmodule} eq $form->{"taxmodulename_$i"}; + print " />\n"; + } + print qq|</select></td> + </tr> |; $sametax = $form->{"taxdescription_$i"}; } diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl index 99eb7f5c..16e67d24 100755 --- a/bin/mozilla/ic.pl +++ b/bin/mozilla/ic.pl @@ -42,6 +42,7 @@ use LedgerSMB::IC; +use LedgerSMB::Tax; require "$form->{path}/io.pl"; @@ -2981,7 +2982,8 @@ sub save { $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"}; for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount } if (!$form->{taxincluded}) { - for (split / /, $form->{"taxaccounts_$i"}) { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } + my @taxlist= Tax::init_taxes($form, $form->{"taxaccounts_$i"}); + $amount += Tax::calculate_taxes(\@taxlist, $form, $amount, 0); } $ml = 1; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index d81fa34c..b2ea21b2 100755 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -38,6 +38,8 @@ # ####################################################################### +use LedgerSMB::Tax; + # any custom scripts for this one if (-f "$form->{path}/custom_io.pl") { eval { require "$form->{path}/custom_io.pl"; }; @@ -504,7 +506,8 @@ sub item_selected { $amount = $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) * $form->{"qty_$i"}; for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount } if (!$form->{taxincluded}) { - for (split / /, $form->{"taxaccounts_$i"}) { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } + my @taxlist= Tax::init_taxes($form, $form->{"taxaccounts_$i"}); + $amount += Tax::calculate_taxes(\@taxlist, $form, $amount, 0); } $form->{creditremaining} -= $amount; @@ -840,7 +843,9 @@ sub invoicetotal { } if (!$form->{taxincluded}) { - for (split / /, $form->{taxaccounts}) { $form->{oldinvtotal} += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } + my @taxlist= Tax::init_taxes($form, $form->{taxaccounts}); + $form->{oldinvtotal} += Tax::calculate_taxes(\@taxlist, $form, + $amount, 0); } $form->{oldtotalpaid} = 0; diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 35f9975b..be87e9eb 100755 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -41,6 +41,7 @@ use LedgerSMB::IR; use LedgerSMB::PE; +use LedgerSMB::Tax; require "$form->{path}/io.pl"; require "$form->{path}/arap.pl"; @@ -422,11 +423,14 @@ sub form_footer { } if (!$form->{taxincluded}) { - - foreach $item (split / /, $form->{taxaccounts}) { + my @taxset = Tax::init_taxes($form, $form->{taxaccounts}); + $form->{invtotal} += $form->round_amount( + Tax::calculate_taxes(\@taxset, $form, $form->{invsubtotal}, 0), 2); + foreach $taxobj (@taxset) { + $item = $taxobj->account; if ($form->{"${item}_base"}) { - $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2); - $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); + $form->{"${item}_total"} = $form->format_amount(\%myconfig, + $form->round_amount($taxobj->value, 2), 2); $tax .= qq| <tr> @@ -673,7 +677,10 @@ sub import_text { $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100); map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts}); map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"}); - map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded}; + if (!$form->{taxincluded}) { + my @taxes = Tax::init_taxes($form, $form->{taxaccounts}); + $amount += (Tax::calculate_taxes(\@taxes, $form, $amount, 0)); + } $form->{creditremaining} -= $amount; @@ -794,7 +801,8 @@ sub update { for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 } for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount } if (!$form->{taxincluded}) { - for (split / /, $form->{"taxaccounts_$i"}) { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } + my @taxes = Tax::init_taxes($form, $form->{"taxaccounts_$i"}); + $amount += (Tax::calculate_taxes(\@taxes, $form, $amount, 0)); } $form->{creditremaining} -= $amount; diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 5696dd11..c93c2337 100755 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -46,6 +46,7 @@ use LedgerSMB::IS; use LedgerSMB::PE; +use LedgerSMB::Tax; require "$form->{path}/arap.pl"; require "$form->{path}/io.pl"; @@ -470,19 +471,19 @@ sub form_footer { if (!$form->{taxincluded}) { - for (split / /, $form->{taxaccounts}) { - if ($form->{"${_}_base"}) { - $form->{"${_}_total"} = $form->round_amount($form->{"${_}_base"} * $form->{"${_}_rate"}, 2); - $form->{invtotal} += $form->{"${_}_total"}; - $form->{"${_}_total"} = $form->format_amount(\%myconfig, $form->{"${_}_total"}, 2); - - $tax .= qq| - <tr> - <th align=right>$form->{"${_}_description"}</th> - <td align=right>$form->{"${_}_total"}</td> - </tr> -|; - } + my @taxes = Tax::init_taxes($form, $form->{taxaccounts}); + $form->{invtotal} += Tax::calculate_taxes(\@taxes, $form, + $form->{invsubtotal}, 0); + foreach $item (@taxes) { + my $taccno = $item->account; + $form->{"${taccno}_total"} = $form->format_amount(\%myconfig, + $item->value, 2); + $tax .= qq| + <tr> + <th align=right>$form->{"${taccno}_description"}</th> + <td align=right>$form->{"${taccno}_total"}</td> + </tr> + | if $item->value; } $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); @@ -813,7 +814,8 @@ sub update { for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 } for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount } if (!$form->{taxincluded}) { - for (split / /, $form->{"taxaccounts_$i"}) { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } + my @taxes = Tax::init_taxes($form, $form->{"taxaccounts_$i"}); + $amount += Tax::calculate_taxes(\@taxes, $form, $amount, 0); } $form->{creditremaining} -= $amount; diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index b0910db5..d4b4bba3 100755 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -44,6 +44,7 @@ use LedgerSMB::OE; use LedgerSMB::IR; use LedgerSMB::IS; use LedgerSMB::PE; +use LedgerSMB::Tax; require "$form->{path}/arap.pl"; require "$form->{path}/io.pl"; @@ -600,19 +601,21 @@ sub form_footer { if (!$form->{taxincluded}) { - for (split / /, $form->{taxaccounts}) { - if ($form->{"${_}_base"}) { - $form->{invtotal} += $form->{"${_}_total"} = $form->round_amount($form->{"${_}_base"} * $form->{"${_}_rate"}, 2); - $form->{"${_}_total"} = $form->format_amount(\%myconfig, $form->{"${_}_total"}, 2); + my @taxes = Tax::init_taxes($form, $form->{taxaccounts}); + $form->{invtotal} += Tax::calculate_taxes(\@taxes, + $form, $form->{invsubtotal}, 0); + foreach my $item (@taxes) { + my $taccno = $item->account; + $form->{"${taccno}_total"} = $form->format_amount(\%myconfig, + $item->value, 2); $tax .= qq| <tr> - <th align=right>$form->{"${_}_description"}</th> - <td align=right>$form->{"${_}_total"}</td> + <th align=right>$form->{"${taccno}_description"}</th> + <td align=right>$form->{"${taccno}_total"}</td> </tr> -|; + | if $item->value; } - } $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); @@ -917,7 +920,8 @@ sub update { for (split / /, $form->{taxaccounts}) { $form->{"${_}_base"} = 0 } for (split / /, $form->{"taxaccounts_$i"}) { $form->{"${_}_base"} += $amount } if (!$form->{taxincluded}) { - for (split / /, $form->{taxaccounts}) { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } + my @taxes = Tax::init_taxes($form, $form->{taxaccounts}); + $amount += Tax::calculate_taxes(\@taxes, $form, $amount, 0); } $form->{creditremaining} -= $amount; diff --git a/bin/mozilla/pos.pl b/bin/mozilla/pos.pl index f7f817ea..ef2fbd92 100755 --- a/bin/mozilla/pos.pl +++ b/bin/mozilla/pos.pl @@ -40,6 +40,7 @@ # #===================================================================== +use LedgerSMB::Tax; 1; # end @@ -376,19 +377,22 @@ sub form_footer { if (!$form->{taxincluded}) { - for (split / /, $form->{taxaccounts}) { - if ($form->{"${_}_base"}) { - $form->{"${_}_total"} = $form->round_amount($form->{"${_}_base"} * $form->{"${_}_rate"}, 2); - $form->{invtotal} += $form->{"${_}_total"}; - $form->{"${_}_total"} = $form->format_amount(\%myconfig, $form->{"${_}_total"}, 2, 0); - - $tax .= qq| - <tr> - <th align=right>$form->{"${_}_description"}</th> - <td align=right>$form->{"${_}_total"}</td> - </tr> -|; - } + my @taxes = Tax::init_taxes($form, $form->{taxaccounts}); + $form->{invtotal} += Tax::calculate_taxes(\@taxes, $form, + $form->{invsubtotal}, 0); + + foreach my $item (@taxes) { + my $taccno = $item->account; + + $form->{"${taccno}_total"} = $form->format_amount(\%myconfig, + $item->value, 2, 0); + + $tax .= qq| + <tr> + <th align=right>$form->{"${taccno}_description"}</th> + <td align=right>$form->{"${taccno}_total"}</td> + </tr> + | if $item->value; } $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); |