From f0ac3781f1a75e5c82434b7d78a5c3e0f6027eb2 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Sun, 2 Sep 2007 07:03:56 +0000 Subject: Correcting bug 1753372: COGS posts to closed dates when books closed after sales invoice issued. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1502 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/IR.pm | 57 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'LedgerSMB') diff --git a/LedgerSMB/IR.pm b/LedgerSMB/IR.pm index 197c9943..0afbc827 100644 --- a/LedgerSMB/IR.pm +++ b/LedgerSMB/IR.pm @@ -414,39 +414,52 @@ sub post_invoice { if ($linetotal) { $query = qq| - INSERT INTO acc_trans - (trans_id, - chart_id, - amount, - transdate, - project_id, - invoice_id) - VALUES (?, ?, ?, ?, - ?, ?)|; + INSERT INTO acc_trans + (trans_id, + chart_id, + amount, + project_id, + invoice_id, + transdate) + VALUES (?, ?, ?, ?, + ?, (SELECT CASE WHEN ? > value::date + THEN ? + ELSE value::date + + '1 day'::interval + END AS value + FROM defaults + WHERE setting_key = 'closedto' + ))|; my $sth = $dbh->prepare($query); $sth->execute( $ref->{trans_id}, $ref->{inventory_accno_id}, - $linetotal, $ref->{transdate}, - $ref->{project_id}, $invoice_id + $linetotal, + $ref->{project_id}, $invoice_id, + $ref->{transdate}, $ref->{transdate}, ) || $form->dberror($query); # add expense $query = qq| - INSERT INTO acc_trans - (trans_id, - chart_id, - amount, - transdate, - project_id, - invoice_id) - VALUES (?, ?, ?, ?, - ?, ?)|; + INSERT INTO acc_trans + (trans_id, chart_id, amount, + project_id, invoice_id, + transdate) + VALUES (?, ?, ?, ?, + ?, (SELECT CASE WHEN ? > value::date + THEN ? + ELSE value::date + + '1 day'::interval + END AS value + FROM defaults + WHERE setting_key = 'closedto' + ))|; $sth = $dbh->prepare($query); $sth->execute( $ref->{trans_id}, $ref->{expense_accno_id}, - $linetotal * -1, $ref->{transdate}, - $ref->{project_id}, $invoice_id + $linetotal * -1, + $ref->{project_id}, $invoice_id, + $ref->{transdate}, $ref->{transdate}, ) || $form->dberror($query); } -- cgit v1.2.3