From: Bernd Bleßmann Date: Mon, 30 Jun 2014 09:14:45 +0000 (+0200) Subject: DB-Trigger, um sicher zu stellen, dass ein Lagerplatz auch zum Lager gehört. X-Git-Tag: release-3.2.0beta~410 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=f1faf9a9eca4073119f7c7e0f43e70399e041777;p=kivitendo-erp.git DB-Trigger, um sicher zu stellen, dass ein Lagerplatz auch zum Lager gehört. Betrifft #2485. --- diff --git a/sql/Pg-upgrade2/check_bin_belongs_to_wh_trigger.sql b/sql/Pg-upgrade2/check_bin_belongs_to_wh_trigger.sql new file mode 100644 index 000000000..5b5e3d931 --- /dev/null +++ b/sql/Pg-upgrade2/check_bin_belongs_to_wh_trigger.sql @@ -0,0 +1,28 @@ +-- @tag: check_bin_belongs_to_wh_trigger +-- @description: Trigger, um sicher zu stellen, dass ein angegebener Lagerplatz auch zum Lager gehört. +-- @depends: delivery_orders warehouse +-- @encoding: utf-8 + +CREATE FUNCTION check_bin_belongs_to_wh() RETURNS "trigger" + AS 'BEGIN + IF NEW.bin_id IS NULL AND NEW.warehouse_id IS NULL THEN + RETURN NEW; + END IF; + IF NEW.bin_id IN (SELECT id FROM bin WHERE warehouse_id = NEW.warehouse_id) THEN + RETURN NEW; + ELSE + RAISE EXCEPTION ''bin (id=%) does not belong to warehouse (id=%).'', NEW.bin_id, NEW.warehouse_id; + RETURN NULL; + END IF; + END;' + LANGUAGE plpgsql; + + +CREATE TRIGGER check_bin_wh_delivery_order_items_stock BEFORE INSERT OR UPDATE ON delivery_order_items_stock + FOR EACH ROW EXECUTE PROCEDURE check_bin_belongs_to_wh(); + +CREATE TRIGGER check_bin_wh_inventory BEFORE INSERT OR UPDATE ON inventory + FOR EACH ROW EXECUTE PROCEDURE check_bin_belongs_to_wh(); + +CREATE TRIGGER check_bin_wh_parts BEFORE INSERT OR UPDATE ON parts + FOR EACH ROW EXECUTE PROCEDURE check_bin_belongs_to_wh();