2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-09-19 16:03:59 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`previousSticker_get`(
|
|
|
|
vSaleGroupFk INT
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Devuelve los campos a imprimir en una etiqueta de preparación previa.
|
2024-09-19 16:03:59 +00:00
|
|
|
* Actualiza el valor de saleGroup.parkingFk en el caso de que exista un
|
2024-01-15 11:31:03 +00:00
|
|
|
* saleGroup del mismo ticket con parking, del mismo sector, para que todos se
|
|
|
|
* pongan juntos.
|
|
|
|
*
|
2024-09-19 16:03:59 +00:00
|
|
|
* @param vSaleGroupFk Identificador de saleGroup
|
2024-01-15 11:31:03 +00:00
|
|
|
*/
|
|
|
|
DECLARE vTicketFk INT;
|
|
|
|
DECLARE vParkingFk INT;
|
|
|
|
DECLARE vSectorFk INT;
|
2024-09-19 16:03:59 +00:00
|
|
|
DECLARE vPreviousLines INT;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-09-19 16:03:59 +00:00
|
|
|
SELECT s.ticketFk, COUNT(*)
|
|
|
|
INTO vTicketFk, vPreviousLines
|
|
|
|
FROM saleGroupDetail sgd
|
|
|
|
JOIN sale s ON s.id = sgd.saleFk
|
|
|
|
WHERE sgd.saleGroupFk = vSaleGroupFk;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
SELECT sg.parkingFk, sc.sectorFk
|
|
|
|
INTO vParkingFk, vSectorFk
|
2024-09-19 16:03:59 +00:00
|
|
|
FROM saleGroup sg
|
|
|
|
JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id
|
|
|
|
JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk
|
|
|
|
JOIN saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
|
|
|
|
JOIN sale s ON s.id = sgd.saleFk
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE s.ticketFk = vTicketFk
|
|
|
|
AND sg.parkingFk IS NOT NULL
|
|
|
|
LIMIT 1;
|
|
|
|
|
2024-09-19 16:03:59 +00:00
|
|
|
UPDATE saleGroup sg
|
2024-01-15 11:31:03 +00:00
|
|
|
SET sg.parkingFk = vParkingFk
|
|
|
|
WHERE sg.id = vSaleGroupFk
|
|
|
|
AND sg.sectorFk = vSectorFk;
|
|
|
|
|
|
|
|
SELECT sgd.saleGroupFk,
|
|
|
|
t.id ticketFk,
|
2024-09-19 16:03:59 +00:00
|
|
|
vPreviousLines previousLines,
|
2024-01-15 11:31:03 +00:00
|
|
|
IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour,
|
|
|
|
IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute ,
|
|
|
|
IFNULL(MAX(i.itemPackingTypeFk),'H') itemPackingTypeFk ,
|
2024-09-19 16:03:59 +00:00
|
|
|
COUNT(*) ticketLines,
|
|
|
|
p.code `location`,
|
2024-01-15 11:31:03 +00:00
|
|
|
sc.description sector
|
2024-09-19 16:03:59 +00:00
|
|
|
FROM sale s
|
|
|
|
JOIN item i ON i.id = s.itemFk
|
|
|
|
JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
|
|
|
JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
|
|
|
|
JOIN sector sc ON sc.id = sg.sectorFk
|
|
|
|
JOIN ticket t ON t.id = s.ticketFk
|
|
|
|
LEFT JOIN parking p ON p.id = sg.parkingFk
|
|
|
|
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE sgd.saleGroupFk = vSaleGroupFk;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|