From ae08355c14b1d079b9f65d57aa937e9ed7bccdd6 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Fri, 28 Dec 2007 19:38:22 +0000 Subject: Correcting join in payment select for single payment git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2016 4979c152-3d1c-0410-bac9-87ea11338e46 --- sql/modules/Payment.sql | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'sql/modules/Payment.sql') diff --git a/sql/modules/Payment.sql b/sql/modules/Payment.sql index 1d177135..1f68d293 100644 --- a/sql/modules/Payment.sql +++ b/sql/modules/Payment.sql @@ -81,20 +81,22 @@ BEGIN 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; -- cgit v1.2.3