From 4005fe906485654b9bd9d850502ba76ab4477211 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 25 Mar 2024 08:47:06 +0100 Subject: [PATCH 1/2] feat: refs #7024 Added entry_checkBooked --- db/routines/vn/functions/entry_count | 0 .../vn/procedures/entry_checkBooked.sql | 22 +++++++++++++++++++ db/routines/vn/triggers/buy_beforeDelete.sql | 1 + db/routines/vn/triggers/buy_beforeInsert.sql | 1 + db/routines/vn/triggers/buy_beforeUpdate.sql | 1 + .../vn/triggers/entry_beforeDelete.sql | 1 + .../vn/triggers/entry_beforeUpdate.sql | 4 +++- 7 files changed, 29 insertions(+), 1 deletion(-) delete mode 100644 db/routines/vn/functions/entry_count create mode 100644 db/routines/vn/procedures/entry_checkBooked.sql diff --git a/db/routines/vn/functions/entry_count b/db/routines/vn/functions/entry_count deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/routines/vn/procedures/entry_checkBooked.sql b/db/routines/vn/procedures/entry_checkBooked.sql new file mode 100644 index 000000000..50990cd43 --- /dev/null +++ b/db/routines/vn/procedures/entry_checkBooked.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_checkBooked`( + vSelf INT +) +BEGIN +/** + * Comprueba si una entrada está contabilizada, + * y si lo está retorna un throw. + * + * @param vSelf Id de entrada + */ + DECLARE vIsBooked BOOL; + + SELECT isBooked INTO vIsBooked + FROM `entry` + WHERE id = vSelf; + + IF vIsBooked THEN + CALL util.throw('Entry is already booked'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/buy_beforeDelete.sql b/db/routines/vn/triggers/buy_beforeDelete.sql index eb7c0ef70..85f1cf298 100644 --- a/db/routines/vn/triggers/buy_beforeDelete.sql +++ b/db/routines/vn/triggers/buy_beforeDelete.sql @@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_beforeDelete` BEFORE DELETE ON `buy` FOR EACH ROW BEGIN + CALL entry_checkBooked(OLD.entryFk); IF OLD.printedStickers <> 0 THEN CALL util.throw("it is not possible to delete buys with printed labels "); END IF; diff --git a/db/routines/vn/triggers/buy_beforeInsert.sql b/db/routines/vn/triggers/buy_beforeInsert.sql index a05f2810b..bc51ac852 100644 --- a/db/routines/vn/triggers/buy_beforeInsert.sql +++ b/db/routines/vn/triggers/buy_beforeInsert.sql @@ -15,6 +15,7 @@ trig: BEGIN LEAVE trig; END IF; + CALL entry_checkBooked(NEW.entryFk); IF NEW.printedStickers <> 0 THEN CALL util.throw('it is not possible to create buy lines with printedstickers other than 0'); END IF; diff --git a/db/routines/vn/triggers/buy_beforeUpdate.sql b/db/routines/vn/triggers/buy_beforeUpdate.sql index 40e0df984..2403091c6 100644 --- a/db/routines/vn/triggers/buy_beforeUpdate.sql +++ b/db/routines/vn/triggers/buy_beforeUpdate.sql @@ -13,6 +13,7 @@ trig:BEGIN LEAVE trig; END IF; + CALL entry_checkBooked(OLD.entryFk); SET NEW.editorFk = account.myUser_getId(); SELECT defaultEntry INTO vDefaultEntry diff --git a/db/routines/vn/triggers/entry_beforeDelete.sql b/db/routines/vn/triggers/entry_beforeDelete.sql index 82a3dabd5..1d2c84b9e 100644 --- a/db/routines/vn/triggers/entry_beforeDelete.sql +++ b/db/routines/vn/triggers/entry_beforeDelete.sql @@ -3,6 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_beforeDelete` BEFORE DELETE ON `entry` FOR EACH ROW BEGIN + CALL entry_checkBooked(OLD.id); DELETE FROM buy WHERE entryFk = OLD.id; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index 384feb458..d740c454c 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -7,8 +7,10 @@ BEGIN DECLARE vPrintedCount INT; DECLARE vHasDistinctWarehouses BOOL; + CALL entry_checkBooked(OLD.id); + SET NEW.editorFk = account.myUser_getId(); - + IF NOT (NEW.travelFk <=> OLD.travelFk) THEN IF NEW.travelFk IS NOT NULL AND NOT travel_hasUniqueAwb(NEW.travelFk) THEN -- 2.40.1 From 17e61b9caa8d2ade5ce342e7b6e5cd85411f83c6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 25 Mar 2024 08:50:18 +0100 Subject: [PATCH 2/2] feat: refs #7024 Minor change --- db/routines/vn/triggers/entry_beforeUpdate.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index d740c454c..8e885475f 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -8,7 +8,6 @@ BEGIN DECLARE vHasDistinctWarehouses BOOL; CALL entry_checkBooked(OLD.id); - SET NEW.editorFk = account.myUser_getId(); IF NOT (NEW.travelFk <=> OLD.travelFk) THEN -- 2.40.1