Merge pull request 'fix: refs #7752 add new state after scan' (!2760) from 7752-insertExpeditionState into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2760
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Pablo Natek 2024-07-19 08:35:39 +00:00
commit d0a635e86a
1 changed files with 45 additions and 43 deletions

View File

@ -1,5 +1,10 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_build`(IN vExpeditions JSON, IN vArcId INT, IN vWorkerFk INT, OUT vPalletFk INT)
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_build`(
vExpeditions JSON,
vArcId INT,
vWorkerFk INT,
OUT vPalletFk INT
)
BEGIN
/** Construye un pallet de expediciones.
*
@ -7,28 +12,22 @@ BEGIN
* en cuyo caso actualiza ese pallet.
*
* @param vExpeditions JSON_ARRAY con esta estructura [exp1, exp2, exp3, ...]
* @param vArcId INT Identificador de vn.arcRead
* @param vWorkerFk INT Identificador de vn.worker
* @param out vPalletFk Identificador de vn.expeditionPallet
* @param vArcId INT Identificador de arcRead
* @param vWorkerFk INT Identificador de worker
* @param out vPalletFk Identificador de expeditionPallet
*/
DECLARE vCounter INT;
DECLARE vExpeditionFk INT;
DECLARE vTruckFk INT;
DECLARE vPrinterFk INT;
DECLARE vExpeditionScanTypeFk INT;
DROP TEMPORARY TABLE IF EXISTS tExpedition;
CREATE TEMPORARY TABLE tExpedition
SELECT
e.id expeditionFk,
r.id routeFk,
ep.id palletFk
FROM
vn.expedition e,
vn.route r,
vn.expeditionPallet ep
LIMIT 0;
ALTER TABLE tExpedition ADD PRIMARY KEY (expeditionFk);
CREATE OR REPLACE TEMPORARY TABLE tExpedition (
expeditionFk INT,
routeFk INT,
palletFk INT,
PRIMARY KEY (expeditionFk)
);
SET vCounter = JSON_LENGTH(vExpeditions);
@ -39,9 +38,9 @@ BEGIN
INSERT IGNORE INTO tExpedition(expeditionFk, routeFk, palletFk)
SELECT vExpeditionFk, t.routeFk, es.palletFk
FROM vn.expedition e
LEFT JOIN vn.ticket t ON t.id = e.ticketFk
LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id
FROM expedition e
LEFT JOIN ticket t ON t.id = e.ticketFk
LEFT JOIN expeditionScan es ON es.expeditionFk = e.id
WHERE e.id = vExpeditionFk;
END WHILE;
@ -52,40 +51,43 @@ BEGIN
WHERE palletFk > 0
GROUP BY palletFk
ORDER BY n DESC
LIMIT 100 ) sub
LIMIT 100
) sub
LIMIT 1;
IF vPalletFk IS NULL THEN
SELECT roadmapStopFk
INTO vTruckFk
SELECT roadmapStopFk INTO vTruckFk
FROM (
SELECT rm.roadmapStopFk, count(*) n
FROM vn.routesMonitor rm
FROM routesMonitor rm
JOIN tExpedition e ON e.routeFk = rm.routeFk
GROUP BY roadmapStopFk
ORDER BY n DESC
LIMIT 1) sub;
LIMIT 1
) sub;
IF vTruckFk IS NULL THEN
CALL util.throw ('TRUCK_NOT_AVAILABLE');
END IF;
INSERT INTO vn.expeditionPallet(truckFk)
VALUES(vTruckFk);
INSERT INTO expeditionPallet SET truckFk = vTruckFk;
SET vPalletFk = LAST_INSERT_ID();
END IF;
INSERT INTO vn.expeditionScan(expeditionFk, palletFk, workerFk)
INSERT INTO expeditionScan(expeditionFk, palletFk, workerFk)
SELECT expeditionFk, vPalletFk, vWorkerFk
FROM tExpedition
ON DUPLICATE KEY UPDATE palletFk = vPalletFk, workerFk = vWorkerFk;
SELECT printerFk INTO vPrinterFk
FROM vn.arcRead
WHERE id = vArcId;
SELECT id INTO vExpeditionScanTypeFk FROM expeditionScanType WHERE code = 'PALLETIZED';
CALL vn.report_print(
INSERT INTO expeditionState(expeditionFk, typeFk)
SELECT expeditionFk, vExpeditionScanTypeFk FROM tExpedition;
SELECT printerFk INTO vPrinterFk FROM arcRead WHERE id = vArcId;
CALL report_print(
'LabelPalletExpedition',
vPrinterFk,
account.myUser_getId(),
@ -93,7 +95,7 @@ BEGIN
'high'
);
UPDATE vn.expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk;
UPDATE expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk;
DROP TEMPORARY TABLE tExpedition;
END$$