feat: refs #3199 Created ticket_recalcItemTaxCountryByScope

This commit is contained in:
Guillermo Bonet 2024-05-14 08:24:11 +02:00
parent 1ba6bf9a9c
commit 7d47a986bf
2 changed files with 51 additions and 13 deletions

View File

@ -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;

View File

@ -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 ;