salix/db/routines/vn/procedures/itemShelvingMatch.sql

32 lines
1.0 KiB
MySQL
Raw Permalink Normal View History

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)
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
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 ;