From c62e6fa0eb19b7805107086587ac554fd20673f3 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 14 Jun 2023 10:51:22 +0200 Subject: [PATCH 1/2] refs #5651 packingSiteAdvanced --- db/changes/232601/00-packingSiteAdvanced.sql | 63 +++++++++++++++++++ modules/ticket/back/model-config.json | 3 + .../back/models/packing-site-advanced.json | 18 ++++++ 3 files changed, 84 insertions(+) create mode 100644 db/changes/232601/00-packingSiteAdvanced.sql create mode 100644 modules/ticket/back/models/packing-site-advanced.json diff --git a/db/changes/232601/00-packingSiteAdvanced.sql b/db/changes/232601/00-packingSiteAdvanced.sql new file mode 100644 index 000000000..63c348fcc --- /dev/null +++ b/db/changes/232601/00-packingSiteAdvanced.sql @@ -0,0 +1,63 @@ +CREATE TABLE `vn`.`packingSiteAdvanced` ( + `ticketFk` int(11), + `workerFk` int(10) unsigned, + PRIMARY KEY (`ticketFk`), + KEY `packingSiteAdvanced_FK_1` (`workerFk`), + CONSTRAINT `packingSiteAdvanced_FK` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `packingSiteAdvanced_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('PackingSiteAdvanced', '*', '*', 'ALLOW', 'ROLE', 'production'); + +DROP PROCEDURE IF EXISTS `vn`.`packingSite_startCollection`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packingSite_startCollection`(vSelf INT, vTicketFk INT) +proc: BEGIN +/** + * @param vSelf packingSite id + * @param vTicketFk A ticket id from the collection to start + */ + DECLARE vNewCollectionFk INT; + DECLARE vIsAdvanced BOOL; + DECLARE vOldCollectionFk INT; + DECLARE vIsPackingByOther BOOL; + + SELECT COUNT(*) > 0 + INTO vIsAdvanced + FROM packingSiteAdvanced + WHERE ticketFk = vTicketFk; + + IF vIsAdvanced THEN + LEAVE proc; + END IF; + + SELECT collectionFk INTO vNewCollectionFk + FROM ticketCollection WHERE ticketFk = vTicketFk; + + SELECT collectionFk INTO vOldCollectionFk + FROM packingSite WHERE id = vSelf; + + IF NOT (vOldCollectionFk <=> vNewCollectionFk) THEN + SELECT COUNT(*) > 0 + INTO vIsPackingByOther + FROM packingSite + WHERE id <> vSelf + AND collectionFk = vOldCollectionFk; + + IF NOT vIsPackingByOther AND NOT collection_isPacked(vOldCollectionFk) AND vSelf IS NOT NULL THEN + CALL util.throw('cannotChangeCollection'); + END IF; + END IF; + + UPDATE packingSite SET collectionFk = vNewCollectionFk + WHERE id = vSelf; +END$$ +DELIMITER ; + + + diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index bee01a875..3c7e12eea 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -100,5 +100,8 @@ }, "TicketConfig": { "dataSource": "vn" + }, + "PackingSiteAdvanced": { + "dataSource": "vn" } } diff --git a/modules/ticket/back/models/packing-site-advanced.json b/modules/ticket/back/models/packing-site-advanced.json new file mode 100644 index 000000000..f48cbf412 --- /dev/null +++ b/modules/ticket/back/models/packing-site-advanced.json @@ -0,0 +1,18 @@ +{ + "name": "PackingSiteAdvanced", + "base": "VnModel", + "options": { + "mysql": { + "table": "packingSiteAdvanced" + } + }, + "properties": { + "ticketFk": { + "id": true, + "type": "number" + }, + "workerFk": { + "type": "number" + } + } +} -- 2.40.1 From 927c0fddc6231075f15209b83291726ee6468b6d Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 14 Jun 2023 13:15:37 +0200 Subject: [PATCH 2/2] refs #5651 --- db/changes/232601/00-packingSiteAdvanced.sql | 64 +++++++++++--------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/db/changes/232601/00-packingSiteAdvanced.sql b/db/changes/232601/00-packingSiteAdvanced.sql index 63c348fcc..0e33744cd 100644 --- a/db/changes/232601/00-packingSiteAdvanced.sql +++ b/db/changes/232601/00-packingSiteAdvanced.sql @@ -12,7 +12,7 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `pri VALUES ('PackingSiteAdvanced', '*', '*', 'ALLOW', 'ROLE', 'production'); -DROP PROCEDURE IF EXISTS `vn`.`packingSite_startCollection`; + DROP PROCEDURE IF EXISTS `vn`.`packingSite_startCollection`; DELIMITER $$ $$ @@ -22,40 +22,48 @@ proc: BEGIN * @param vSelf packingSite id * @param vTicketFk A ticket id from the collection to start */ - DECLARE vNewCollectionFk INT; - DECLARE vIsAdvanced BOOL; - DECLARE vOldCollectionFk INT; - DECLARE vIsPackingByOther BOOL; + DECLARE vExists BOOL; + DECLARE vIsAdvanced BOOL; + DECLARE vNewCollectionFk INT; + DECLARE vOldCollectionFk INT; + DECLARE vIsPackingByOther BOOL; - SELECT COUNT(*) > 0 - INTO vIsAdvanced - FROM packingSiteAdvanced - WHERE ticketFk = vTicketFk; + SELECT id, collectionFk + INTO vExists, vOldCollectionFk + FROM packingSite + WHERE id = vSelf; - IF vIsAdvanced THEN - LEAVE proc; - END IF; + IF NOT vExists THEN + CALL util.throw('packingSiteNotExists'); + END IF; - SELECT collectionFk INTO vNewCollectionFk - FROM ticketCollection WHERE ticketFk = vTicketFk; + SELECT COUNT(*) > 0 + INTO vIsAdvanced + FROM packingSiteAdvanced + WHERE ticketFk = vTicketFk; - SELECT collectionFk INTO vOldCollectionFk - FROM packingSite WHERE id = vSelf; + IF vIsAdvanced THEN + LEAVE proc; + END IF; - IF NOT (vOldCollectionFk <=> vNewCollectionFk) THEN - SELECT COUNT(*) > 0 - INTO vIsPackingByOther - FROM packingSite - WHERE id <> vSelf - AND collectionFk = vOldCollectionFk; + SELECT collectionFk INTO vNewCollectionFk + FROM ticketCollection WHERE ticketFk = vTicketFk; - IF NOT vIsPackingByOther AND NOT collection_isPacked(vOldCollectionFk) AND vSelf IS NOT NULL THEN - CALL util.throw('cannotChangeCollection'); - END IF; - END IF; + IF vOldCollectionFk IS NOT NULL + AND vOldCollectionFk <> vNewCollectionFk THEN + SELECT COUNT(*) > 0 + INTO vIsPackingByOther + FROM packingSite + WHERE id <> vSelf + AND collectionFk = vOldCollectionFk; - UPDATE packingSite SET collectionFk = vNewCollectionFk - WHERE id = vSelf; + IF NOT vIsPackingByOther AND NOT collection_isPacked(vOldCollectionFk) THEN + CALL util.throw('cannotChangeCollection'); + END IF; + END IF; + + UPDATE packingSite SET collectionFk = vNewCollectionFk + WHERE id = vSelf; END$$ DELIMITER ; -- 2.40.1