[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [1511] trunk/LedgerSMB
- Subject: SF.net SVN: ledger-smb: [1511] trunk/LedgerSMB
- From: ..hidden..
- Date: Wed, 05 Sep 2007 16:05:41 -0700
Revision: 1511
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1511&view=rev
Author: einhverfr
Date: 2007-09-05 16:05:40 -0700 (Wed, 05 Sep 2007)
Log Message:
-----------
Fixing bug 1761766: Sales tax change will affect previous invoices
Modified Paths:
--------------
trunk/LedgerSMB/AM.pm
trunk/LedgerSMB/Tax.pm
Modified: trunk/LedgerSMB/AM.pm
===================================================================
--- trunk/LedgerSMB/AM.pm 2007-09-05 23:02:18 UTC (rev 1510)
+++ trunk/LedgerSMB/AM.pm 2007-09-05 23:05:40 UTC (rev 1511)
@@ -2021,8 +2021,11 @@
# 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 @@
$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);
}
Modified: trunk/LedgerSMB/Tax.pm
===================================================================
--- trunk/LedgerSMB/Tax.pm 2007-09-05 23:02:18 UTC (rev 1510)
+++ trunk/LedgerSMB/Tax.pm 2007-09-05 23:05:40 UTC (rev 1511)
@@ -44,18 +44,25 @@
}
}
- 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'};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.