salix/db/routines/vn/procedures/ticket_setProblemTaxDataChe...

24 lines
698 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost`
PROCEDURE `vn`.`ticket_setProblemTaxDataChecked`(vClientFk INT)
BEGIN
/**
* Update the problem of tickets, depending on whether
* the client taxDataCheched is verified or not
*
* @param vClientFk Id cliente, if NULL all clients
*/
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk))
ENGINE = MEMORY
SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem
FROM ticket t
JOIN client c ON c.id = t.clientFk
WHERE t.shipped >= util.midnight()
AND (c.id = vClientFk OR vClientFk IS NULL);
CALL ticket_setProblem('isTaxDataChecked');
DROP TEMPORARY TABLE tmp.ticket;
END$$
DELIMITER ;