Merge pull request 'feat: refs #3199 Added one more scope ticketTotal' (!2447) from 3199-ticket_recalc_itemTaxCountry into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2447
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Guillermo Bonet 2024-08-21 12:32:27 +00:00
commit 35c49b4708
1 changed files with 21 additions and 8 deletions

View File

@ -14,16 +14,28 @@ BEGIN
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
DECLARE cTickets CURSOR FOR DECLARE cTickets CURSOR FOR
SELECT id FROM ticket SELECT DISTINCT t.id
WHERE refFk IS NULL FROM ticket t
AND ((vScope = 'client' AND clientFk = vId) LEFT JOIN tItems ti ON ti.id = t.id
OR (vScope = 'address' AND addressFk = vId)); WHERE t.refFk IS NULL
AND ((vScope = 'client' AND t.clientFk = vId)
OR (vScope = 'address' AND t.addressFk = vId)
OR (vScope = 'item' AND ti.id)
);
DECLARE CONTINUE HANDLER FOR NOT FOUND DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
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
JOIN itemTaxCountry itc ON itc.itemFk = s.itemFk
WHERE t.refFk IS NULL
AND (vScope = 'item' AND itc.itemFk = vId);
OPEN cTickets; OPEN cTickets;
myLoop: LOOP myLoop: LOOP
SET vDone = FALSE; SET vDone = FALSE;
FETCH cTickets INTO vTicketFk; FETCH cTickets INTO vTicketFk;
@ -34,7 +46,8 @@ BEGIN
CALL ticket_recalc(vTicketFk, NULL); CALL ticket_recalc(vTicketFk, NULL);
END LOOP; END LOOP;
CLOSE cTickets; CLOSE cTickets;
DROP TEMPORARY TABLE tItems;
END$$ END$$
DELIMITER ; DELIMITER ;