From 4d7ac901c6f46fe798b71ba67e7e1008c0636771 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 14 May 2024 07:52:21 +0200 Subject: [PATCH 1/9] feat: refs #3199 Added more scopes ticket_recalcByScope --- .../vn/procedures/ticket_recalcByScope.sql | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/ticket_recalcByScope.sql b/db/routines/vn/procedures/ticket_recalcByScope.sql index 41105fe23..833ce712d 100644 --- a/db/routines/vn/procedures/ticket_recalcByScope.sql +++ b/db/routines/vn/procedures/ticket_recalcByScope.sql @@ -14,10 +14,19 @@ BEGIN DECLARE vTicketFk INT; DECLARE cTickets CURSOR FOR - SELECT id FROM ticket - WHERE refFk IS NULL - AND ((vScope = 'client' AND clientFk = vId) - OR (vScope = 'address' AND addressFk = vId)); + SELECT DISTINCT t.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk + WHERE t.refFk IS NULL + DATE(t.shipped) > util.VN_CURDATE() + AND ( + (vScope = 'client' AND t.clientFk = vId) + OR (vScope = 'address' AND t.addressFk = vId) + OR (vScope = 'item' AND itc.itemFk = vId) + OR (vScope = 'country' AND itc.countryFk = vId) + OR (vScope = 'taxClass' AND itc.taxClassFk = vId) + ); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; -- 2.40.1 From 1ba6bf9a9c728c052d0fba75f5ab4505c431d85a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 14 May 2024 07:54:52 +0200 Subject: [PATCH 2/9] feat: refs #3199 Added more scopes ticket_recalcByScope --- db/routines/vn/procedures/ticket_recalcByScope.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_recalcByScope.sql b/db/routines/vn/procedures/ticket_recalcByScope.sql index 833ce712d..e484c2890 100644 --- a/db/routines/vn/procedures/ticket_recalcByScope.sql +++ b/db/routines/vn/procedures/ticket_recalcByScope.sql @@ -19,7 +19,7 @@ BEGIN JOIN sale s ON s.ticketFk = t.id JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk WHERE t.refFk IS NULL - DATE(t.shipped) > util.VN_CURDATE() + AND DATE(t.shipped) > util.VN_CURDATE() AND ( (vScope = 'client' AND t.clientFk = vId) OR (vScope = 'address' AND t.addressFk = vId) -- 2.40.1 From 7d47a986bf9797764a12c0cc5e3c16024b04b5e5 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 14 May 2024 08:24:11 +0200 Subject: [PATCH 3/9] feat: refs #3199 Created ticket_recalcItemTaxCountryByScope --- .../vn/procedures/ticket_recalcByScope.sql | 17 ++----- .../ticket_recalcItemTaxCountryByScope.sql | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 db/routines/vn/procedures/ticket_recalcItemTaxCountryByScope.sql diff --git a/db/routines/vn/procedures/ticket_recalcByScope.sql b/db/routines/vn/procedures/ticket_recalcByScope.sql index e484c2890..41105fe23 100644 --- a/db/routines/vn/procedures/ticket_recalcByScope.sql +++ b/db/routines/vn/procedures/ticket_recalcByScope.sql @@ -14,19 +14,10 @@ BEGIN DECLARE vTicketFk INT; DECLARE cTickets CURSOR FOR - SELECT DISTINCT t.id - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk - WHERE t.refFk IS NULL - AND DATE(t.shipped) > util.VN_CURDATE() - AND ( - (vScope = 'client' AND t.clientFk = vId) - OR (vScope = 'address' AND t.addressFk = vId) - OR (vScope = 'item' AND itc.itemFk = vId) - OR (vScope = 'country' AND itc.countryFk = vId) - OR (vScope = 'taxClass' AND itc.taxClassFk = vId) - ); + SELECT id FROM ticket + WHERE refFk IS NULL + AND ((vScope = 'client' AND clientFk = vId) + OR (vScope = 'address' AND addressFk = vId)); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; diff --git a/db/routines/vn/procedures/ticket_recalcItemTaxCountryByScope.sql b/db/routines/vn/procedures/ticket_recalcItemTaxCountryByScope.sql new file mode 100644 index 000000000..82b2a4a48 --- /dev/null +++ b/db/routines/vn/procedures/ticket_recalcItemTaxCountryByScope.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcItemTaxCountryByScope`( + vScope VARCHAR(255), + vId INT +) +BEGIN +/** + * Recalculates tickets in an scope. + * + * @param vScope The scope name + * @param vId The scope id + */ + DECLARE vDone BOOL; + DECLARE vTicketFk INT; + + DECLARE cTickets CURSOR FOR + SELECT DISTINCT t.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk + WHERE t.refFk IS NULL + AND DATE(t.shipped) > util.VN_CURDATE() + AND ( + (vScope = 'item' AND itc.itemFk = vId) + OR (vScope = 'country' AND itc.countryFk = vId) + OR (vScope = 'taxClass' AND itc.taxClassFk = vId) + ); + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + OPEN cTickets; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cTickets INTO vTicketFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + CALL ticket_recalc(vTicketFk, NULL); + END LOOP; + + CLOSE cTickets; +END$$ +DELIMITER ; -- 2.40.1 From 2cee9c9c01799d53f0a784133735b838b6844b2f Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 14 May 2024 08:58:44 +0200 Subject: [PATCH 4/9] feat: refs #3199 Added one more scope ticket_recalcByScope --- .../vn/procedures/ticket_recalcByScope.sql | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/ticket_recalcByScope.sql b/db/routines/vn/procedures/ticket_recalcByScope.sql index 41105fe23..c5df8f82d 100644 --- a/db/routines/vn/procedures/ticket_recalcByScope.sql +++ b/db/routines/vn/procedures/ticket_recalcByScope.sql @@ -14,10 +14,17 @@ BEGIN DECLARE vTicketFk INT; DECLARE cTickets CURSOR FOR - SELECT id FROM ticket - WHERE refFk IS NULL - AND ((vScope = 'client' AND clientFk = vId) - OR (vScope = 'address' AND addressFk = vId)); + SELECT DISTINCT t.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk + WHERE t.refFk IS NULL + AND DATE(t.shipped) > util.VN_CURDATE() + AND ( + (vScope = 'client' AND t.clientFk = vId) + OR (vScope = 'address' AND t.addressFk = vId) + OR (vScope = 'item' AND itc.itemFk = vId) + ); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; -- 2.40.1 From 9b09bc4efb2ffec0312bccba4b6831ddca660c87 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 14 May 2024 08:59:11 +0200 Subject: [PATCH 5/9] feat: refs #3199 Added one more scope ticket_recalcByScope --- .../ticket_recalcItemTaxCountryByScope.sql | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 db/routines/vn/procedures/ticket_recalcItemTaxCountryByScope.sql diff --git a/db/routines/vn/procedures/ticket_recalcItemTaxCountryByScope.sql b/db/routines/vn/procedures/ticket_recalcItemTaxCountryByScope.sql deleted file mode 100644 index 82b2a4a48..000000000 --- a/db/routines/vn/procedures/ticket_recalcItemTaxCountryByScope.sql +++ /dev/null @@ -1,47 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcItemTaxCountryByScope`( - vScope VARCHAR(255), - vId INT -) -BEGIN -/** - * Recalculates tickets in an scope. - * - * @param vScope The scope name - * @param vId The scope id - */ - DECLARE vDone BOOL; - DECLARE vTicketFk INT; - - DECLARE cTickets CURSOR FOR - SELECT DISTINCT t.id - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk - WHERE t.refFk IS NULL - AND DATE(t.shipped) > util.VN_CURDATE() - AND ( - (vScope = 'item' AND itc.itemFk = vId) - OR (vScope = 'country' AND itc.countryFk = vId) - OR (vScope = 'taxClass' AND itc.taxClassFk = vId) - ); - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - OPEN cTickets; - - myLoop: LOOP - SET vDone = FALSE; - FETCH cTickets INTO vTicketFk; - - IF vDone THEN - LEAVE myLoop; - END IF; - - CALL ticket_recalc(vTicketFk, NULL); - END LOOP; - - CLOSE cTickets; -END$$ -DELIMITER ; -- 2.40.1 From e61210fd17e52951a5f010d73bdb8b043129e2cb Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 19 Jul 2024 09:09:45 +0200 Subject: [PATCH 6/9] feat: #3199 Requested changes --- db/routines/vn/procedures/ticket_recalcByScope.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_recalcByScope.sql b/db/routines/vn/procedures/ticket_recalcByScope.sql index c5df8f82d..1541b532e 100644 --- a/db/routines/vn/procedures/ticket_recalcByScope.sql +++ b/db/routines/vn/procedures/ticket_recalcByScope.sql @@ -19,7 +19,6 @@ BEGIN JOIN sale s ON s.ticketFk = t.id JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk WHERE t.refFk IS NULL - AND DATE(t.shipped) > util.VN_CURDATE() AND ( (vScope = 'client' AND t.clientFk = vId) OR (vScope = 'address' AND t.addressFk = vId) -- 2.40.1 From a995d80b46270d82e76f841f648f0f35c8222c6a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 20 Aug 2024 10:58:26 +0200 Subject: [PATCH 7/9] feat: refs #3199 Requested changes --- .../vn/procedures/ticket_recalcByScope.sql | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/ticket_recalcByScope.sql b/db/routines/vn/procedures/ticket_recalcByScope.sql index 1541b532e..9199325ee 100644 --- a/db/routines/vn/procedures/ticket_recalcByScope.sql +++ b/db/routines/vn/procedures/ticket_recalcByScope.sql @@ -14,22 +14,26 @@ BEGIN DECLARE vTicketFk INT; DECLARE cTickets CURSOR FOR + SELECT DISTINCT t.id + FROM ticket t + LEFT JOIN tItemCalc tic ON tic.id = t.id + WHERE t.refFk IS NULL + AND ((vScope = 'client' AND t.clientFk = vId) + OR (vScope = 'address' AND t.addressFk = vId) + OR (vScope = 'item' AND tic.id) + ); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + CREATE OR REPLACE TEMPORARY TABLE tItemCalc SELECT DISTINCT t.id FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk WHERE t.refFk IS NULL - AND ( - (vScope = 'client' AND t.clientFk = vId) - OR (vScope = 'address' AND t.addressFk = vId) - OR (vScope = 'item' AND itc.itemFk = vId) - ); - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; + AND (vScope = 'item' AND itc.itemFk = vId); OPEN cTickets; - myLoop: LOOP SET vDone = FALSE; FETCH cTickets INTO vTicketFk; @@ -40,7 +44,8 @@ BEGIN CALL ticket_recalc(vTicketFk, NULL); END LOOP; - CLOSE cTickets; + + DROP TEMPORARY TABLE tItemCalc; END$$ DELIMITER ; -- 2.40.1 From d0f1362f85a534ad7e365f9b33060fc8fb36ee47 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 20 Aug 2024 10:59:05 +0200 Subject: [PATCH 8/9] feat: refs #3199 Requested changes --- db/routines/vn/procedures/ticket_recalcByScope.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/ticket_recalcByScope.sql b/db/routines/vn/procedures/ticket_recalcByScope.sql index 9199325ee..b872d3163 100644 --- a/db/routines/vn/procedures/ticket_recalcByScope.sql +++ b/db/routines/vn/procedures/ticket_recalcByScope.sql @@ -16,16 +16,16 @@ BEGIN DECLARE cTickets CURSOR FOR SELECT DISTINCT t.id FROM ticket t - LEFT JOIN tItemCalc tic ON tic.id = t.id + LEFT JOIN tItems ti ON ti.id = t.id WHERE t.refFk IS NULL AND ((vScope = 'client' AND t.clientFk = vId) OR (vScope = 'address' AND t.addressFk = vId) - OR (vScope = 'item' AND tic.id) + OR (vScope = 'item' AND ti.id) ); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - CREATE OR REPLACE TEMPORARY TABLE tItemCalc + CREATE OR REPLACE TEMPORARY TABLE tItems SELECT DISTINCT t.id FROM ticket t JOIN sale s ON s.ticketFk = t.id @@ -46,6 +46,6 @@ BEGIN END LOOP; CLOSE cTickets; - DROP TEMPORARY TABLE tItemCalc; + DROP TEMPORARY TABLE tItems; END$$ DELIMITER ; -- 2.40.1 From d2bd408e316cb4b593f6711989ed9486123e339d Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 20 Aug 2024 12:59:28 +0200 Subject: [PATCH 9/9] feat: refs #3199 Requested changes --- db/routines/vn/procedures/ticket_recalcByScope.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/routines/vn/procedures/ticket_recalcByScope.sql b/db/routines/vn/procedures/ticket_recalcByScope.sql index b872d3163..ede755187 100644 --- a/db/routines/vn/procedures/ticket_recalcByScope.sql +++ b/db/routines/vn/procedures/ticket_recalcByScope.sql @@ -26,6 +26,8 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; CREATE OR REPLACE TEMPORARY TABLE tItems + (PRIMARY KEY (id)) + ENGINE = MEMORY SELECT DISTINCT t.id FROM ticket t JOIN sale s ON s.ticketFk = t.id -- 2.40.1