2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-11-13 08:56:38 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`shelvingParking_get`(
|
|
|
|
vShelvingCode VARCHAR(10),
|
|
|
|
vWarehouseFk INT,
|
|
|
|
vDayRange INT
|
|
|
|
)
|
|
|
|
BEGIN
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT s.itemFk,
|
|
|
|
s.concept,
|
|
|
|
CAST(SUM(s.quantity) AS DECIMAL(10,0)) as sinServir,
|
|
|
|
CAST(IFNULL(ist.visible,0) AS DECIMAL(10,0)) as aparcado
|
|
|
|
FROM vn.sale s
|
|
|
|
LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id
|
|
|
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
2024-11-13 08:56:38 +00:00
|
|
|
LEFT JOIN vn.itemShelvingStock ist ON ist.itemFk = s.itemFk
|
|
|
|
AND ist.warehouseFk = vWarehouseFk
|
|
|
|
JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk
|
|
|
|
JOIN shelving sh ON sh.id = ish.shelvingFk
|
|
|
|
AND sh.code = vShelvingCode COLLATE utf8_general_ci
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE()))
|
|
|
|
AND iss.saleFk IS NULL
|
|
|
|
AND t.warehouseFk = vWarehouseFk
|
|
|
|
GROUP BY s.itemFk
|
|
|
|
HAVING sinServir > aparcado;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|