[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1502] trunk/LedgerSMB/IR.pm



Revision: 1502
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1502&view=rev
Author:   einhverfr
Date:     2007-09-02 00:03:56 -0700 (Sun, 02 Sep 2007)

Log Message:
-----------
Correcting bug 1753372:  COGS posts to closed dates when books closed after sales invoice issued.

Modified Paths:
--------------
    trunk/LedgerSMB/IR.pm

Modified: trunk/LedgerSMB/IR.pm
===================================================================
--- trunk/LedgerSMB/IR.pm	2007-09-02 07:02:25 UTC (rev 1501)
+++ trunk/LedgerSMB/IR.pm	2007-09-02 07:03:56 UTC (rev 1502)
@@ -414,39 +414,52 @@
 
                     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);
                     }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.