feat: refs #6822 poner esquemas en el with
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Robert Ferrús 2024-11-28 08:22:30 +01:00
parent be394cec28
commit 3f4aa60cd2
1 changed files with 10 additions and 10 deletions

View File

@ -75,27 +75,27 @@ BEGIN
CREATE OR REPLACE TEMPORARY TABLE tBuy
WITH tBuy AS (
SELECT b.itemFk, SUM(b.quantity) totalQuantity
FROM buy b
FROM vn.buy b
WHERE b.entryFk = vOriginalEntry
GROUP BY b.itemFk
),
itemShelvings AS (
SELECT ish.itemFk, SUM(visible) visible
FROM itemShelving ish
JOIN shelving sh ON sh.code = ish.shelvingFk
JOIN parking p ON p.id = sh.parkingFk
JOIN sector s ON s.id = p.sectorFk
FROM vn.itemShelving ish
JOIN vn.shelving sh ON sh.code = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk
JOIN vn.sector s ON s.id = p.sectorFk
WHERE s.warehouseFk = vWarehouseFk
AND sh.parked = util.VN_CURDATE()
GROUP BY ish.itemFk
),
sales AS (
SELECT s.itemFk, SUM(s.quantity) sold
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN itemShelvingSale iss ON iss.saleFk = s.id
JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk
JOIN shelving s2 ON s2.code = is2.shelvingFk
FROM vn.ticket t
JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id
JOIN vn.itemShelving is2 ON is2.id = iss.itemShelvingFk
JOIN vn.shelving s2 ON s2.code = is2.shelvingFk
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
AND s2.parked = util.VN_CURDATE()
GROUP BY s.itemFk