diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-09-05 23:05:40 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-09-05 23:05:40 +0000 |
commit | 8266444ddc033a4d6584d2d023565df98173e5ea (patch) | |
tree | 274e5515945ba3799de63dfcb886bdf2578bed5f | |
parent | 311db34c7abbc4c78fe28994b13f21c4eb7f1e8d (diff) |
Fixing bug 1761766: Sales tax change will affect previous invoices
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1511 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r-- | LedgerSMB/AM.pm | 13 | ||||
-rw-r--r-- | LedgerSMB/Tax.pm | 15 |
2 files changed, 20 insertions, 8 deletions
diff --git a/LedgerSMB/AM.pm b/LedgerSMB/AM.pm index 79207304..9b1081eb 100644 --- a/LedgerSMB/AM.pm +++ b/LedgerSMB/AM.pm @@ -2021,8 +2021,11 @@ sub save_taxes { # connect to database my $dbh = $form->{dbh}; - my $query = qq|DELETE FROM tax|; - $dbh->do($query) || $form->dberror($query); + my $query = qq| + UPDATE tax + SET validto = (now())::date + WHERE chart_id = ?|; + my $update_sth = $dbh->prepare($query) || $form->dberror($query); $query = qq| INSERT INTO tax (chart_id, rate, taxnumber, validto, @@ -2036,11 +2039,13 @@ sub save_taxes { $form->parse_amount( $myconfig, $form->{"taxrate_$i"} ) / 100; my $validto = $form->{"validto_$i"}; $validto = undef if not $validto; + my @queryargs = ( - $chart_id, $rate, $form->{"taxnumber_$i"}, - $validto, $form->{"pass_$i"}, $form->{"taxmodule_id_$i"} + $chart_id, $rate, $form->{"taxnumber_$i"}, $validto, + $form->{"pass_$i"}, $form->{"taxmodule_id_$i"} ); + $update_sth->execute($chart_id) || $form->dberror($query); $sth->execute(@queryargs) || $form->dberror($query); } diff --git a/LedgerSMB/Tax.pm b/LedgerSMB/Tax.pm index 01bff4d4..dda940ec 100644 --- a/LedgerSMB/Tax.pm +++ b/LedgerSMB/Tax.pm @@ -44,18 +44,25 @@ sub init_taxes { } } - my $query = qq|SELECT t.taxnumber, c.description, + 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 = ?|; + INNER JOIN taxmodule m + ON (t.taxmodule_id = m.taxmodule_id) + WHERE c.accno = ? + AND coalesce(validto::timestamp, 'infinity') + >= coalesce(?::timestamp, now()) + ORDER BY validto ASC + LIMIT 1 + |; my $sth = $dbh->prepare($query); foreach $taxaccount (@accounts) { next if ( !defined $taxaccount ); if ( defined $taxaccounts2 ) { next if $taxaccounts2 !~ /\b$taxaccount\b/; } - $sth->execute($taxaccount) || $form->dberror($query); + $sth->execute($taxaccount, $form->{transdate}) || $form->dberror($query); my $ref = $sth->fetchrow_hashref; my $module = $ref->{'taxmodulename'}; |