feat: refs #6453 Added new ticket search
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Guillermo Bonet 2024-07-29 11:46:59 +02:00
parent 578de51f7e
commit 4c602800ea
1 changed files with 33 additions and 2 deletions

View File

@ -123,14 +123,14 @@ BEGIN
LEAVE lDates; LEAVE lDates;
END IF; END IF;
-- Busca un ticket existente que coincida con los parametros -- Busca un ticket libre disponible
WITH tPrevia AS ( WITH tPrevia AS (
SELECT DISTINCT s.ticketFk SELECT DISTINCT s.ticketFk
FROM vn.sale s FROM vn.sale s
JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.ticket t ON t.id = s.ticketFk
WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment)
) ),
SELECT t.id INTO vTicketFk SELECT t.id INTO vTicketFk
FROM vn.ticket t FROM vn.ticket t
JOIN vn.alertLevel al ON al.code = 'FREE' JOIN vn.alertLevel al ON al.code = 'FREE'
@ -146,6 +146,37 @@ BEGIN
AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id) AND (tls.alertLevel IS NULL OR tls.alertLevel = al.id)
LIMIT 1; LIMIT 1;
-- Comprobamos si hay un ticket de previa disponible
IF vTicketFk IS NULL THEN
WITH tItemPackingTypeOrder AS (
SELECT GROUP_CONCAT(DISTINCT i.itemPackingTypeFk) distinctItemPackingTypes,
o.address_id
FROM vn.item i
JOIN orderRow oro ON oro.itemFk = i.id
JOIN `order` o ON o.id = oro.orderFk
WHERE oro.orderFk = vSelf
),
tItemPackingTypeTicket AS (
SELECT t.id,
GROUP_CONCAT(DISTINCT i.itemPackingTypeFk) distinctItemPackingTypes
FROM vn.ticket t
JOIN vn.alertLevel al ON al.code = 'ON_PREVIOUS'
JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.item i ON i.id = s.itemFk
JOIN tItemPackingTypeOrder ipto
WHERE t.refFk IS NULL
AND DATE(t.shipped) = vShipment
AND t.warehouseFk = vWarehouseFk
AND t.addressFk = ipto.address_id
GROUP BY t.id
)
SELECT iptt.id INTO vTicketFk
FROM tItemPackingTypeTicket iptt
JOIN tItemPackingTypeOrder ipto
WHERE INSTR(iptt.distinctItemPackingTypes, ipto.distinctItemPackingTypes)
LIMIT 1
END IF;
-- Crea el ticket en el caso de no existir uno adecuado -- Crea el ticket en el caso de no existir uno adecuado
IF vTicketFk IS NULL THEN IF vTicketFk IS NULL THEN
SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); SET vShipment = IFNULL(vShipment, util.VN_CURDATE());