fix: getSimilar daysInforward

This commit is contained in:
Javi Gallego 2024-10-01 12:19:51 +02:00
parent 36e1cfd51a
commit 6685ade299
1 changed files with 31 additions and 31 deletions

View File

@ -1,10 +1,10 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_getSimilar`(
vSelf INT,
vWarehouseFk INT,
vDated DATE,
vShowType BOOL,
vDaysInForward INT
vSelf INT,
vWarehouseFk INT,
vDated DATE,
vShowType BOOL,
vDaysInForward INT
)
BEGIN
/**
@ -17,48 +17,48 @@ BEGIN
* @param vShowType Mostrar tipos
* @param vDaysInForward Días de alcance para las ventas
*/
DECLARE vAvailableCalcFk INT;
DECLARE vPriority INT DEFAULT 1;
DECLARE vAvailableCalcFk INT;
DECLARE vPriority INT DEFAULT 1;
CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated);
CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated);
WITH itemTags AS (
SELECT i.id,
typeFk,
tag5,
value5,
tag6,
value6,
tag7,
value7,
tag8,
value8,
t.name,
it.value
WITH itemTags AS (
SELECT i.id,
typeFk,
tag5,
value5,
tag6,
value6,
tag7,
value7,
tag8,
value8,
t.name,
it.value
FROM vn.item i
LEFT JOIN vn.itemTag it ON it.itemFk = i.id
AND it.priority = vPriority
LEFT JOIN vn.tag t ON t.id = it.tagFk
WHERE i.id = vSelf
),
stock AS (
SELECT itemFk, SUM(visible) stock
),
stock AS (
SELECT itemFk, SUM(visible) stock
FROM vn.itemShelvingStock
WHERE warehouseFk = vWarehouseFk
GROUP BY itemFk
),
sold AS (
SELECT SUM(s.quantity) quantity, s.itemFk
),
sold AS (
SELECT SUM(s.quantity) quantity, s.itemFk
FROM vn.sale s
JOIN vn.ticket t ON t.id = s.ticketFk
LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id
WHERE t.shipped BETWEEN CURDATE() AND CURDATE() + INTERVAL vDaysInForward DAY
WHERE t.shipped >= CURDATE() + INTERVAL vDaysInForward DAY
AND iss.saleFk IS NULL
AND t.warehouseFk = vWarehouseFk
GROUP BY s.itemFk
)
SELECT i.id itemFk,
CAST(sd.quantity AS INT) advanceable,
)
SELECT i.id itemFk,
LEAST(CAST(sd.quantity AS INT), sk.stock) advanceable,
i.longName,
i.subName,
i.tag5,