From 6845f1456ecd075625ae15db4c800d06353401a8 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 25 Jul 2024 15:03:33 +0200 Subject: [PATCH 1/6] fix: refs #7781 prevent pallet merge --- .../vn/procedures/expeditionPallet_build.sql | 71 +++++++++++-------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/db/routines/vn/procedures/expeditionPallet_build.sql b/db/routines/vn/procedures/expeditionPallet_build.sql index e917c5eb2..3e51df50c 100644 --- a/db/routines/vn/procedures/expeditionPallet_build.sql +++ b/db/routines/vn/procedures/expeditionPallet_build.sql @@ -18,9 +18,11 @@ BEGIN */ DECLARE vCounter INT; DECLARE vExpeditionFk INT; + DECLARE vExpeditionWithPallet INT; DECLARE vTruckFk INT; DECLARE vPrinterFk INT; DECLARE vExpeditionStateTypeFk INT; + DECLARE vExpeditionWithOutPallet INT; CREATE OR REPLACE TEMPORARY TABLE tExpedition ( expeditionFk INT, @@ -44,48 +46,55 @@ BEGIN WHERE e.id = vExpeditionFk; END WHILE; - SELECT palletFk INTO vPalletFk - FROM ( - SELECT palletFk, count(*) n - FROM tExpedition - WHERE palletFk > 0 - GROUP BY palletFk - ORDER BY n DESC - LIMIT 100 - ) sub - LIMIT 1; + SELECT COUNT(palletFk) INTO vExpeditionWithPallet FROM tExpedition; + SELECT GROUP_CONCAT(expeditionFk SEPARATOR ', ') INTO vExpeditionWithOutPallet + FROM tExpedition + WHERE palletFk; - IF vPalletFk IS NULL THEN - SELECT roadmapStopFk INTO vTruckFk - FROM ( - SELECT rm.roadmapStopFk, count(*) n - FROM routesMonitor rm - JOIN tExpedition e ON e.routeFk = rm.routeFk - GROUP BY roadmapStopFk - ORDER BY n DESC - LIMIT 1 - ) sub; - - IF vTruckFk IS NULL THEN - CALL util.throw ('TRUCK_NOT_AVAILABLE'); - END IF; - - INSERT INTO expeditionPallet SET truckFk = vTruckFk; - - SET vPalletFk = LAST_INSERT_ID(); + IF NOT vExpeditionWithPallet THEN + CALL util.throw ('NO_FREE_EXPEDITIONS'); END IF; + SELECT roadmapStopFk INTO vTruckFk + FROM ( + SELECT rm.roadmapStopFk, count(*) n + FROM routesMonitor rm + JOIN tExpedition e ON e.routeFk = rm.routeFk + WHERE e.palletFk IS NULL + GROUP BY roadmapStopFk + ORDER BY n DESC + LIMIT 1 + ) sub; + + IF vTruckFk IS NULL THEN + CALL util.throw ('TRUCK_NOT_AVAILABLE'); + END IF; + + INSERT INTO expeditionPallet SET truckFk = vTruckFk; + + SET vPalletFk = LAST_INSERT_ID(); + INSERT INTO expeditionScan(expeditionFk, palletFk, workerFk) SELECT expeditionFk, vPalletFk, vWorkerFk FROM tExpedition - ON DUPLICATE KEY UPDATE palletFk = vPalletFk, workerFk = vWorkerFk; + WHERE palletFk IS NULL; SELECT id INTO vExpeditionStateTypeFk FROM expeditionStateType WHERE code = 'PALLETIZED'; - + INSERT INTO expeditionState(expeditionFk, typeFk) - SELECT expeditionFk, vExpeditionStateTypeFk FROM tExpedition; + SELECT expeditionFk, vExpeditionStateTypeFk + FROM tExpedition + WHERE palletFk IS NULL; + + IF vExpeditionWithPallet THEN + UPDATE arcRead + SET error = vExpeditionWithOutPallet + WHERE id = vArcId; + ELSE + UPDATE arcRead SET error = NULL WHERE id = vArcId; + END IF; SELECT printerFk INTO vPrinterFk FROM arcRead WHERE id = vArcId; From ba494a77e6f56b9a049503a5828c8e65439c3ee0 Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 26 Jul 2024 12:39:00 +0200 Subject: [PATCH 2/6] fix: refs #7781 conditional --- db/routines/vn/procedures/expeditionPallet_build.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/expeditionPallet_build.sql b/db/routines/vn/procedures/expeditionPallet_build.sql index 3e51df50c..0e4621ca3 100644 --- a/db/routines/vn/procedures/expeditionPallet_build.sql +++ b/db/routines/vn/procedures/expeditionPallet_build.sql @@ -88,7 +88,7 @@ BEGIN FROM tExpedition WHERE palletFk IS NULL; - IF vExpeditionWithPallet THEN + IF vExpeditionWithOutPallet THEN UPDATE arcRead SET error = vExpeditionWithOutPallet WHERE id = vArcId; From 9f2057fdd085b59684b823d65e8276fc03601362 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 8 Aug 2024 12:46:10 +0200 Subject: [PATCH 3/6] fix: refs #7781 pallet merge --- .../vn/procedures/expeditionPallet_build.sql | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/db/routines/vn/procedures/expeditionPallet_build.sql b/db/routines/vn/procedures/expeditionPallet_build.sql index 0e4621ca3..8a86f70fe 100644 --- a/db/routines/vn/procedures/expeditionPallet_build.sql +++ b/db/routines/vn/procedures/expeditionPallet_build.sql @@ -6,23 +6,25 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_bu OUT vPalletFk INT ) BEGIN -/** Construye un pallet de expediciones. +/** + * Builds an expedition pallet. * - * Primero comprueba si esas expediciones ya pertenecen a otro pallet, - * en cuyo caso actualiza ese pallet. + * First, it checks if these expeditions already belong to another pallet, + * in which case it returns an error. * - * @param vExpeditions JSON_ARRAY con esta estructura [exp1, exp2, exp3, ...] - * @param vArcId INT Identificador de arcRead - * @param vWorkerFk INT Identificador de worker - * @param out vPalletFk Identificador de expeditionPallet + * @param vExpeditions JSON_ARRAY with this structure [exp1, exp2, exp3, ...] + * @param vArcId INT Identifier of arcRead + * @param vWorkerFk INT Identifier of worker + * @param out vPalletFk Identifier of expeditionPallet */ + DECLARE vCounter INT; DECLARE vExpeditionFk INT; - DECLARE vExpeditionWithPallet INT; DECLARE vTruckFk INT; DECLARE vPrinterFk INT; DECLARE vExpeditionStateTypeFk INT; - DECLARE vExpeditionWithOutPallet INT; + DECLARE vFreeExpeditionCount INT; + DECLARE vExpeditionWithPallet INT; CREATE OR REPLACE TEMPORARY TABLE tExpedition ( expeditionFk INT, @@ -46,15 +48,19 @@ BEGIN WHERE e.id = vExpeditionFk; END WHILE; - SELECT COUNT(palletFk) INTO vExpeditionWithPallet FROM tExpedition; - SELECT GROUP_CONCAT(expeditionFk SEPARATOR ', ') INTO vExpeditionWithOutPallet + SELECT COUNT(expeditionFk) INTO vFreeExpeditionCount + FROM tExpedition + WHERE palletFk IS NULL; + + SELECT GROUP_CONCAT(expeditionFk SEPARATOR ', ') INTO vExpeditionWithPallet FROM tExpedition WHERE palletFk; - IF NOT vExpeditionWithPallet THEN + IF NOT vFreeExpeditionCount THEN CALL util.throw ('NO_FREE_EXPEDITIONS'); END IF; + SELECT roadmapStopFk INTO vTruckFk FROM ( SELECT rm.roadmapStopFk, count(*) n @@ -88,9 +94,9 @@ BEGIN FROM tExpedition WHERE palletFk IS NULL; - IF vExpeditionWithOutPallet THEN + IF vExpeditionWithPallet THEN UPDATE arcRead - SET error = vExpeditionWithOutPallet + SET error = vExpeditionWithPallet WHERE id = vArcId; ELSE UPDATE arcRead SET error = NULL WHERE id = vArcId; From 225060ff7493a02e1dc3b5a53edb74f857f5b571 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 2 Sep 2024 09:24:08 +0200 Subject: [PATCH 4/6] fix: refs #7781 varible asign value --- .../vn/procedures/expeditionPallet_build.sql | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/procedures/expeditionPallet_build.sql b/db/routines/vn/procedures/expeditionPallet_build.sql index 8a86f70fe..2dbe19d14 100644 --- a/db/routines/vn/procedures/expeditionPallet_build.sql +++ b/db/routines/vn/procedures/expeditionPallet_build.sql @@ -52,7 +52,7 @@ BEGIN FROM tExpedition WHERE palletFk IS NULL; - SELECT GROUP_CONCAT(expeditionFk SEPARATOR ', ') INTO vExpeditionWithPallet + SELECT COUNT(expeditionFk) INTO vExpeditionWithPallet FROM tExpedition WHERE palletFk; @@ -60,7 +60,6 @@ BEGIN CALL util.throw ('NO_FREE_EXPEDITIONS'); END IF; - SELECT roadmapStopFk INTO vTruckFk FROM ( SELECT rm.roadmapStopFk, count(*) n @@ -91,12 +90,16 @@ BEGIN INSERT INTO expeditionState(expeditionFk, typeFk) SELECT expeditionFk, vExpeditionStateTypeFk - FROM tExpedition - WHERE palletFk IS NULL; + FROM tExpedition + WHERE palletFk IS NULL; IF vExpeditionWithPallet THEN UPDATE arcRead - SET error = vExpeditionWithPallet + SET error = ( + SELECT GROUP_CONCAT(expeditionFk SEPARATOR ', ') + FROM tExpedition + WHERE palletFk + ) WHERE id = vArcId; ELSE UPDATE arcRead SET error = NULL WHERE id = vArcId; From 09031822a67e0ff3109b320f9b6633cdc94c2e70 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 12 Sep 2024 08:24:33 +0200 Subject: [PATCH 5/6] feat: refs #7781 only print when no expedition form other pallets --- .../vn/procedures/expeditionPallet_build.sql | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/db/routines/vn/procedures/expeditionPallet_build.sql b/db/routines/vn/procedures/expeditionPallet_build.sql index 2dbe19d14..766064a5b 100644 --- a/db/routines/vn/procedures/expeditionPallet_build.sql +++ b/db/routines/vn/procedures/expeditionPallet_build.sql @@ -103,20 +103,20 @@ BEGIN WHERE id = vArcId; ELSE UPDATE arcRead SET error = NULL WHERE id = vArcId; + + SELECT printerFk INTO vPrinterFk FROM arcRead WHERE id = vArcId; + + CALL report_print( + 'LabelPalletExpedition', + vPrinterFk, + account.myUser_getId(), + JSON_OBJECT('palletFk', vPalletFk, 'userFk', account.myUser_getId()), + 'high' + ); + + UPDATE expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk; END IF; - SELECT printerFk INTO vPrinterFk FROM arcRead WHERE id = vArcId; - - CALL report_print( - 'LabelPalletExpedition', - vPrinterFk, - account.myUser_getId(), - JSON_OBJECT('palletFk', vPalletFk, 'userFk', account.myUser_getId()), - 'high' - ); - - UPDATE expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk; - DROP TEMPORARY TABLE tExpedition; END$$ DELIMITER ; From 72bab95be186b12bf2edb226a9ab6711ce68bdfc Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 4 Oct 2024 07:52:13 +0200 Subject: [PATCH 6/6] fix: refs #7781 leave early before any updates on the proc --- .../vn/procedures/expeditionPallet_build.sql | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/db/routines/vn/procedures/expeditionPallet_build.sql b/db/routines/vn/procedures/expeditionPallet_build.sql index 766064a5b..cffa42633 100644 --- a/db/routines/vn/procedures/expeditionPallet_build.sql +++ b/db/routines/vn/procedures/expeditionPallet_build.sql @@ -5,7 +5,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_bu vWorkerFk INT, OUT vPalletFk INT ) -BEGIN +proc: BEGIN /** * Builds an expedition pallet. * @@ -56,6 +56,17 @@ BEGIN FROM tExpedition WHERE palletFk; + IF vExpeditionWithPallet THEN + UPDATE arcRead + SET error = ( + SELECT GROUP_CONCAT(expeditionFk SEPARATOR ', ') + FROM tExpedition + WHERE palletFk + ) + WHERE id = vArcId; + LEAVE proc; + END IF; + IF NOT vFreeExpeditionCount THEN CALL util.throw ('NO_FREE_EXPEDITIONS'); END IF; @@ -93,29 +104,19 @@ BEGIN FROM tExpedition WHERE palletFk IS NULL; - IF vExpeditionWithPallet THEN - UPDATE arcRead - SET error = ( - SELECT GROUP_CONCAT(expeditionFk SEPARATOR ', ') - FROM tExpedition - WHERE palletFk - ) - WHERE id = vArcId; - ELSE - UPDATE arcRead SET error = NULL WHERE id = vArcId; + UPDATE arcRead SET error = NULL WHERE id = vArcId; - SELECT printerFk INTO vPrinterFk FROM arcRead WHERE id = vArcId; + SELECT printerFk INTO vPrinterFk FROM arcRead WHERE id = vArcId; - CALL report_print( - 'LabelPalletExpedition', - vPrinterFk, - account.myUser_getId(), - JSON_OBJECT('palletFk', vPalletFk, 'userFk', account.myUser_getId()), - 'high' - ); + CALL report_print( + 'LabelPalletExpedition', + vPrinterFk, + account.myUser_getId(), + JSON_OBJECT('palletFk', vPalletFk, 'userFk', account.myUser_getId()), + 'high' + ); - UPDATE expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk; - END IF; + UPDATE expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk; DROP TEMPORARY TABLE tExpedition; END$$