summaryrefslogtreecommitdiff
path: root/LedgerSMB/Tax.pm
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-04-12 20:46:20 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-04-12 20:46:20 +0000
commitdf073d6e09c0f87fb2e88cc215ace843a5851d4a (patch)
tree1c15ce909d3e0353b21bbd909e6720fd485a3a53 /LedgerSMB/Tax.pm
parent65458125b8f3814fd6ef4d07b55ab69f62f5a528 (diff)
Formatting with Perltidy
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@1068 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/Tax.pm')
-rwxr-xr-xLedgerSMB/Tax.pm137
1 files changed, 70 insertions, 67 deletions
diff --git a/LedgerSMB/Tax.pm b/LedgerSMB/Tax.pm
index 1996f23c..70161257 100755
--- a/LedgerSMB/Tax.pm
+++ b/LedgerSMB/Tax.pm
@@ -4,15 +4,15 @@
# LedgerSMB::Tax
# Default simple tax application
#
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2006
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
#
#
@@ -30,85 +30,88 @@ package Tax;
use Math::BigFloat;
sub init_taxes {
- my ($form, $taxaccounts, $taxaccounts2) = @_;
- my $dbh = $form->{dbh};
- @taxes = ();
- my @accounts = split / /, $taxaccounts;
- if (defined $taxaccounts2){
- my @tmpaccounts = @accounts;
- $#accounts = 0;
- for my $acct (split / /, $taxaccounts2){
- if ($taxaccounts =~ /\s$acct\s/){
- push @accounts, $acct;
- }
- }
-
- }
- my $query = qq|SELECT t.taxnumber, c.description,
+ my ( $form, $taxaccounts, $taxaccounts2 ) = @_;
+ my $dbh = $form->{dbh};
+ @taxes = ();
+ my @accounts = split / /, $taxaccounts;
+ if ( defined $taxaccounts2 ) {
+ my @tmpaccounts = @accounts;
+ $#accounts = 0;
+ for my $acct ( split / /, $taxaccounts2 ) {
+ if ( $taxaccounts =~ /\s$acct\s/ ) {
+ push @accounts, $acct;
+ }
+ }
+
+ }
+ my $query = qq|SELECT t.taxnumber, c.description,
t.rate, t.chart_id, t.pass, m.taxmodulename
FROM tax t INNER JOIN chart c ON (t.chart_id = c.id)
INNER JOIN taxmodule m ON (t.taxmodule_id = m.taxmodule_id)
WHERE c.accno = ?|;
- my $sth = $dbh->prepare($query);
- foreach $taxaccount (@accounts) {
- next if (! defined $taxaccount);
- if (defined $taxaccounts2){
- next if $taxaccount !~ /$taxaccounts2/;
- }
- $sth->execute($taxaccount) || $form->dberror($query);
- my $ref = $sth->fetchrow_hashref;
+ my $sth = $dbh->prepare($query);
+ foreach $taxaccount (@accounts) {
+ next if ( !defined $taxaccount );
+ if ( defined $taxaccounts2 ) {
+ next if $taxaccount !~ /$taxaccounts2/;
+ }
+ $sth->execute($taxaccount) || $form->dberror($query);
+ my $ref = $sth->fetchrow_hashref;
- my $module = $ref->{'taxmodulename'};
- require "LedgerSMB/Taxes/${module}.pm";
- $module =~ s/\//::/g;
- my $tax = (eval 'Taxes::'.$module)->new();
+ my $module = $ref->{'taxmodulename'};
+ require "LedgerSMB/Taxes/${module}.pm";
+ $module =~ s/\//::/g;
+ my $tax = ( eval 'Taxes::' . $module )->new();
- $tax->pass($ref->{'pass'});
- $tax->account($taxaccount);
- $tax->rate(Math::BigFloat->new($ref->{'rate'}));
- $tax->taxnumber($ref->{'taxnumber'});
- $tax->chart($ref->{'chart'});
- $tax->description($ref->{'description'});
- $tax->value(Math::BigFloat->bzero());
+ $tax->pass( $ref->{'pass'} );
+ $tax->account($taxaccount);
+ $tax->rate( Math::BigFloat->new( $ref->{'rate'} ) );
+ $tax->taxnumber( $ref->{'taxnumber'} );
+ $tax->chart( $ref->{'chart'} );
+ $tax->description( $ref->{'description'} );
+ $tax->value( Math::BigFloat->bzero() );
- push @taxes, $tax;
- $sth->finish;
- }
- return @taxes;
+ push @taxes, $tax;
+ $sth->finish;
+ }
+ return @taxes;
}
sub calculate_taxes {
- my ($taxes, $form, $subtotal, $extract) = @_;
- my $total = Math::BigFloat->bzero();
- my %passes;
- foreach my $tax (@taxes) {
- push @{$passes{$tax->pass}}, $tax;
- }
- my @passkeys = sort keys %passes;
- @passkeys = reverse @passkeys if $extract;
- foreach my $pass (@passkeys) {
- my $passrate = Math::BigFloat->bzero();
- my $passtotal = Math::BigFloat->bzero();
- foreach my $tax (@{$passes{$pass}}) {
- $passrate += $tax->rate;
- }
- foreach my $tax (@{$passes{$pass}}) {
- $passtotal += $tax->apply_tax($form, $subtotal + $total) if not $extract;
- $passtotal += $tax->extract_tax($form, $subtotal - $total, $passrate) if $extract;
- }
- $total += $passtotal;
- }
- return $total;
+ my ( $taxes, $form, $subtotal, $extract ) = @_;
+ my $total = Math::BigFloat->bzero();
+ my %passes;
+ foreach my $tax (@taxes) {
+ push @{ $passes{ $tax->pass } }, $tax;
+ }
+ my @passkeys = sort keys %passes;
+ @passkeys = reverse @passkeys if $extract;
+ foreach my $pass (@passkeys) {
+ my $passrate = Math::BigFloat->bzero();
+ my $passtotal = Math::BigFloat->bzero();
+ foreach my $tax ( @{ $passes{$pass} } ) {
+ $passrate += $tax->rate;
+ }
+ foreach my $tax ( @{ $passes{$pass} } ) {
+ $passtotal += $tax->apply_tax( $form, $subtotal + $total )
+ if not $extract;
+ $passtotal +=
+ $tax->extract_tax( $form, $subtotal - $total, $passrate )
+ if $extract;
+ }
+ $total += $passtotal;
+ }
+ return $total;
}
sub apply_taxes {
- my ($taxes, $form, $subtotal) = @_;
- return $subtotal + calculate_taxes($taxes, $form, $subtotal, 0);
+ my ( $taxes, $form, $subtotal ) = @_;
+ return $subtotal + calculate_taxes( $taxes, $form, $subtotal, 0 );
}
sub extract_taxes {
- my ($taxes, $form, $subtotal) = @_;
- return $subtotal - calculate_taxes($taxes, $form, $subtotal, 1);
+ my ( $taxes, $form, $subtotal ) = @_;
+ return $subtotal - calculate_taxes( $taxes, $form, $subtotal, 1 );
}
1;