From 9f9063567a957f9442ab64c23b2e0f6be39f032b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 12:40:07 +0200 Subject: [PATCH 01/11] refactor: refs #7505 item_getVisible refactor --- .../cache/procedures/visible_refresh.sql | 5 +- db/routines/vn/procedures/item_GetVisible.sql | 43 ------------- db/routines/vn/procedures/item_getVisible.sql | 49 ++++++++++++++ .../vn/procedures/multipleInventory.sql | 64 ++++++------------- 4 files changed, 70 insertions(+), 91 deletions(-) delete mode 100644 db/routines/vn/procedures/item_GetVisible.sql create mode 100644 db/routines/vn/procedures/item_getVisible.sql diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 63b42dfd9..954b8ff23 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -20,11 +20,12 @@ proc: BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) 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; -- 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; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_GetVisible.sql b/db/routines/vn/procedures/item_GetVisible.sql deleted file mode 100644 index ca5e43107..000000000 --- a/db/routines/vn/procedures/item_GetVisible.sql +++ /dev/null @@ -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 ; diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_getVisible.sql new file mode 100644 index 000000000..0516b9d06 --- /dev/null +++ b/db/routines/vn/procedures/item_getVisible.sql @@ -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 ; diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 2a28aa9a0..4d5c5d366 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -1,9 +1,9 @@ -DELIMITER $$ +DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventory`( vDate DATE, vWarehouseFk TINYINT, vMaxDays TINYINT -) +) proc: BEGIN DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; DECLARE vDateFrom DATE DEFAULT vDate; @@ -78,47 +78,18 @@ proc: BEGIN ai.sd = sub.Subtotal; -- Cálculo del visible - UPDATE tmp.itemInventory ai - JOIN ( - SELECT itemFk Id_Article, SUM(quantity) Subtotal - FROM ( - SELECT s.itemFk, s.quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped >= vDate - AND t.shipped < vDateTomorrow - AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL) - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - 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; + CALL `cache`.stock_refresh(false); + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible + (PRIMARY KEY (item_id)) + ENGINE = MEMORY + SELECT item_id, amount stock, amount visible FROM `cache`.stock + WHERE warehouse_id = vWarehouseFk; + + CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + UPDATE tmp.itemInventory it + JOIN tmp.itemVisible iv ON iv.item_id = it.id + SET it.visible = iv.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc @@ -189,6 +160,7 @@ proc: BEGIN DROP TEMPORARY TABLE tmp.itemTravel, tmp.itemCalc, - tmp.itemAtp; -END$$ -DELIMITER ; + tmp.itemAtp, + tmp.itemVisible; +END$$ +DELIMITER ; From a9aad7406aec4e0065069c2db4598a65d930bf3c Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 12:51:36 +0200 Subject: [PATCH 02/11] refactor: refs #7505 Minor change --- db/routines/vn/procedures/multipleInventory.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 4d5c5d366..05f25268c 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -87,9 +87,9 @@ proc: BEGIN WHERE warehouse_id = vWarehouseFk; CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); - UPDATE tmp.itemInventory it - JOIN tmp.itemVisible iv ON iv.item_id = it.id - SET it.visible = iv.visible; + UPDATE tmp.itemInventory it + JOIN tmp.itemVisible iv ON iv.item_id = it.id + SET it.visible = iv.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc From 4f10a93584f309711d455d9081dfee2df9e80ae1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 13:36:46 +0200 Subject: [PATCH 03/11] refactor: refs #7505 Minor change --- db/routines/vn/procedures/multipleInventory.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 05f25268c..630301b94 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -86,7 +86,7 @@ proc: BEGIN SELECT item_id, amount stock, amount visible FROM `cache`.stock WHERE warehouse_id = vWarehouseFk; - CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + CALL item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = iv.visible; From 3bd596e5fd91d63a5c10f62fc45bd8805063d9ca Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 13:53:41 +0200 Subject: [PATCH 04/11] refactor: refs #7505 Added description --- db/routines/vn/procedures/item_getVisible.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_getVisible.sql index 0516b9d06..2294d8903 100644 --- a/db/routines/vn/procedures/item_getVisible.sql +++ b/db/routines/vn/procedures/item_getVisible.sql @@ -5,6 +5,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`( vItemFk INT ) BEGIN +/** + * Calcula el visible de un artículo o de todos. + * + * @param vWarehouse Warehouse id + * @param vDated Max date to filter + * @param vItemFk Item id + * @param tmp.itemVisible(item_id, stock, visible) + */ DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; INSERT INTO tmp.itemVisible (item_id, visible) From aa0e06cfec4be89f54eb2828f115fc8ae800d54e Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 14:00:59 +0200 Subject: [PATCH 05/11] refactor: refs #7505 Changed name --- db/routines/cache/procedures/visible_refresh.sql | 2 +- .../vn/procedures/{item_getVisible.sql => item_calcVisible.sql} | 2 +- db/routines/vn/procedures/multipleInventory.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename db/routines/vn/procedures/{item_getVisible.sql => item_calcVisible.sql} (99%) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 954b8ff23..b200e86f2 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -25,7 +25,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_getVisible(v_warehouse, util.VN_CURDATE(), NULL); + CALL vn.item_calcVisible(v_warehouse, util.VN_CURDATE(), NULL); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql similarity index 99% rename from db/routines/vn/procedures/item_getVisible.sql rename to db/routines/vn/procedures/item_calcVisible.sql index 2294d8903..f7eee661b 100644 --- a/db/routines/vn/procedures/item_getVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`( vWarehouseFk INT, vDated INT, vItemFk INT diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 630301b94..b201bcaae 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -86,7 +86,7 @@ proc: BEGIN SELECT item_id, amount stock, amount visible FROM `cache`.stock WHERE warehouse_id = vWarehouseFk; - CALL item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + CALL item_calcVisible(vWarehouseFk, util.VN_CURDATE(), NULL); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = iv.visible; From 7279feab12f6050cd4aa4840c370082db48304c6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:33:31 +0200 Subject: [PATCH 06/11] feat: refs #7505 Changes --- .../cache/procedures/visible_refresh.sql | 2 +- .../vn/procedures/item_calcVisible.sql | 22 +++++++++---------- .../vn/procedures/multipleInventory.sql | 19 ++++++++-------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index b200e86f2..4feffde8e 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -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) diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index f7eee661b..728c94276 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -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 diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index dd3bd6f17..3e0cf72c7 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -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 ; From 86acc644fea1069e7f94ec52b76ef7a4bafaa635 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:38:07 +0200 Subject: [PATCH 07/11] feat: refs #7505 Changes --- db/routines/vn/procedures/multipleInventory.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 3e0cf72c7..33eb0b0ed 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -83,7 +83,7 @@ proc: BEGIN ai.sd = iic.quantity; -- Cálculo del visible - CALL cache.stock_refresh(false); + CALL cache.stock_refresh(false); CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) @@ -92,7 +92,7 @@ proc: BEGIN FROM cache.stock WHERE warehouse_id = vWarehouseFk; - CALL item_calcVisible(NULL, vWarehouseFk, util.VN_CURDATE()); + CALL item_calcVisible(NULL, vWarehouseFk, vDate); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = it.visible + iv.visible; From 29f9fa0ce36d6c1b9eab9c220b48d9454451f953 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:45:55 +0200 Subject: [PATCH 08/11] feat: refs #7505 Optimization --- .../vn/procedures/multipleInventory.sql | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 33eb0b0ed..6cd584c6e 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -10,7 +10,7 @@ proc: BEGIN DECLARE vDateTo DATETIME; DECLARE vDateToTomorrow DATETIME; DECLARE vDefaultDayRange INT; - DECLARE vCalc INT; + DECLARE vCalcFk INT; IF vDate < util.VN_CURDATE() THEN LEAVE proc; @@ -83,19 +83,18 @@ proc: BEGIN ai.sd = iic.quantity; -- Cálculo del visible - CALL cache.stock_refresh(false); + CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); - CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible + CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, amount stock, amount visible - FROM cache.stock - WHERE warehouse_id = vWarehouseFk; + SELECT item_id, visible + FROM cache.visible + WHERE calc_id = vCalcFk; - CALL item_calcVisible(NULL, vWarehouseFk, vDate); UPDATE tmp.itemInventory it - JOIN tmp.itemVisible iv ON iv.item_id = it.id - SET it.visible = it.visible + iv.visible; + JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id + SET it.visible = it.visible + ivc.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc @@ -168,6 +167,6 @@ proc: BEGIN tmp.itemCalc, tmp.itemAtp, tItemInventoryCalc, - tmp.itemVisible; + tItemVisibleCalc; END$$ DELIMITER ; From c2e9095ccdae2ac6d7b0940916c186259dc43abe Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:22:32 +0200 Subject: [PATCH 09/11] feat: refs #7505 Requested changes --- db/routines/cache/procedures/visible_refresh.sql | 2 +- db/routines/vn/procedures/item_calcVisible.sql | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 4feffde8e..a59669ff6 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -25,7 +25,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_calcVisible(NULL, util.VN_CURDATE(), v_warehouse); + CALL vn.item_calcVisible(NULL, v_warehouse); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index 728c94276..820e73a7e 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -1,7 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`( vSelf INT, - vDated DATE, vWarehouseFk INT ) BEGIN @@ -9,11 +8,11 @@ BEGIN * Calcula el visible de un artículo o de todos. * * @param vWarehouse Warehouse id - * @param vDated Max date to filter * @param vSelf Item id * @param tmp.itemVisible(item_id, stock, visible) */ - DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; + DECLARE vDated DATE DEFAULT util.VN_CURDATE(); + DECLARE vTomorrow DATETIME DEFAULT util.tomorrow(); INSERT INTO tmp.itemVisible(item_id, visible) SELECT itemFk, SUM(quantity) From 470c9bc8720dc1db1a84c47acabe00da23cb29d3 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:24:17 +0200 Subject: [PATCH 10/11] feat: refs #7505 Minor changes --- db/routines/cache/procedures/visible_refresh.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index a59669ff6..d7e02ad96 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -1,13 +1,13 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) -proc: BEGIN +BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN CALL cache_calc_unlock (v_calc); RESIGNAL; END; - CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse); + CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse); IF !v_refresh THEN LEAVE proc; @@ -15,13 +15,13 @@ proc: BEGIN -- Calculamos el stock hasta ayer - CALL `cache`.stock_refresh(false); + CALL cache.stock_refresh(false); CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT item_id, amount stock, amount visible - FROM `cache`.stock + FROM cache.stock WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy @@ -31,7 +31,7 @@ proc: BEGIN INSERT INTO visible (calc_id, item_id,visible) SELECT v_calc, item_id, visible FROM tmp.itemVisible; - CALL cache_calc_end (v_calc); + CALL cache_calc_end (v_calc); DROP TEMPORARY TABLE tmp.itemVisible; END$$ From e2b6473831e2211406e8f5c35fbecb9c9c271bbb Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:24:35 +0200 Subject: [PATCH 11/11] feat: refs #7505 Minor changes --- db/routines/cache/procedures/visible_refresh.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index d7e02ad96..78d23dbfb 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) -BEGIN +proc:BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN CALL cache_calc_unlock (v_calc);