From 4fc43df11bd9f210be9222e2cdb835472ce11f17 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 9 Aug 2024 11:28:30 +0200 Subject: [PATCH 1/3] feat: refs #6650 new itemShelvingLog --- ...mShelving _afterDelete.sql => itemShelving_afterDelete.sql} | 2 +- db/versions/11183-limePhormium/00-firstScript.sql | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) rename db/routines/vn/triggers/{itemShelving _afterDelete.sql => itemShelving_afterDelete.sql} (88%) create mode 100644 db/versions/11183-limePhormium/00-firstScript.sql diff --git a/db/routines/vn/triggers/itemShelving _afterDelete.sql b/db/routines/vn/triggers/itemShelving_afterDelete.sql similarity index 88% rename from db/routines/vn/triggers/itemShelving _afterDelete.sql rename to db/routines/vn/triggers/itemShelving_afterDelete.sql index 9a1759eff..449ad5530 100644 --- a/db/routines/vn/triggers/itemShelving _afterDelete.sql +++ b/db/routines/vn/triggers/itemShelving_afterDelete.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterDel BEGIN INSERT INTO shelvingLog SET `action` = 'delete', - `changedModel` = 'itemShelving', + `changedModel` = 'ItemShelving', `changedModelId` = OLD.id, `userFk` = account.myUser_getId(); END$$ diff --git a/db/versions/11183-limePhormium/00-firstScript.sql b/db/versions/11183-limePhormium/00-firstScript.sql new file mode 100644 index 000000000..d6d1fc271 --- /dev/null +++ b/db/versions/11183-limePhormium/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.shelvingLog MODIFY + COLUMN changedModel enum('Shelving', 'ItemShelving') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Shelving' NOT NULL; +ALTER TABLE vn.shelvingLog MODIFY COLUMN originFk varchar(11) DEFAULT NULL NULL; From b436ac051833540353aedc5d604dbbc5d89b56f4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 3 Sep 2024 07:45:25 +0200 Subject: [PATCH 2/3] fix: refs #7916 itemShelving_transfer --- .../vn/procedures/itemShelving_transfer.sql | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_transfer.sql b/db/routines/vn/procedures/itemShelving_transfer.sql index 47a9a7cf0..94d2308a1 100644 --- a/db/routines/vn/procedures/itemShelving_transfer.sql +++ b/db/routines/vn/procedures/itemShelving_transfer.sql @@ -5,28 +5,26 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_transf ) BEGIN /** - * Transfiere producto de una ubicaciĆ³n a otra, fusionando si coincide el - * packing y la fecha. + * Transfiere producto de una ubicaciĆ³n a otra + * fusionando si coincide el packing y la fecha. * * @param vItemShelvingFk Identificador de itemShelving * @param vShelvingFk Identificador de shelving */ - DECLARE vNewItemShelvingFk INT DEFAULT 0; + DECLARE vNewItemShelvingFk INT; - SELECT MAX(ish.id) - INTO vNewItemShelvingFk + SELECT MAX(ish.id) INTO vNewItemShelvingFk FROM itemShelving ish JOIN ( - SELECT - itemFk, - packing, - created, - buyFk + SELECT itemFk, + packing, + created, + buyFk FROM itemShelving WHERE id = vItemShelvingFk ) ish2 ON ish2.itemFk = ish.itemFk AND ish2.packing = ish.packing - AND date(ish2.created) = date(ish.created) + AND DATE(ish2.created) = DATE(ish.created) AND ish2.buyFk = ish.buyFk WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci; @@ -39,10 +37,16 @@ BEGIN DELETE FROM itemShelving WHERE id = vItemShelvingFk; ELSE - UPDATE itemShelving - SET shelvingFk = vShelvingFk - WHERE id = vItemShelvingFk; + IF (SELECT EXISTS(SELECT id FROM shelving + WHERE code = vShelvingFk COLLATE utf8_unicode_ci)) THEN + + UPDATE itemShelving + SET shelvingFk = vShelvingFk + WHERE id = vItemShelvingFk; + ELSE + CALL util.throw('The shelving not exists'); + END IF; END IF; - SELECT true; + SELECT TRUE; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; From 6b53c24f20d1b157cb18bce9a91d2614c4af7c78 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 3 Sep 2024 08:17:27 +0200 Subject: [PATCH 3/3] feat: refs #6650 Added saleGroupLog --- .../saleGroupDetail._beforeInsert.sql | 8 ++++++ .../triggers/saleGroupDetail_afterDelete.sql | 12 +++++++++ .../triggers/saleGroupDetail_beforeUpdate.sql | 8 ++++++ .../vn/triggers/saleGroup_afterDelete.sql | 2 +- .../11183-limePhormium/00-firstScript.sql | 26 ++++++++++++++++--- 5 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 db/routines/vn/triggers/saleGroupDetail._beforeInsert.sql create mode 100644 db/routines/vn/triggers/saleGroupDetail_afterDelete.sql create mode 100644 db/routines/vn/triggers/saleGroupDetail_beforeUpdate.sql diff --git a/db/routines/vn/triggers/saleGroupDetail._beforeInsert.sql b/db/routines/vn/triggers/saleGroupDetail._beforeInsert.sql new file mode 100644 index 000000000..9513be46a --- /dev/null +++ b/db/routines/vn/triggers/saleGroupDetail._beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroupDetail_beforeInsert` + BEFORE INSERT ON `saleGroupDetail` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/saleGroupDetail_afterDelete.sql b/db/routines/vn/triggers/saleGroupDetail_afterDelete.sql new file mode 100644 index 000000000..1698ad8ce --- /dev/null +++ b/db/routines/vn/triggers/saleGroupDetail_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroupDetail_afterDelete` + AFTER DELETE ON `saleGroupDetail` + FOR EACH ROW +BEGIN + INSERT INTO saleGroupLog + SET `action` = 'delete', + `changedModel` = 'SaleGroupDetail', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/saleGroupDetail_beforeUpdate.sql b/db/routines/vn/triggers/saleGroupDetail_beforeUpdate.sql new file mode 100644 index 000000000..0da18fd98 --- /dev/null +++ b/db/routines/vn/triggers/saleGroupDetail_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroupDetail_beforeUpdate` + BEFORE UPDATE ON `saleGroupDetail` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/saleGroup_afterDelete.sql b/db/routines/vn/triggers/saleGroup_afterDelete.sql index 1e0163187..7ba34c6ce 100644 --- a/db/routines/vn/triggers/saleGroup_afterDelete.sql +++ b/db/routines/vn/triggers/saleGroup_afterDelete.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroup_afterDelete AFTER DELETE ON `saleGroup` FOR EACH ROW BEGIN - INSERT INTO ticketLog + INSERT INTO saleGroupLog SET `action` = 'delete', `changedModel` = 'SaleGroup', `changedModelId` = OLD.id, diff --git a/db/versions/11183-limePhormium/00-firstScript.sql b/db/versions/11183-limePhormium/00-firstScript.sql index d6d1fc271..a30338f9e 100644 --- a/db/versions/11183-limePhormium/00-firstScript.sql +++ b/db/versions/11183-limePhormium/00-firstScript.sql @@ -1,3 +1,23 @@ -ALTER TABLE vn.shelvingLog MODIFY - COLUMN changedModel enum('Shelving', 'ItemShelving') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Shelving' NOT NULL; -ALTER TABLE vn.shelvingLog MODIFY COLUMN originFk varchar(11) DEFAULT NULL NULL; +CREATE OR REPLACE TABLE `vn`.`saleGroupLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete','select') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('SaleGroup', 'SaleGroupDetail') NOT NULL DEFAULT 'SaleGroup', + `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), + `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), + `changedModelId` int(11) NOT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + `summaryId` varchar(30) DEFAULT NULL, + `reason` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `saleGroupUserFk` (`userFk`), + KEY `saleGroupLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `saleGroupLog_originFk` (`originFk`,`creationDate`), + CONSTRAINT `saleGroupLogUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE vn.parkingLog + MODIFY COLUMN changedModel enum('Parking') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Parking' NOT NULL;