Compare commits

...

1 Commits

Author SHA1 Message Date
Javi Gallego 5b482048a1 feat: refs #4560 refactor 2024-06-11 07:41:33 +02:00
1 changed files with 27 additions and 31 deletions

View File

@ -7,9 +7,9 @@ BEGIN
* en cuyo caso actualiza ese pallet. * en cuyo caso actualiza ese pallet.
* *
* @param vExpeditions JSON_ARRAY con esta estructura [exp1, exp2, exp3, ...] * @param vExpeditions JSON_ARRAY con esta estructura [exp1, exp2, exp3, ...]
* @param vArcId INT Identificador de vn.arcRead * @param vArcId INT Identificador de arcRead
* @param vWorkerFk INT Identificador de vn.worker * @param vWorkerFk INT Identificador de worker
* @param out vPalletFk Identificador de vn.expeditionPallet * @param out vPalletFk Identificador de expeditionPallet
*/ */
DECLARE vCounter INT; DECLARE vCounter INT;
DECLARE vExpeditionFk INT; DECLARE vExpeditionFk INT;
@ -23,9 +23,9 @@ BEGIN
r.id routeFk, r.id routeFk,
ep.id palletFk ep.id palletFk
FROM FROM
vn.expedition e, expedition e,
vn.route r, route r,
vn.expeditionPallet ep expeditionPallet ep
LIMIT 0; LIMIT 0;
ALTER TABLE tExpedition ADD PRIMARY KEY (expeditionFk); ALTER TABLE tExpedition ADD PRIMARY KEY (expeditionFk);
@ -39,53 +39,49 @@ BEGIN
INSERT IGNORE INTO tExpedition(expeditionFk, routeFk, palletFk) INSERT IGNORE INTO tExpedition(expeditionFk, routeFk, palletFk)
SELECT vExpeditionFk, t.routeFk, es.palletFk SELECT vExpeditionFk, t.routeFk, es.palletFk
FROM vn.expedition e FROM expedition e
LEFT JOIN vn.ticket t ON t.id = e.ticketFk LEFT JOIN ticket t ON t.id = e.ticketFk
LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id LEFT JOIN expeditionScan es ON es.expeditionFk = e.id
WHERE e.id = vExpeditionFk; WHERE e.id = vExpeditionFk;
END WHILE; END WHILE;
SELECT palletFk INTO vPalletFk SELECT palletFk
FROM ( INTO vPalletFk
SELECT palletFk, count(*) n
FROM tExpedition FROM tExpedition
WHERE palletFk > 0 WHERE palletFk > 0
GROUP BY palletFk GROUP BY palletFk
ORDER BY n DESC ORDER BY COUNT(*) DESC
LIMIT 100 ) sub
LIMIT 1; LIMIT 1;
IF vPalletFk IS NULL THEN IF vPalletFk IS NULL THEN
SELECT roadmapStopFk SELECT rm.roadmapStopFk
INTO vTruckFk INTO vTruckFk
FROM ( FROM routesMonitor rm
SELECT rm.roadmapStopFk, count(*) n
FROM vn.routesMonitor rm
JOIN tExpedition e ON e.routeFk = rm.routeFk JOIN tExpedition e ON e.routeFk = rm.routeFk
GROUP BY roadmapStopFk GROUP BY rm.roadmapStopFk
ORDER BY n DESC ORDER BY COUNT(*) DESC
LIMIT 1) sub; LIMIT 1;
IF vTruckFk IS NULL THEN IF vTruckFk IS NULL THEN
CALL util.throw ('TRUCK_NOT_AVAILABLE'); CALL util.throw ('TRUCK_NOT_AVAILABLE');
END IF; END IF;
INSERT INTO vn.expeditionPallet(truckFk) INSERT INTO expeditionPallet(truckFk)
VALUES(vTruckFk); VALUES(vTruckFk);
SET vPalletFk = LAST_INSERT_ID(); SET vPalletFk = LAST_INSERT_ID();
END IF; END IF;
INSERT INTO vn.expeditionScan(expeditionFk, palletFk, workerFk) INSERT INTO expeditionScan(expeditionFk, palletFk, workerFk)
SELECT expeditionFk, vPalletFk, vWorkerFk SELECT expeditionFk, vPalletFk, vWorkerFk
FROM tExpedition FROM tExpedition
ON DUPLICATE KEY UPDATE palletFk = vPalletFk, workerFk = vWorkerFk; ON DUPLICATE KEY UPDATE palletFk = vPalletFk, workerFk = vWorkerFk;
SELECT printerFk INTO vPrinterFk SELECT printerFk INTO vPrinterFk
FROM vn.arcRead FROM arcRead
WHERE id = vArcId; WHERE id = vArcId;
CALL vn.report_print( CALL report_print(
'LabelPalletExpedition', 'LabelPalletExpedition',
vPrinterFk, vPrinterFk,
account.myUser_getId(), account.myUser_getId(),
@ -93,7 +89,7 @@ BEGIN
'high' 'high'
); );
UPDATE vn.expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk; UPDATE expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk;
DROP TEMPORARY TABLE tExpedition; DROP TEMPORARY TABLE tExpedition;
END$$ END$$