summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-13 21:27:59 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-12-13 21:27:59 +0000
commit03bfa825f47a35ff8fac5c9a0ffa95107687901c (patch)
treeb34647425df248a3ca0699f7b59ec7b7c131883e /sql
parent536b29fa6ca68c26012785df5ad6807ce96acc40 (diff)
Added a routine to sanitize the CGI variables. Needed for some CSV exports routines.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1978 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql')
-rw-r--r--sql/modules/Payment.sql15
-rw-r--r--sql/modules/Voucher.sql25
2 files changed, 31 insertions, 9 deletions
diff --git a/sql/modules/Payment.sql b/sql/modules/Payment.sql
index f48bd22f..77a48045 100644
--- a/sql/modules/Payment.sql
+++ b/sql/modules/Payment.sql
@@ -207,10 +207,6 @@ This then returns a set of contact information with a 2 dimensional array
cnsisting of outstanding invoices.
$$;
-CREATE OR REPLACE FUNCTION payment_create_queue_entry() RETURNS int AS
-$$
-$$ LANGUAGE PLPGSQL;
-
CREATE OR REPLACE FUNCTION payment_bulk_queue
(in_transactions numeric[], in_batch_id int, in_source text, in_total numeric,
in_ar_ap_accno text, in_cash_accno text,
@@ -233,21 +229,22 @@ $$ LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION job__process_payment(in_job_id int)
RETURNS bool AS $$
DECLARE
- queue_record RECORD
- t_auth_name text,
+ queue_record RECORD;
+ t_auth_name text;
BEGIN
-- TODO: Move the set session authorization into a utility function
- SELECT created_by INTO t_auth_name FROM pending_jobs
+ SELECT entered_by INTO t_auth_name FROM pending_job
WHERE id = in_job_id;
- EXECUTE 'SET SESSION AUTHORIZATION ' quote_ident(t_auth_name);
+ EXECUTE 'SET SESSION AUTHORIZATION ' || quote_ident(t_auth_name);
FOR queue_record IN
SELECT * from payments_queue WHERE job_id = in_job_id
LOOP
PERFORM payment_bulk_post
(transactions, batch_id, source, total, ar_ap_accno, cash_accno,
- payment_date, account_class);
+ payment_date, account_class)
+ FROM payments_queue WHERE job_id = in_job_id;
END LOOP;
UPDATE pending_job
SET completed_at = timeofday()::timestamp,
diff --git a/sql/modules/Voucher.sql b/sql/modules/Voucher.sql
index 5227a848..0633ab5d 100644
--- a/sql/modules/Voucher.sql
+++ b/sql/modules/Voucher.sql
@@ -221,3 +221,28 @@ BEGIN
return currval('batch_id_seq');
END;
$$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION batch_delete(in_batch_id int) RETURNS int AS
+$$
+DECLARE
+ t_transaction_ids int[];
+BEGIN
+
+ -- voucher_id is only set in acc_trans on payment/receipt vouchers and
+ -- their reversals. -CT
+ DELETE FROM acc_trans WHERE voucher_id IN
+ (select voucher_id FROM voucher where batch_id = in_batch_id);
+
+ SELECT as_array(trans_id) INTO t_transaction_ids
+ FROM voucher WHERE batch_id = in_batch_id AND batch_class IN (1, 2, 5);
+
+ DELETE FROM acc_trans WHERE trans_id = ANY(t_transaction_ids);
+ DELETE FROM ap WHERE id = ANY(t_transaction_ids);
+ DELETE FROM gl WHERE id = ANY(t_transaction_ids);
+ DELETE FROM voucher WHERE batch_id = in_batch_id;
+ DELETE FROM batch WHERE id = in_batch_id;
+ DELETE FROM transactions WHERE id = ANY(t_transaction_ids);
+
+ RETURN 1;
+END;
+$$ language plpgsql;