2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_scan`(vBarcode VARCHAR(512))
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-01-30 11:45:17 +00:00
|
|
|
* Busca transaciones a partir de un codigo de barras, las marca como escaneadas
|
2024-01-15 11:31:03 +00:00
|
|
|
* y las devuelve.
|
|
|
|
* Ver https://wiki.verdnatura.es/index.php/Ekt#Algoritmos_de_lectura
|
|
|
|
*
|
|
|
|
* @param vBarcode Código de compra de una etiqueta de subasta
|
|
|
|
* @param vLabels Cantidad escaneada
|
|
|
|
* @table tmp.ekt(ektFk) Transacciones escaneadas
|
|
|
|
*/
|
|
|
|
DECLARE vIsFound BOOL;
|
|
|
|
DECLARE vUsefulAuctionLeftSegmentLength INT;
|
|
|
|
DECLARE vStandardBarcodeLength INT;
|
|
|
|
DECLARE vFloridayBarcodeLength INT;
|
|
|
|
DECLARE vFloramondoBarcodeLength INT;
|
|
|
|
DECLARE vAuction INT;
|
|
|
|
DECLARE vKlo INT;
|
|
|
|
DECLARE vFec DATE;
|
|
|
|
DECLARE vShortAgj INT;
|
|
|
|
DECLARE vLongAgj INT;
|
|
|
|
DECLARE vXtraLongAgj INT;
|
|
|
|
DECLARE vDefaultKlo INT;
|
|
|
|
|
2024-05-21 12:40:42 +00:00
|
|
|
SELECT usefulAuctionLeftSegmentLength,
|
|
|
|
standardBarcodeLength,
|
|
|
|
floridayBarcodeLength,
|
|
|
|
floramondoBarcodeLength,
|
|
|
|
defaultKlo
|
|
|
|
INTO vUsefulAuctionLeftSegmentLength,
|
2024-01-15 11:31:03 +00:00
|
|
|
vStandardBarcodeLength,
|
|
|
|
vFloridayBarcodeLength,
|
|
|
|
vFloramondoBarcodeLength,
|
|
|
|
vDefaultKlo
|
2024-05-21 12:40:42 +00:00
|
|
|
FROM ektConfig;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-05-21 12:40:42 +00:00
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ekt
|
2024-01-15 11:31:03 +00:00
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT id ektFk FROM ekt LIMIT 0;
|
|
|
|
|
2024-05-21 12:40:42 +00:00
|
|
|
CASE
|
2024-01-15 11:31:03 +00:00
|
|
|
WHEN LENGTH(vBarcode) <= vFloridayBarcodeLength THEN
|
|
|
|
INSERT INTO tmp.ekt
|
|
|
|
SELECT id
|
2024-05-21 12:40:42 +00:00
|
|
|
FROM ektRecent e
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE e.cps = vBarcode
|
|
|
|
OR e.batchNumber = vBarcode;
|
|
|
|
|
|
|
|
WHEN LENGTH(vBarcode) = vFloramondoBarcodeLength THEN
|
|
|
|
INSERT INTO tmp.ekt
|
|
|
|
SELECT e.id
|
2024-05-21 12:40:42 +00:00
|
|
|
FROM ektRecent e
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE e.pro = MID(vBarcode,2,6)
|
2024-05-21 12:40:42 +00:00
|
|
|
AND CAST(e.ptd AS SIGNED) = MID(vBarcode, 8, 5);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
ELSE
|
2024-05-21 12:40:42 +00:00
|
|
|
SET vBarcode = LPAD(vBarcode, vStandardBarcodeLength, '0');
|
2024-01-15 11:31:03 +00:00
|
|
|
SET vAuction = MID(vBarcode, 1, 3);
|
|
|
|
SET vKlo = MID(vBarcode, 4, 2);
|
|
|
|
SET vFec = MAKEDATE(YEAR(util.VN_CURDATE()), MID(vBarcode, 6, 3));
|
|
|
|
SET vShortAgj = MID(vBarcode, 9, 5);
|
|
|
|
SET vLongAgj = MID(vBarcode, 9, 7);
|
|
|
|
SET vXtraLongAgj = MID(vBarcode, 9, 8);
|
|
|
|
|
|
|
|
-- Clásico de subasta
|
|
|
|
-- Trade standard
|
|
|
|
-- Trade que construye como la subasta
|
2024-05-21 12:40:42 +00:00
|
|
|
-- Trade como el anterior pero sin trade code
|
2024-01-15 11:31:03 +00:00
|
|
|
INSERT INTO tmp.ekt
|
|
|
|
SELECT id
|
|
|
|
FROM ekt
|
2024-01-30 09:12:27 +00:00
|
|
|
WHERE fec >= vFec - INTERVAL 1 DAY
|
2024-05-21 12:40:42 +00:00
|
|
|
AND (
|
|
|
|
(vKlo = vDefaultKlo
|
2024-01-15 11:31:03 +00:00
|
|
|
AND (klo = vKlo OR klo IS NULL OR klo = 0)
|
2024-05-21 12:40:42 +00:00
|
|
|
AND agj IN (vShortAgj, vLongAgj, vXtraLongAgj)
|
|
|
|
) OR (
|
|
|
|
klo = vKlo
|
2024-01-15 11:31:03 +00:00
|
|
|
AND auction = vAuction
|
2024-05-21 12:40:42 +00:00
|
|
|
AND agj = vShortAgj
|
|
|
|
) OR (
|
|
|
|
klo = auction -- No se si se refiere a esto
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
)
|
2024-05-21 12:40:42 +00:00
|
|
|
ORDER BY agj DESC, fec DESC
|
|
|
|
LIMIT 1;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
|
|
|
|
|
|
|
-- BatchNumber largo
|
|
|
|
IF NOT vIsFound THEN
|
|
|
|
INSERT INTO tmp.ekt
|
|
|
|
SELECT id
|
2024-05-21 12:40:42 +00:00
|
|
|
FROM ektRecent e
|
|
|
|
WHERE e.batchNumber = LEFT(
|
|
|
|
vBarcode,
|
|
|
|
vUsefulAuctionLeftSegmentLength
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
AND e.batchNumber > 0;
|
|
|
|
|
|
|
|
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
-- Order Number
|
|
|
|
IF NOT vIsFound THEN
|
|
|
|
INSERT INTO tmp.ekt
|
|
|
|
SELECT id
|
2024-05-21 12:40:42 +00:00
|
|
|
FROM ektRecent e
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE e.putOrderFk = vBarcode;
|
|
|
|
|
|
|
|
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
-- deliveryNumber incrustado
|
|
|
|
IF NOT vIsFound THEN
|
|
|
|
INSERT INTO tmp.ekt
|
|
|
|
SELECT id
|
2024-05-21 12:40:42 +00:00
|
|
|
FROM ektRecent e
|
|
|
|
WHERE e.deliveryNumber = MID(vBarcode, 4, 13)
|
2024-01-15 11:31:03 +00:00
|
|
|
AND e.deliveryNumber > 0;
|
|
|
|
|
|
|
|
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
|
|
|
END IF;
|
|
|
|
END CASE;
|
|
|
|
|
|
|
|
IF vIsFound THEN
|
|
|
|
UPDATE ekt e
|
2024-05-21 12:40:42 +00:00
|
|
|
JOIN tmp.ekt t ON t.ektFk = e.id
|
2024-01-15 11:31:03 +00:00
|
|
|
SET e.scanned = TRUE;
|
|
|
|
END IF;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|