[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4561] trunk/sql/modules/Business_Unit.sql
- Subject: SF.net SVN: ledger-smb:[4561] trunk/sql/modules/Business_Unit.sql
- From: ..hidden..
- Date: Sun, 25 Mar 2012 07:32:48 +0000
Revision: 4561
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4561&view=rev
Author: einhverfr
Date: 2012-03-25 07:32:47 +0000 (Sun, 25 Mar 2012)
Log Message:
-----------
Triggers to maintain customer/vendor links
Modified Paths:
--------------
trunk/sql/modules/Business_Unit.sql
Modified: trunk/sql/modules/Business_Unit.sql
===================================================================
--- trunk/sql/modules/Business_Unit.sql 2012-03-25 07:04:59 UTC (rev 4560)
+++ trunk/sql/modules/Business_Unit.sql 2012-03-25 07:32:47 UTC (rev 4561)
@@ -187,4 +187,36 @@
RETURNS business_unit AS
$$ SELECT * FROM business_unit where id = $1; $$ LANGUAGE SQL;
+CREATE OR REPLACE FUNCTION eca_bu_trigger() RETURNS TRIGGER AS
+$$
+BEGIN
+ IF TG_OP = 'INSERT'
+ INSERT INTO business_unit(class_id, description, credit_id)
+ VALUES (7 - NEW.entity_class, NEW.meta_number, NEW.id);
+ ELSIF TG_OP = 'UPDATE'
+ IF new.meta_number <> old.meta_number THEN
+ UPDATE business_unit SET description = new.meta_number
+ WHERE class_id = 7 - NEW.entity_class
+ AND credit_id = new.id;
+ END IF;
+ ELSIF TG_OP = 'DELETE'
+ DELETE FROM business_unit WHERE class_id = 7 - NEW.entity_class
+ AND credit_id = old_id;
+ RETURN;
+ END IF;
+ RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+DROP TRIGGER IF EXISTS eca_maintain_b_units CASCADE;
+DROP TRIGGER IF EXISTS eca_maintain_b_units_del CASCADE;
+
+CREATE TRIGGER eca_maintain_b_units AFTER INSERT OR UPDATE
+ ON entity_credit_account
+ FOR EACH ROW EXECUTE PROCEDURE eca_bu_trigger();
+
+CREATE TRIGGER eca_maintain_b_units_del BEFORE DELETE
+ ON entity_credit_account
+ FOR EACH ROW EXECUTE PROCEDURE eca_bu_trigger();
+
COMMIT;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.