From 3da6a700ae97694b6aa27342a52a6f5dd33be34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 30 Aug 2024 13:08:15 +0200 Subject: [PATCH 1/4] fix: refs #7213 problem rounding --- .../sale_setProblemRoundingByBuy.sql | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql diff --git a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql new file mode 100644 index 000000000..cb7322c22 --- /dev/null +++ b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql @@ -0,0 +1,71 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemRoundingByBuy`( + vBuyFk INT +) +/** + * Update rounding problem for all sales related to a buy + * @param vBuyFk Id buy + */ + DECLARE vItemFk INT, + DECLARE vWareHouseFk INT + DECLARE vMaxDated DATE; + DECLARE vMinDated DATE; + DECLARE vLanding DATE; + DECLARE vLastBuy INT; + DECLARE vCurrentBuy INT; + DECLARE vGrouping INT; + + SELECT b.itemFk, t.warehouseInFk + INTO vItemFk, vWareHouseFk + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + WHERE b.id = vBuyFk; + + SELECT DATE(MAX(t.shipped)) + INTERVAL 1 DAY, DATE(MIN(t.shipped)) + INTO vMaxDated, vMinDated + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE t.shipped >= CURDATE() + AND s.itemFk = vItemFk + AND s.quantity > 0; + + CALL buy_getUltimate(vItemFk, vWareHouseFk, vMinDated); + + SELECT bu.buyFk, b.grouping INTO vLastBuy, vGrouping + FROM tmp.buyUltimate bu + JOIN buy b ON b.id = bu.buyFk; + + DROP TEMPORARY TABLE tmp.buyUltimate; + + SET vLanding = vMaxDated; + + WHILE vCurrentBuy <> vLastBuy OR vLanding > vMinDated DO + SET vMaxDated = vLanding - INTERVAL 1 DAY; + + CALL buy_getUltimate(vItemFk, vWareHouseFk, vMaxDated); + + SELECT buyFk, landing + INTO vCurrentBuy, vLanding + FROM tmp.buyUltimate; + + DROP TEMPORARY TABLE tmp.buyUltimate; + END WHILE; + + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk, isProblemCalcNeeded)) + SELECT s.id saleFk , + MOD(s.quantity, vGrouping) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE s.itemFk = vItemFk + AND s.quantity > 0 + AND t.shipped BETWEEN vMinDated + AND util.dayEnd(vMaxDated); + + CALL sale_setProblem('hasRounding'); + + DROP TEMPORARY TABLE tmp.sale; +END$$ +DELIMITER ; \ No newline at end of file -- 2.40.1 From beb54aedf85ca6f83e867a6e1564691b262199b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 30 Aug 2024 13:14:45 +0200 Subject: [PATCH 2/4] fix: refs #7213 problem rounding --- db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql index cb7322c22..60b495a75 100644 --- a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql +++ b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql @@ -2,12 +2,13 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemRoundingByBuy`( vBuyFk INT ) +BEGIN /** * Update rounding problem for all sales related to a buy * @param vBuyFk Id buy */ - DECLARE vItemFk INT, - DECLARE vWareHouseFk INT + DECLARE vItemFk INT; + DECLARE vWareHouseFk INT; DECLARE vMaxDated DATE; DECLARE vMinDated DATE; DECLARE vLanding DATE; -- 2.40.1 From 4ed5811042b00b54eb65755023dac28a7bdab5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 30 Aug 2024 14:14:06 +0200 Subject: [PATCH 3/4] fix: refs #7213 problem rounding --- .../sale_setProblemRoundingByBuy.sql | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql index 60b495a75..efa1a65fb 100644 --- a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql +++ b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql @@ -4,8 +4,9 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemRoun ) BEGIN /** - * Update rounding problem for all sales related to a buy - * @param vBuyFk Id buy + * Update rounding problem for all sales related to a buy. + * + * @param vBuyFk Buy id */ DECLARE vItemFk INT; DECLARE vWareHouseFk INT; @@ -18,16 +19,16 @@ BEGIN SELECT b.itemFk, t.warehouseInFk INTO vItemFk, vWareHouseFk - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel t ON t.id = e.travelFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk WHERE b.id = vBuyFk; SELECT DATE(MAX(t.shipped)) + INTERVAL 1 DAY, DATE(MIN(t.shipped)) INTO vMaxDated, vMinDated FROM sale s JOIN ticket t ON t.id = s.ticketFk - WHERE t.shipped >= CURDATE() + WHERE t.shipped >= util.VN_CURDATE() AND s.itemFk = vItemFk AND s.quantity > 0; @@ -54,16 +55,16 @@ BEGIN END WHILE; CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk, isProblemCalcNeeded)) - SELECT s.id saleFk , + (INDEX(saleFk, isProblemCalcNeeded)) + ENGINE = MEMORY + SELECT s.id saleFk, MOD(s.quantity, vGrouping) hasProblem, ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM sale s JOIN ticket t ON t.id = s.ticketFk WHERE s.itemFk = vItemFk AND s.quantity > 0 - AND t.shipped BETWEEN vMinDated - AND util.dayEnd(vMaxDated); + AND t.shipped BETWEEN vMinDated AND util.dayEnd(vMaxDated); CALL sale_setProblem('hasRounding'); -- 2.40.1 From c88b069ac344695c8f0abcdd60abf19196d7fa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 30 Aug 2024 14:16:03 +0200 Subject: [PATCH 4/4] fix: refs #7213 problem rounding --- db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql index efa1a65fb..a1362c222 100644 --- a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql +++ b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql @@ -56,7 +56,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.sale (INDEX(saleFk, isProblemCalcNeeded)) - ENGINE = MEMORY + ENGINE = MEMORY SELECT s.id saleFk, MOD(s.quantity, vGrouping) hasProblem, ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded -- 2.40.1