2024-04-17 11:21:27 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`ticket_recalcByScope`(
|
2024-04-17 11:21:27 +00:00
|
|
|
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;
|
|
|
|
|
2024-04-22 07:02:43 +00:00
|
|
|
DECLARE cTickets CURSOR FOR
|
2024-04-17 11:21:27 +00:00
|
|
|
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;
|
|
|
|
|
2024-04-22 07:02:43 +00:00
|
|
|
OPEN cTickets;
|
2024-04-17 11:21:27 +00:00
|
|
|
|
|
|
|
myLoop: LOOP
|
|
|
|
SET vDone = FALSE;
|
2024-04-22 07:02:43 +00:00
|
|
|
FETCH cTickets INTO vTicketFk;
|
2024-04-17 11:21:27 +00:00
|
|
|
|
|
|
|
IF vDone THEN
|
|
|
|
LEAVE myLoop;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
CALL ticket_recalc(vTicketFk, NULL);
|
|
|
|
END LOOP;
|
|
|
|
|
2024-04-22 07:02:43 +00:00
|
|
|
CLOSE cTickets;
|
2024-04-17 11:21:27 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|