refactor: refs #7505 item_getVisible refactor #2573
|
@ -20,11 +20,12 @@ proc: BEGIN
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible
|
||||||
(PRIMARY KEY (item_id))
|
(PRIMARY KEY (item_id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT item_id, amount stock, amount visible FROM `cache`.stock
|
SELECT item_id, amount stock, amount visible
|
||||||
|
FROM `cache`.stock
|
||||||
WHERE warehouse_id = v_warehouse;
|
WHERE warehouse_id = v_warehouse;
|
||||||
|
|
||||||
-- Calculamos los movimientos confirmados de hoy
|
-- Calculamos los movimientos confirmados de hoy
|
||||||
CALL vn.item_GetVisible(v_warehouse, NULL);
|
CALL vn.item_getVisible(v_warehouse, util.VN_CURDATE(), NULL);
|
||||||
DELETE FROM visible WHERE calc_id = v_calc;
|
DELETE FROM visible WHERE calc_id = v_calc;
|
||||||
|
|
||||||
INSERT INTO visible (calc_id, item_id,visible)
|
INSERT INTO visible (calc_id, item_id,visible)
|
||||||
guillermo marked this conversation as resolved
|
|||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_GetVisible`(vWarehouse SMALLINT, vItem INT)
|
|
||||||
BEGIN
|
|
||||||
DECLARE vTomorrow DATETIME DEFAULT TIMESTAMPADD(DAY, 1, util.VN_CURDATE());
|
|
||||||
|
|
||||||
INSERT INTO tmp.itemVisible (item_id, visible)
|
|
||||||
SELECT item_id, SUM(amount) amount
|
|
||||||
FROM (
|
|
||||||
SELECT i.itemFk AS item_id, quantity AS amount
|
|
||||||
FROM itemTicketOut i
|
|
||||||
LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk
|
|
||||||
JOIN state s ON s.id = ts.stateFk
|
|
||||||
LEFT JOIN (SELECT DISTINCT saleFk
|
|
||||||
FROM saleTracking st
|
|
||||||
JOIN state s ON s.id = st.stateFk
|
|
||||||
WHERE st.created > util.VN_CURDATE()
|
|
||||||
AND (s.isPicked OR st.isChecked)
|
|
||||||
) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
|
|
||||||
WHERE i.warehouseFk = vWarehouse
|
|
||||||
AND (vItem IS NULL OR i.itemFk = vItem)
|
|
||||||
AND (s.isPicked OR i.reserved OR stPrevious.saleFk )
|
|
||||||
AND i.shipped >= util.VN_CURDATE() AND i.shipped < vTomorrow
|
|
||||||
UNION ALL
|
|
||||||
SELECT iei.itemFk, quantity
|
|
||||||
FROM itemEntryIn iei
|
|
||||||
WHERE (iei.isReceived != FALSE /*OR ip.modificationDate > util.VN_CURDATE()*/)
|
|
||||||
AND iei.landed >= util.VN_CURDATE() AND iei.landed < vTomorrow
|
|
||||||
AND iei.warehouseInFk = vWarehouse
|
|
||||||
AND (vItem IS NULL OR iei.itemFk = vItem)
|
|
||||||
AND iei.isVirtualStock is FALSE
|
|
||||||
UNION ALL
|
|
||||||
SELECT itemFk, quantity
|
|
||||||
FROM itemEntryOut
|
|
||||||
WHERE isDelivered != FALSE
|
|
||||||
AND shipped >= util.VN_CURDATE() AND shipped < vTomorrow
|
|
||||||
AND warehouseOutFk = vWarehouse
|
|
||||||
AND (vItem IS NULL OR itemFk = vItem)
|
|
||||||
) t
|
|
||||||
GROUP BY item_id
|
|
||||||
ON DUPLICATE KEY UPDATE
|
|
||||||
visible = IFNULL(stock,0) + VALUES(visible);
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`(
|
||||||
|
vWarehouseFk INT,
|
||||||
|
vDated INT,
|
||||||
|
vItemFk INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY;
|
||||||
|
|
||||||
|
INSERT INTO tmp.itemVisible (item_id, visible)
|
||||||
|
SELECT itemFk, SUM(quantity)
|
||||||
|
FROM (
|
||||||
|
SELECT i.itemFk, i.quantity
|
||||||
|
FROM itemTicketOut i
|
||||||
|
LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk
|
||||||
|
JOIN `state` s ON s.id = ts.stateFk
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT st.saleFk
|
||||||
|
FROM saleTracking st
|
||||||
|
JOIN state s ON s.id = st.stateFk
|
||||||
|
WHERE st.created > vDated
|
||||||
|
AND (s.isPicked OR st.isChecked)
|
||||||
|
) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
|
||||||
|
WHERE i.warehouseFk = vWarehouseFk
|
||||||
|
AND (vItemFk IS NULL OR i.itemFk = vItemFk)
|
||||||
|
AND (s.isPicked OR i.reserved OR stPrevious.saleFk)
|
||||||
|
AND i.shipped >= vDated AND i.shipped < vTomorrow
|
||||||
|
UNION ALL
|
||||||
|
SELECT itemFk, quantity
|
||||||
|
FROM itemEntryIn
|
||||||
|
WHERE isReceived
|
||||||
|
AND landed >= vDated AND landed < vTomorrow
|
||||||
|
AND warehouseInFk = vWarehouseFk
|
||||||
|
AND (vItemFk IS NULL OR itemFk = vItemFk)
|
||||||
|
AND NOT isVirtualStock
|
||||||
|
UNION ALL
|
||||||
|
SELECT itemFk, quantity
|
||||||
|
FROM itemEntryOut
|
||||||
|
WHERE isDelivered
|
||||||
|
AND shipped >= vDated
|
||||||
|
AND shipped < vTomorrow
|
||||||
|
AND warehouseOutFk = vWarehouseFk
|
||||||
|
AND (vItemFk IS NULL OR itemFk = vItemFk)
|
||||||
|
) t
|
||||||
|
GROUP BY itemFk
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
visible = IFNULL(stock, 0) + VALUES(visible);
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -1,9 +1,9 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventory`(
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventory`(
|
||||||
vDate DATE,
|
vDate DATE,
|
||||||
vWarehouseFk TINYINT,
|
vWarehouseFk TINYINT,
|
||||||
vMaxDays TINYINT
|
vMaxDays TINYINT
|
||||||
)
|
)
|
||||||
proc: BEGIN
|
proc: BEGIN
|
||||||
DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY;
|
DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY;
|
||||||
DECLARE vDateFrom DATE DEFAULT vDate;
|
DECLARE vDateFrom DATE DEFAULT vDate;
|
||||||
|
@ -78,47 +78,18 @@ proc: BEGIN
|
||||||
ai.sd = sub.Subtotal;
|
ai.sd = sub.Subtotal;
|
||||||
|
|
||||||
-- Cálculo del visible
|
-- Cálculo del visible
|
||||||
UPDATE tmp.itemInventory ai
|
CALL `cache`.stock_refresh(false);
|
||||||
JOIN (
|
|
||||||
SELECT itemFk Id_Article, SUM(quantity) Subtotal
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible
|
||||||
FROM (
|
(PRIMARY KEY (item_id))
|
||||||
SELECT s.itemFk, s.quantity
|
ENGINE = MEMORY
|
||||||
FROM sale s
|
SELECT item_id, amount stock, amount visible FROM `cache`.stock
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
WHERE warehouse_id = vWarehouseFk;
|
||||||
JOIN warehouse w ON w.id = t.warehouseFk
|
|
||||||
WHERE t.shipped >= vDate
|
CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL);
|
||||||
AND t.shipped < vDateTomorrow
|
UPDATE tmp.itemInventory it
|
||||||
AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
|
JOIN tmp.itemVisible iv ON iv.item_id = it.id
|
||||||
AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
|
SET it.visible = iv.visible;
|
||||||
AND w.isComparative
|
|
||||||
UNION ALL
|
|
||||||
SELECT b.itemFk, - b.quantity
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
JOIN warehouse w ON w.id = t.warehouseInFk
|
|
||||||
WHERE t.landed = vDate
|
|
||||||
AND NOT t.isReceived
|
|
||||||
AND NOT e.isExcludedFromAvailable
|
|
||||||
AND NOT e.isRaid
|
|
||||||
AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
|
|
||||||
AND w.isComparative
|
|
||||||
UNION ALL
|
|
||||||
SELECT b.itemFk, b.quantity
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
JOIN warehouse w ON w.id = t.warehouseOutFk
|
|
||||||
WHERE t.shipped = vDate
|
|
||||||
AND NOT t.isReceived
|
|
||||||
AND NOT e.isExcludedFromAvailable
|
|
||||||
AND NOT e.isRaid
|
|
||||||
AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
|
|
||||||
AND w.isComparative
|
|
||||||
) sub2
|
|
||||||
GROUP BY itemFk
|
|
||||||
) sub ON ai.id = sub.Id_Article
|
|
||||||
SET ai.visible = ai.visible + sub.Subtotal;
|
|
||||||
|
|
||||||
-- Calculo del disponible
|
-- Calculo del disponible
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
|
||||||
|
@ -189,6 +160,7 @@ proc: BEGIN
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
||||||
tmp.itemTravel,
|
tmp.itemTravel,
|
||||||
tmp.itemCalc,
|
tmp.itemCalc,
|
||||||
tmp.itemAtp;
|
tmp.itemAtp,
|
||||||
END$$
|
tmp.itemVisible;
|
||||||
DELIMITER ;
|
END$$
|
||||||
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue
el visible no es guarda per dia, no es pot calcular per dia. Tampoc aporta res. El concepte "visible per dia" seria l'stock .