[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[6125] trunk/sql



Revision: 6125
          http://sourceforge.net/p/ledger-smb/code/6125
Author:   einhverfr
Date:     2013-10-14 07:34:08 +0000 (Mon, 14 Oct 2013)
Log Message:
-----------
Adding trigger to prevent transactions in closed periods

Modified Paths:
--------------
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Fixes.sql

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2013-10-11 09:10:28 UTC (rev 6124)
+++ trunk/sql/Pg-database.sql	2013-10-14 07:34:08 UTC (rev 6125)
@@ -1440,6 +1440,10 @@
 for payments.$$;
 
 CREATE INDEX acc_trans_voucher_id_idx ON acc_trans(voucher_id);
+
+-- preventing closed transactions
+
+
 --
 --
 CREATE TABLE parts (
@@ -2415,6 +2419,31 @@
 $$ This provides centralized support for insertions into audittrail.
 $$;
 
+CREATE FUNCTION prevent_closed_transactions() RETURNS trigger
+    LANGUAGE plpgsql
+    AS $$
+DECLARE t_end_date date;
+BEGIN
+SELECT max(end_date) into t_end_date FROM account_checkpoint;
+IF new.transdate <= t_end_date THEN
+    RAISE EXCEPTION 'Transaction entered into closed period.  Transdate: %',
+                   new.transdate;
+END IF;
+RETURN new;
+END;
+$$;
+
+CREATE TRIGGER acc_trans_prevent_closed BEFORE INSERT ON acc_trans 
+FOR EACH ROW EXECUTE PROCEDURE prevent_closed_transactions();
+CREATE TRIGGER ap_prevent_closed BEFORE INSERT ON ap 
+FOR EACH ROW EXECUTE PROCEDURE prevent_closed_transactions();
+CREATE TRIGGER ar_prevent_closed BEFORE INSERT ON ar 
+FOR EACH ROW EXECUTE PROCEDURE prevent_closed_transactions();
+CREATE TRIGGER gl_prevent_closed BEFORE INSERT ON gl 
+FOR EACH ROW EXECUTE PROCEDURE prevent_closed_transactions();
+
+
+
 CREATE TRIGGER gl_audit_trail AFTER INSERT OR UPDATE OR DELETE ON gl
 FOR EACH ROW EXECUTE PROCEDURE gl_audit_trail_append();
 

Modified: trunk/sql/modules/Fixes.sql
===================================================================
--- trunk/sql/modules/Fixes.sql	2013-10-11 09:10:28 UTC (rev 6124)
+++ trunk/sql/modules/Fixes.sql	2013-10-14 07:34:08 UTC (rev 6125)
@@ -205,3 +205,32 @@
 BEGIN;
 INSERT INTO defaults (setting_key, value) values ('dojo_theme', 'claro');
 COMMIT;
+
+BEGIN;
+CREATE FUNCTION prevent_closed_transactions() RETURNS trigger
+    LANGUAGE plpgsql
+    AS $$
+DECLARE t_end_date date;
+BEGIN
+SELECT max(end_date) into t_end_date FROM account_checkpoint;
+IF new.transdate <= t_end_date THEN
+    RAISE EXCEPTION 'Transaction entered into closed period.  Transdate: %',
+                   new.transdate;
+END IF;
+RETURN new;
+END;
+$$;
+
+
+CREATE TRIGGER acc_trans_prevent_closed BEFORE INSERT ON acc_trans 
+FOR EACH ROW EXECUTE PROCEDURE prevent_closed_transactions();
+CREATE TRIGGER ap_prevent_closed BEFORE INSERT ON ap 
+FOR EACH ROW EXECUTE PROCEDURE prevent_closed_transactions();
+CREATE TRIGGER ar_prevent_closed BEFORE INSERT ON ar 
+FOR EACH ROW EXECUTE PROCEDURE prevent_closed_transactions();
+CREATE TRIGGER gl_prevent_closed BEFORE INSERT ON gl 
+FOR EACH ROW EXECUTE PROCEDURE prevent_closed_transactions();
+COMMIT;
+
+
+

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits