summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2008-06-23 21:57:46 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2008-06-23 21:57:46 +0000
commit17c0ab0a7ee10abc0b0397f21d0277096bdc15f7 (patch)
treee8ef09774fa813c45280c021f57b5c8fbc5a6c64 /sql
parent675bce61fec48b070d653424867e897cf57b72df (diff)
Correcting missing files and commits
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2170 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql')
-rw-r--r--sql/modules/Drafts.sql27
1 files changed, 22 insertions, 5 deletions
diff --git a/sql/modules/Drafts.sql b/sql/modules/Drafts.sql
index 40312388..c2fc5abb 100644
--- a/sql/modules/Drafts.sql
+++ b/sql/modules/Drafts.sql
@@ -1,6 +1,7 @@
CREATE TYPE draft_search_result AS (
id int,
transdate date,
+ reference text,
description text,
amount numeric
);
@@ -12,7 +13,8 @@ $$
DECLARE out_row RECORD;
BEGIN
FOR out_row IN
- SELECT trans.id, trans.transdate, trans.description,
+ SELECT trans.id, trans.transdate, trans.reference,
+ trans.description,
sum(case when in_type = 'ap' AND chart.link = 'AP'
THEN line.amount
WHEN in_type = 'ar' AND chart.link = 'AR'
@@ -22,13 +24,16 @@ BEGIN
ELSE 0
END) as amount
FROM (
- SELECT id, transdate, description, approved from ap
+ SELECT id, transdate, invnumber as reference,
+ description, approved from ap
WHERE in_type = 'ap'
UNION
- SELECT id, transdate, description, approved from ar
+ SELECT id, transdate, invnumber as reference,
+ description, approved from ar
WHERE in_type = 'ar'
UNION
- SELECT id, transdate, description, approved from gl
+ SELECT id, transdate, reference, description,
+ approved from gl
WHERE in_type = 'gl'
) trans
JOIN acc_trans line ON (trans.id = line.trans_id)
@@ -63,7 +68,19 @@ begin
ELSE
raise exception 'Invalid table % in draft_approve for transaction %', t_table, in_id;
END IF;
- RETURN FOUND;
+
+ IF NOT FOUND THEN
+ RETURN FALSE;
+ END IF;
+
+ UPDATE transactions
+ SET approved_by =
+ (select entity_id FROM users
+ WHERE username = SESSION_USER),
+ approved_at = now()
+ WHERE id = in_id;
+
+ RETURN TRUE;
END;
$$ LANGUAGE PLPGSQL SECURITY DEFINER;