From 8266444ddc033a4d6584d2d023565df98173e5ea Mon Sep 17 00:00:00 2001 From: einhverfr Date: Wed, 5 Sep 2007 23:05:40 +0000 Subject: 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 --- LedgerSMB/Tax.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'LedgerSMB/Tax.pm') 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'}; -- cgit v1.2.3