2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingMatch`(vEntryFk INT, vAllTravel BOOLEAN, vFromTimed DATETIME, vToTimed DATETIME)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
|
|
|
|
DECLARE vTravelFk INT;
|
|
|
|
|
|
|
|
SELECT travelFk INTO vTravelFk
|
|
|
|
FROM entry
|
|
|
|
WHERE id = vEntryFk;
|
|
|
|
|
|
|
|
SELECT i.id, i.longName, i.size, i.subName, b.stickers, ish.etiquetas, b.printed
|
|
|
|
FROM item i
|
|
|
|
JOIN (
|
|
|
|
SELECT itemFk, sum(stickers) AS stickers, sum(printedStickers) as printed
|
|
|
|
FROM buy b
|
|
|
|
JOIN entry e ON e.id = b.entryFk
|
|
|
|
WHERE IF(vAllTravel , travelFk = vTravelFk, b.entryFk = vEntryFk)
|
|
|
|
GROUP BY itemFk
|
|
|
|
) b ON b.itemFk = i.id
|
|
|
|
LEFT JOIN (
|
|
|
|
SELECT itemFk, sum(cast(visible / packing AS DECIMAL(10,0))) AS etiquetas
|
|
|
|
FROM itemShelving ish
|
2024-11-13 08:03:44 +00:00
|
|
|
JOIN shelving sh ON sh.id = ish.shelvingFk
|
2024-01-15 11:31:03 +00:00
|
|
|
LEFT JOIN parking pk ON pk.id = sh.parkingFk
|
|
|
|
WHERE ish.created BETWEEN vFromTimed AND vToTimed
|
|
|
|
GROUP BY itemFk
|
|
|
|
) ish ON ish.itemFk = id
|
|
|
|
WHERE b.stickers OR ish.etiquetas;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|