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

26 lines
662 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketBoxesView`(IN vTicketFk INT)
BEGIN
SELECT s.id,
s.itemFk,
s.concept,
floor(s.quantity / b.packing) as Cajas,
b.packing,
s.isPicked,
i.size
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN item i ON i.id = s.itemFk
JOIN cache.last_buy lb on lb.warehouse_id = t.warehouseFk AND lb.item_id = s.itemFk
JOIN buy b on b.id = lb.buy_id
JOIN packaging p on p.id = b.packagingFk
WHERE s.quantity >= b.packing
AND t.id = vTicketFk
AND p.isBox
GROUP BY s.itemFk;
END$$
DELIMITER ;