From 4005fe906485654b9bd9d850502ba76ab4477211 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 25 Mar 2024 08:47:06 +0100 Subject: [PATCH 1/4] 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 From 17e61b9caa8d2ade5ce342e7b6e5cd85411f83c6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 25 Mar 2024 08:50:18 +0100 Subject: [PATCH 2/4] 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 From df115ec58bcfe81a6fa32e8cadcbdd2ceb144da0 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 25 Mar 2024 09:41:05 +0100 Subject: [PATCH 3/4] refactor: refs #6880 vn.professionalCategory changes --- db/dump/fixtures.before.sql | 6 +++--- db/routines/vn/views/salesPersonSince.sql | 2 +- db/versions/10968-salmonBamboo/00-firstScript.sql | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 db/versions/10968-salmonBamboo/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 4e01532e2..1ac832ba9 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1980,10 +1980,10 @@ INSERT INTO `pbx`.`sip`(`user_id`, `extension`) (5, 1102), (9, 1201); -INSERT INTO `vn`.`professionalCategory` (`id`, `name`, `level`, `dayBreak`) +INSERT INTO `vn`.`professionalCategory` (`id`, `description`) VALUES - (1, 'employee', NULL, NULL), - (2, 'florist', NULL, NULL); + (1, 'employee'), + (2, 'florist'); INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) VALUES diff --git a/db/routines/vn/views/salesPersonSince.sql b/db/routines/vn/views/salesPersonSince.sql index 43c45adc0..4234ecac4 100644 --- a/db/routines/vn/views/salesPersonSince.sql +++ b/db/routines/vn/views/salesPersonSince.sql @@ -12,5 +12,5 @@ FROM ( `pc`.`id` = `b`.`workerBusinessProfessionalCategoryFk` ) ) -WHERE `pc`.`name` = 'Aux ventas' +WHERE `pc`.`description` = 'Aux ventas' GROUP BY `b`.`workerFk` diff --git a/db/versions/10968-salmonBamboo/00-firstScript.sql b/db/versions/10968-salmonBamboo/00-firstScript.sql new file mode 100644 index 000000000..b79201071 --- /dev/null +++ b/db/versions/10968-salmonBamboo/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.professionalCategory DROP COLUMN dayBreak, DROP COLUMN `level`; +ALTER TABLE vn.professionalCategory + CHANGE name description varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; From bde8742147a99cb40f2be9efa7873e21d6d5a114 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 25 Mar 2024 12:51:47 +0100 Subject: [PATCH 4/4] fix: refs #7024 entry_checkBooked --- db/routines/vn/triggers/entry_beforeUpdate.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index 8e885475f..98ebe1364 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -6,8 +6,11 @@ BEGIN DECLARE vIsVirtual BOOL; DECLARE vPrintedCount INT; DECLARE vHasDistinctWarehouses BOOL; + + IF NEW.isBooked = OLD.isBooked THEN + CALL entry_checkBooked(OLD.id); + END IF; - CALL entry_checkBooked(OLD.id); SET NEW.editorFk = account.myUser_getId(); IF NOT (NEW.travelFk <=> OLD.travelFk) THEN