summaryrefslogtreecommitdiff
path: root/sql/modules
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-19 06:05:41 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-19 06:05:41 +0000
commitc2f3e31ee16b527315a3c6ffde4f4001c431f9ee (patch)
tree9b45b8246f4c1d64345f7cfa24aeba2f4ec4e6db /sql/modules
parentf97616a63f7c121d6cf5371fc249c8476b763c08 (diff)
Some voucher fixes
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1795 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql/modules')
-rw-r--r--sql/modules/Voucher.sql29
1 files changed, 22 insertions, 7 deletions
diff --git a/sql/modules/Voucher.sql b/sql/modules/Voucher.sql
index 6ed8fa7d..d626595f 100644
--- a/sql/modules/Voucher.sql
+++ b/sql/modules/Voucher.sql
@@ -193,7 +193,7 @@ RETURNS BOOL AS
$$
DECLARE
control_amount NUMERIC;
- voucher vouchers%ROWTYPE;
+ voucher voucher%ROWTYPE;
incriment NUMERIC;
BEGIN
-- CHECK CONTROL NUMBERS
@@ -204,7 +204,7 @@ BEGIN
SELECT id FROM gl
WHERE coalesce(approved, false) != true)
AND trans_id IN (
- SELECT transaction_id FROM vouchers
+ SELECT transaction_id FROM voucher
WHERE batch_id = ANY (in_batch_id))
AND coalesce(approved, false) != true
AND amount > 0
@@ -214,7 +214,7 @@ BEGIN
SELECT sum(ac.amount) INTO control_amount
FROM acc_trans ac
- JOIN vouchers v ON (v.transaction_id = ac.trans_id)
+ JOIN voucher v ON (v.transaction_id = ac.trans_id)
WHERE v.batch_id = ANY (in_batch_id)
AND ac.vr_id = v.id
AND coalesce(approved, false) = false
@@ -224,7 +224,7 @@ BEGIN
SELECT sum(amount) INTO control_amount
FROM acc_trans
WHERE trans_id IN
- (SELECT transaction_id FROM vouchers
+ (SELECT transaction_id FROM voucher
WHERE batch_id = ANY (in_batch_id))
AND trans_id IN
(SELECT trans_id FROM ap
@@ -245,20 +245,20 @@ BEGIN
UPDATE acc_trans
SET approved = true
WHERE trans_id IN
- (SELECT transaction_id FROM vouchers
+ (SELECT transaction_id FROM voucher
WHERE batch_id = ANY (in_batch_id));
IF in_batch = 'gl' THEN
UPDATE gl SET approved = true
WHERE trans_id IN
- (SELECT transaction_id FROM vouchers
+ (SELECT transaction_id FROM voucher
WHERE batch_id = ANY (in_batch_id));
ELSE
UPDATE ap SET approved = true
WHERE trans_id IN
- (SELECT transaction_id FROM vouchers
+ (SELECT transaction_id FROM voucher
WHERE batch_id = ANY (in_batch_id));
END IF;
END IF;
@@ -266,3 +266,18 @@ BEGIN
RETURN TRUE;
END;
$$ LANGUAGE PLPGSQL;
+
+
+CREATE OR REPLACE FUNCTION batch_create(
+in_batch_number text, in_description text, in_batch_class text) RETURNS int AS
+$$
+BEGIN
+ INSERT INTO
+ batch (batch_class_id, description, control_code, created_by)
+ VALUES ((SELECT id FROM batch_class WHERE class = in_batch_class),
+ in_description, in_batch_number,
+ (select id FROM users WHERE username = session_user));
+
+ return currval('batch_id_seq');
+END;
+$$ LANGUAGE PLPGSQL;