summaryrefslogtreecommitdiff
path: root/sql/modules
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-29 01:21:15 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-29 01:21:15 +0000
commitaaf5222fc502164ed7193a1c7036a0b80824ca27 (patch)
treee4abb1efce735bc700567ee472fa8d4e44699c00 /sql/modules
parent93c240a9788ce8085ef68b76cf82efc0606fea2f (diff)
Correcting more Payment Problems
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1914 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql/modules')
-rw-r--r--sql/modules/Payment.sql19
1 files changed, 15 insertions, 4 deletions
diff --git a/sql/modules/Payment.sql b/sql/modules/Payment.sql
index b5beb196..1562a2ed 100644
--- a/sql/modules/Payment.sql
+++ b/sql/modules/Payment.sql
@@ -66,13 +66,13 @@ BEGIN
SELECT a.id AS invoice_id, a.invnumber,
a.transdate AS invoice_date, a.amount,
CASE WHEN discount_terms
- < extract('days' FROM age(a.transdate))
+ > extract('days' FROM age(a.transdate))
THEN 0
ELSE (a.amount - a.paid) * c.discount / 100
END AS discount,
a.amount - a.paid -
CASE WHEN discount_terms
- < extract('days' FROM age(a.transdate))
+ > extract('days' FROM age(a.transdate))
THEN 0
ELSE (a.amount - a.paid) * c.discount / 100
END AS due
@@ -87,6 +87,7 @@ BEGIN
JOIN entity_credit_account c USING (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.entity_id = coalesce(in_entity_id, a.entity_id)
LOOP
@@ -131,11 +132,14 @@ BEGIN
ELSE (a.amount - a.paid) * c.discount / 100
END)::text,
(a.amount - a.paid -
- CASE WHEN c.discount_terms
+ (CASE WHEN c.discount_terms
> extract('days' FROM age(a.transdate))
THEN 0
ELSE (a.amount - a.paid) * c.discount / 100
- END)::text]])
+ END))::text]]),
+ bool_and(lock_record(a.id, (select max(session_id) FROM "session" where users_id = (
+ select id from users WHERE username =
+ SESSION_USER))))
FROM entity e
JOIN entity_credit_account c ON (e.id = c.entity_id)
JOIN (SELECT id, invnumber, transdate, amount, entity_id,
@@ -146,6 +150,7 @@ BEGIN
paid, curr, 2 as invoice_class
FROM ar
) a USING (entity_id)
+ JOIN transactions t ON (a.id = t.id)
WHERE a.invoice_class = in_account_class
AND ((a.transdate >= in_date_from
AND a.transdate <= in_date_to)
@@ -153,6 +158,12 @@ BEGIN
WHERE batch_id = in_batch_id))
AND c.entity_class = in_account_class
AND a.curr = in_currency
+ AND a.amount - a.paid <> 0
+ AND t.locked_by NOT IN
+ (select "session_id" FROM "session"
+ WHERE users_id IN
+ (select id from users
+ where username <> SESSION_USER))
AND EXISTS (select trans_id FROM acc_trans
WHERE trans_id = a.id AND
chart_id = (SELECT id frOM chart