summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-28 19:38:22 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-28 19:38:22 +0000
commitae08355c14b1d079b9f65d57aa937e9ed7bccdd6 (patch)
tree320512f47c11b62e0ed1acd3a7abe7c4418a5fab
parentedcc1da31f8815b090ca43bba32bf824aff7aac8 (diff)
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
-rw-r--r--sql/modules/Payment.sql12
1 files changed, 7 insertions, 5 deletions
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;