From c8b156771d39f9893ca84093f547464f60adcd1b Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 9 Feb 2024 14:00:16 +0100 Subject: [PATCH 1/2] feat: refs #6395 Added buyerFk in buy --- db/routines/vn/triggers/buy_beforeInsert.sql | 1 + db/routines/vn/triggers/buy_beforeUpdate.sql | 4 ++++ db/versions/10880-salmonHydrangea/00-firstScript.sql | 1 + 3 files changed, 6 insertions(+) create mode 100644 db/versions/10880-salmonHydrangea/00-firstScript.sql diff --git a/db/routines/vn/triggers/buy_beforeInsert.sql b/db/routines/vn/triggers/buy_beforeInsert.sql index c88bef05a..c698e23e6 100644 --- a/db/routines/vn/triggers/buy_beforeInsert.sql +++ b/db/routines/vn/triggers/buy_beforeInsert.sql @@ -19,6 +19,7 @@ trig: BEGIN END IF; SET NEW.editorFk = account.myUser_getId(); + SET NEW.buyerFk = NEW.editorFk; CALL buy_checkGrouping(NEW.`grouping`); diff --git a/db/routines/vn/triggers/buy_beforeUpdate.sql b/db/routines/vn/triggers/buy_beforeUpdate.sql index fc03c456f..b41418bcc 100644 --- a/db/routines/vn/triggers/buy_beforeUpdate.sql +++ b/db/routines/vn/triggers/buy_beforeUpdate.sql @@ -65,6 +65,10 @@ trig:BEGIN SET NEW.isIgnored = TRUE; END IF; + IF NOT (NEW.itemFk <=> OLD.itemFk) THEN + SET NEW.buyerFk = NEW.editorFk; + END IF; + IF NOT (NEW.itemFk <=> OLD.itemFk) OR NOT (OLD.entryFk <=> NEW.entryFk) THEN CREATE OR REPLACE TEMPORARY TABLE tmp.buysToCheck diff --git a/db/versions/10880-salmonHydrangea/00-firstScript.sql b/db/versions/10880-salmonHydrangea/00-firstScript.sql new file mode 100644 index 000000000..934fc2020 --- /dev/null +++ b/db/versions/10880-salmonHydrangea/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.buy ADD buyerFk int(10) unsigned DEFAULT NULL NULL; From 184a3a3c7a453a1337e171d02970ecce9fb32db1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 14 Mar 2024 10:05:25 +0100 Subject: [PATCH 2/2] refs #6395 Requested changes --- db/routines/vn/triggers/buy_beforeInsert.sql | 9 ++++++++- db/routines/vn/triggers/buy_beforeUpdate.sql | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/triggers/buy_beforeInsert.sql b/db/routines/vn/triggers/buy_beforeInsert.sql index c698e23e6..a05f2810b 100644 --- a/db/routines/vn/triggers/buy_beforeInsert.sql +++ b/db/routines/vn/triggers/buy_beforeInsert.sql @@ -9,6 +9,7 @@ trig: BEGIN DECLARE vGroupingMode TINYINT; DECLARE vGenericFk INT; DECLARE vGenericInDate BOOL; + DECLARE vBuyerFk INT; IF @isModeInventory THEN LEAVE trig; @@ -19,7 +20,13 @@ trig: BEGIN END IF; SET NEW.editorFk = account.myUser_getId(); - SET NEW.buyerFk = NEW.editorFk; + + SELECT it.workerFk INTO vBuyerFk + FROM item i + JOIN itemType it ON it.id = i.typeFk + WHERE i.id = NEW.itemFk; + + SET NEW.buyerFk = vBuyerFk; CALL buy_checkGrouping(NEW.`grouping`); diff --git a/db/routines/vn/triggers/buy_beforeUpdate.sql b/db/routines/vn/triggers/buy_beforeUpdate.sql index b41418bcc..40e0df984 100644 --- a/db/routines/vn/triggers/buy_beforeUpdate.sql +++ b/db/routines/vn/triggers/buy_beforeUpdate.sql @@ -7,6 +7,7 @@ trig:BEGIN DECLARE vGenericInDate BOOL; DECLARE vIsInventory BOOL; DECLARE vDefaultEntry INT; + DECLARE vBuyerFk INT; IF @isTriggerDisabled THEN LEAVE trig; @@ -66,7 +67,12 @@ trig:BEGIN END IF; IF NOT (NEW.itemFk <=> OLD.itemFk) THEN - SET NEW.buyerFk = NEW.editorFk; + SELECT it.workerFk INTO vBuyerFk + FROM item i + JOIN itemType it ON it.id = i.typeFk + WHERE i.id = NEW.itemFk; + + SET NEW.buyerFk = vBuyerFk; END IF; IF NOT (NEW.itemFk <=> OLD.itemFk) OR