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