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

SF.net SVN: ledger-smb: [2016] trunk/sql/modules/Payment.sql



Revision: 2016
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2016&view=rev
Author:   einhverfr
Date:     2007-12-28 11:38:22 -0800 (Fri, 28 Dec 2007)

Log Message:
-----------
Correcting join in payment select for single payment

Modified Paths:
--------------
    trunk/sql/modules/Payment.sql

Modified: trunk/sql/modules/Payment.sql
===================================================================
--- trunk/sql/modules/Payment.sql	2007-12-28 07:04:34 UTC (rev 2015)
+++ trunk/sql/modules/Payment.sql	2007-12-28 19:38:22 UTC (rev 2016)
@@ -81,20 +81,22 @@
 		            ELSE (a.amount - a.paid) * c.discount / 100  
 		       END AS due
 		  FROM (SELECT id, invnumber, transdate, amount, entity_id,
-		               1 as invoice_class, paid, curr
+		               1 as invoice_class, paid, curr, 
+		               entity_credit_account
 		          FROM ap
                          UNION
 		        SELECT id, invnumber, transdate, amount, entity_id,
-		               2 AS invoice_class, paid, curr
+		               2 AS invoice_class, paid, curr,
+		               entity_credit_account
 		          FROM ar
 		       ) a
-		  JOIN entity_credit_account c USING (entity_id)
+		  JOIN entity_credit_account c ON (c.id = a.entity_credit_account
+			OR (a.entity_credit_account IS NULL and 
+				a.entity_id = c.entity_id))
 		 WHERE a.invoice_class = in_account_class
 		       AND c.entity_class = in_account_class
 		       AND a.amount - a.paid <> 0
 		       AND a.curr = in_curr
-		       AND a.credit_account = coalesce(in_entity_credit_id, 
-				a.credit_account)
 	LOOP
 		RETURN NEXT payment_inv;
 	END LOOP;


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