salix/db/routines/vn/procedures/ticket_setProblemFreeze.sql

31 lines
819 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemFreeze`(
vClientFk INT
)
BEGIN
/**
* Update the problem of tickets whose client is frozen or unfrozen
*
* @param vClientFk Id Cliente, if NULL all clients
*/
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk, isProblemCalcNeeded))
ENGINE = MEMORY
SELECT t.id ticketFk,
FALSE hasProblem,
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
FROM ticket t
WHERE t.shipped >= util.VN_CURDATE()
AND (vClientFk IS NULL OR t.clientFk = vClientFk);
UPDATE tmp.ticket t
JOIN ticket ti ON ti.id = t.ticketFk
JOIN client c ON c.id = ti.clientFk
SET t.hasProblem = TRUE
WHERE c.isFreezed;
CALL ticket_setProblem('isFreezed');
DROP TEMPORARY TABLE tmp.ticket;
END$$
DELIMITER ;