X-Git-Url: http://wagnertech.de/git?p=kivitendo-erp.git;a=blobdiff_plain;f=sql%2FPg-upgrade2%2Fadd_parts_price_history2.sql;fp=sql%2FPg-upgrade2%2Fadd_parts_price_history2.sql;h=ebf0036d772b0cceb8985a3fc76f45ad7f2eb4c7;hp=0000000000000000000000000000000000000000;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44 diff --git a/sql/Pg-upgrade2/add_parts_price_history2.sql b/sql/Pg-upgrade2/add_parts_price_history2.sql new file mode 100644 index 000000000..ebf0036d7 --- /dev/null +++ b/sql/Pg-upgrade2/add_parts_price_history2.sql @@ -0,0 +1,18 @@ +-- @tag: add_parts_price_history2 +-- @description: Korrigierte Triggerfunktion für Entwicklung der Stammdatenpreise +-- @depends: add_parts_price_history +CREATE OR REPLACE FUNCTION add_parts_price_history_entry() RETURNS "trigger" AS $$ + BEGIN + IF (TG_OP = 'UPDATE') + AND ((OLD.lastcost IS NULL AND NEW.lastcost IS NULL) OR (OLD.lastcost = NEW.lastcost)) + AND ((OLD.listprice IS NULL AND NEW.listprice IS NULL) OR (OLD.listprice = NEW.listprice)) + AND ((OLD.sellprice IS NULL AND NEW.sellprice IS NULL) OR (OLD.sellprice = NEW.sellprice)) THEN + RETURN NEW; + END IF; + + INSERT INTO parts_price_history (part_id, lastcost, listprice, sellprice, valid_from) + VALUES (NEW.id, NEW.lastcost, NEW.listprice, NEW.sellprice, now()); + + RETURN NEW; + END; +$$ LANGUAGE plpgsql;