This commit is contained in:
parent
c9e9d95cff
commit
7279feab12
|
@ -25,7 +25,7 @@ proc: BEGIN
|
||||||
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_calcVisible(v_warehouse, util.VN_CURDATE(), NULL);
|
CALL vn.item_calcVisible(NULL, util.VN_CURDATE(), v_warehouse);
|
||||||
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)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`(
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`(
|
||||||
vWarehouseFk INT,
|
vSelf INT,
|
||||||
vDated INT,
|
vDated DATE,
|
||||||
vItemFk INT
|
vWarehouseFk INT
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
|
@ -10,12 +10,12 @@ BEGIN
|
||||||
*
|
*
|
||||||
* @param vWarehouse Warehouse id
|
* @param vWarehouse Warehouse id
|
||||||
* @param vDated Max date to filter
|
* @param vDated Max date to filter
|
||||||
* @param vItemFk Item id
|
* @param vSelf Item id
|
||||||
* @param tmp.itemVisible(item_id, stock, visible)
|
* @param tmp.itemVisible(item_id, stock, visible)
|
||||||
*/
|
*/
|
||||||
DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY;
|
DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY;
|
||||||
|
|
||||||
INSERT INTO tmp.itemVisible (item_id, visible)
|
INSERT INTO tmp.itemVisible(item_id, visible)
|
||||||
SELECT itemFk, SUM(quantity)
|
SELECT itemFk, SUM(quantity)
|
||||||
FROM (
|
FROM (
|
||||||
SELECT i.itemFk, i.quantity
|
SELECT i.itemFk, i.quantity
|
||||||
|
@ -29,8 +29,8 @@ BEGIN
|
||||||
WHERE st.created > vDated
|
WHERE st.created > vDated
|
||||||
AND (s.isPicked OR st.isChecked)
|
AND (s.isPicked OR st.isChecked)
|
||||||
) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
|
) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
|
||||||
WHERE i.warehouseFk = vWarehouseFk
|
WHERE IFNULL(vWarehouseFk, i.warehouseFk) = i.warehouseFk
|
||||||
AND (vItemFk IS NULL OR i.itemFk = vItemFk)
|
AND (vSelf IS NULL OR i.itemFk = vSelf)
|
||||||
AND (s.isPicked OR i.reserved OR stPrevious.saleFk)
|
AND (s.isPicked OR i.reserved OR stPrevious.saleFk)
|
||||||
AND i.shipped >= vDated AND i.shipped < vTomorrow
|
AND i.shipped >= vDated AND i.shipped < vTomorrow
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
@ -38,8 +38,8 @@ BEGIN
|
||||||
FROM itemEntryIn
|
FROM itemEntryIn
|
||||||
WHERE isReceived
|
WHERE isReceived
|
||||||
AND landed >= vDated AND landed < vTomorrow
|
AND landed >= vDated AND landed < vTomorrow
|
||||||
AND warehouseInFk = vWarehouseFk
|
AND IFNULL(vWarehouseFk, warehouseInFk) = warehouseInFk
|
||||||
AND (vItemFk IS NULL OR itemFk = vItemFk)
|
AND (vSelf IS NULL OR itemFk = vSelf)
|
||||||
AND NOT isVirtualStock
|
AND NOT isVirtualStock
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT itemFk, quantity
|
SELECT itemFk, quantity
|
||||||
|
@ -47,8 +47,8 @@ BEGIN
|
||||||
WHERE isDelivered
|
WHERE isDelivered
|
||||||
AND shipped >= vDated
|
AND shipped >= vDated
|
||||||
AND shipped < vTomorrow
|
AND shipped < vTomorrow
|
||||||
AND warehouseOutFk = vWarehouseFk
|
AND IFNULL(vWarehouseFk, warehouseOutFk) = warehouseOutFk
|
||||||
AND (vItemFk IS NULL OR itemFk = vItemFk)
|
AND (vSelf IS NULL OR itemFk = vSelf)
|
||||||
) t
|
) t
|
||||||
GROUP BY itemFk
|
GROUP BY itemFk
|
||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
|
|
|
@ -83,19 +83,19 @@ proc: BEGIN
|
||||||
ai.sd = iic.quantity;
|
ai.sd = iic.quantity;
|
||||||
|
|
||||||
-- Cálculo del visible
|
-- Cálculo del visible
|
||||||
CALL cache.visible_refresh(vCalc, FALSE, vWarehouseFk);
|
CALL cache.stock_refresh(false);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible
|
||||||
(PRIMARY KEY (item_id))
|
(PRIMARY KEY (item_id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT item_id, visible
|
SELECT item_id, amount stock, amount visible
|
||||||
FROM cache.visible
|
FROM cache.stock
|
||||||
WHERE calc_id = vCalc;
|
WHERE warehouse_id = vWarehouseFk;
|
||||||
|
|
||||||
CALL item_calcVisible(vWarehouseFk, util.VN_CURDATE(), NULL);
|
CALL item_calcVisible(NULL, vWarehouseFk, util.VN_CURDATE());
|
||||||
UPDATE tmp.itemInventory it
|
UPDATE tmp.itemInventory it
|
||||||
JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id
|
JOIN tmp.itemVisible iv ON iv.item_id = it.id
|
||||||
SET it.visible = it.visible + ivc.visible;
|
SET it.visible = it.visible + iv.visible;
|
||||||
|
|
||||||
-- Calculo del disponible
|
-- Calculo del disponible
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
|
||||||
|
@ -168,7 +168,6 @@ proc: BEGIN
|
||||||
tmp.itemCalc,
|
tmp.itemCalc,
|
||||||
tmp.itemAtp,
|
tmp.itemAtp,
|
||||||
tItemInventoryCalc,
|
tItemInventoryCalc,
|
||||||
tItemVisibleCalc,
|
tmp.itemVisible;
|
||||||
tmp.itemAtp;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue