From 2a203926b967715a184dce7fc08fac389d4b024f Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 2 Jul 2024 09:02:24 +0200 Subject: [PATCH 1/7] feat: refs #7564 Added volume column --- db/versions/11124-greenBamboo/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11124-greenBamboo/00-firstScript.sql diff --git a/db/versions/11124-greenBamboo/00-firstScript.sql b/db/versions/11124-greenBamboo/00-firstScript.sql new file mode 100644 index 000000000..6f47cbc21 --- /dev/null +++ b/db/versions/11124-greenBamboo/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.ticket ADD volume decimal(10,6) DEFAULT NULL NULL COMMENT 'Unidad en m3'; -- 2.40.1 From 1e5fd8002cc925b8f7f90fd768328e0e7816103b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 2 Jul 2024 09:36:23 +0200 Subject: [PATCH 2/7] feat: refs #7564 Added proc --- .../vn/procedures/ticket_setVolume.sql | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 db/routines/vn/procedures/ticket_setVolume.sql diff --git a/db/routines/vn/procedures/ticket_setVolume.sql b/db/routines/vn/procedures/ticket_setVolume.sql new file mode 100644 index 000000000..060a6fa57 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setVolume.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolume`( + vSelf INT +) +BEGIN +/** + * Update the volume ticket + * + * @param vSelf Ticket id + */ + DECLARE vVolume DECIMAL(10,6); + + SELECT SUM(s.quantity * ic.cm3delivery / 1000000) INTO vVolume + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN itemCost ic ON ic.itemFk = s.itemFk + AND ic.warehouseFk = t.warehouseFk + WHERE t.id = vSelf; + + UPDATE ticket + SET volume = vVolume + WHERE id = vSelf; +END$$ +DELIMITER ; -- 2.40.1 From 2f8df96ba7d0e8cd4d82d50a18a131fe2a10fa98 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 09:29:12 +0200 Subject: [PATCH 3/7] feat: refs #7564 Added ticket_setVolumeItemCost --- .../procedures/ticket_setVolumeItemCost.sql | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 db/routines/vn/procedures/ticket_setVolumeItemCost.sql diff --git a/db/routines/vn/procedures/ticket_setVolumeItemCost.sql b/db/routines/vn/procedures/ticket_setVolumeItemCost.sql new file mode 100644 index 000000000..c00fc63dc --- /dev/null +++ b/db/routines/vn/procedures/ticket_setVolumeItemCost.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`( + vItemFk INT +) +BEGIN +/** + * Update the volume tickets of item + * + * @param vSelf Ticket id + */ + CREATE OR REPLACE TEMPORARY TABLE tTicket + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN itemCost ic ON ic.itemFk = s.itemFk + AND ic.warehouseFk = t.warehouseFk + WHERE t.id IN ( + SELECT DISTINCT ticketFk + FROM sale + WHERE itemFk = vItemFk + ) + GROUP BY t.id; + + UPDATE ticket t + JOIN tTicket tt ON tt.id = t.id + SET t.volume = tt.volume; + + DROP TEMPORARY TABLE tTicket; +END$$ +DELIMITER ; -- 2.40.1 From 7fc47f05060be40dbd747c6ddc1fe8ee9710d6cc Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 20 Aug 2024 11:43:08 +0200 Subject: [PATCH 4/7] feat: refs #7564 Requested changes --- .../vn/procedures/ticket_setVolumeItemCost.sql | 9 +++------ db/versions/11124-greenBamboo/01-firstScript.sql | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 db/versions/11124-greenBamboo/01-firstScript.sql diff --git a/db/routines/vn/procedures/ticket_setVolumeItemCost.sql b/db/routines/vn/procedures/ticket_setVolumeItemCost.sql index c00fc63dc..f266cd769 100644 --- a/db/routines/vn/procedures/ticket_setVolumeItemCost.sql +++ b/db/routines/vn/procedures/ticket_setVolumeItemCost.sql @@ -16,17 +16,14 @@ BEGIN JOIN ticket t ON t.id = s.ticketFk JOIN itemCost ic ON ic.itemFk = s.itemFk AND ic.warehouseFk = t.warehouseFk - WHERE t.id IN ( - SELECT DISTINCT ticketFk - FROM sale - WHERE itemFk = vItemFk - ) + WHERE s.itemFk = vItemFk + AND t.shipped >= util.VN_CURDATE() GROUP BY t.id; UPDATE ticket t JOIN tTicket tt ON tt.id = t.id SET t.volume = tt.volume; - + DROP TEMPORARY TABLE tTicket; END$$ DELIMITER ; diff --git a/db/versions/11124-greenBamboo/01-firstScript.sql b/db/versions/11124-greenBamboo/01-firstScript.sql new file mode 100644 index 000000000..0398e8a13 --- /dev/null +++ b/db/versions/11124-greenBamboo/01-firstScript.sql @@ -0,0 +1,16 @@ +-- Calculamos todos los volumenes de todos los tickets una sola vez +CREATE OR REPLACE TEMPORARY TABLE tTicketVolume + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN itemCost ic ON ic.itemFk = s.itemFk + AND ic.warehouseFk = t.warehouseFk + GROUP BY t.id; + +UPDATE ticket t + JOIN tTicketVolume tv ON tv.id = t.id + SET t.volume = tv.volume; + +DROP TEMPORARY TABLE tTicketVolume; -- 2.40.1 From 8a03650eca59a06f412637d03a89c61f7bcce7ef Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 20 Aug 2024 11:44:38 +0200 Subject: [PATCH 5/7] feat: refs #7564 Requested changes --- db/versions/11124-greenBamboo/01-firstScript.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/versions/11124-greenBamboo/01-firstScript.sql b/db/versions/11124-greenBamboo/01-firstScript.sql index 0398e8a13..ff1177455 100644 --- a/db/versions/11124-greenBamboo/01-firstScript.sql +++ b/db/versions/11124-greenBamboo/01-firstScript.sql @@ -3,13 +3,13 @@ CREATE OR REPLACE TEMPORARY TABLE tTicketVolume (PRIMARY KEY (id)) ENGINE = MEMORY SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN itemCost ic ON ic.itemFk = s.itemFk + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.itemCost ic ON ic.itemFk = s.itemFk AND ic.warehouseFk = t.warehouseFk GROUP BY t.id; -UPDATE ticket t +UPDATE vn.ticket t JOIN tTicketVolume tv ON tv.id = t.id SET t.volume = tv.volume; -- 2.40.1 From 2b12e046e4d4b28081c2f05b4750574ad32cea88 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 20 Aug 2024 11:45:50 +0200 Subject: [PATCH 6/7] feat: refs #7564 Fix version --- db/versions/11124-greenBamboo/01-firstScript.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/versions/11124-greenBamboo/01-firstScript.sql b/db/versions/11124-greenBamboo/01-firstScript.sql index ff1177455..06c6918be 100644 --- a/db/versions/11124-greenBamboo/01-firstScript.sql +++ b/db/versions/11124-greenBamboo/01-firstScript.sql @@ -1,5 +1,5 @@ -- Calculamos todos los volumenes de todos los tickets una sola vez -CREATE OR REPLACE TEMPORARY TABLE tTicketVolume +CREATE OR REPLACE TEMPORARY TABLE tmp.tTicketVolume (PRIMARY KEY (id)) ENGINE = MEMORY SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume @@ -13,4 +13,4 @@ UPDATE vn.ticket t JOIN tTicketVolume tv ON tv.id = t.id SET t.volume = tv.volume; -DROP TEMPORARY TABLE tTicketVolume; +DROP TEMPORARY TABLE tmp.tTicketVolume; -- 2.40.1 From c991f32f5a737069ea398270ad05e710a70ef3da Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 20 Aug 2024 12:01:28 +0200 Subject: [PATCH 7/7] feat: refs #7564 Fix version --- db/versions/11124-greenBamboo/01-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11124-greenBamboo/01-firstScript.sql b/db/versions/11124-greenBamboo/01-firstScript.sql index 06c6918be..9cacbd5ff 100644 --- a/db/versions/11124-greenBamboo/01-firstScript.sql +++ b/db/versions/11124-greenBamboo/01-firstScript.sql @@ -10,7 +10,7 @@ CREATE OR REPLACE TEMPORARY TABLE tmp.tTicketVolume GROUP BY t.id; UPDATE vn.ticket t - JOIN tTicketVolume tv ON tv.id = t.id + JOIN tmp.tTicketVolume tv ON tv.id = t.id SET t.volume = tv.volume; DROP TEMPORARY TABLE tmp.tTicketVolume; -- 2.40.1