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

31 lines
798 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittle`(
vSelf INT
)
BEGIN
/**
* Update the problems when the ticket is too small or is no longer so
*
* @param vSelf Id del ticket
*/
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk, isProblemCalcNeeded))
ENGINE = MEMORY
WITH tickets AS (
SELECT addressFk, DATE(shipped) dated
FROM vn.ticket
WHERE id = vSelf
)
SELECT t.id ticketFk,
ticket_isTooLittle(t.id) hasProblem,
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
FROM vn.ticket t
JOIN tickets ts ON ts.addressFk = t.addressFk
WHERE t.shipped BETWEEN ts.dated AND util.dayEnd(ts.dated);
CALL ticket_setProblem('isTooLittle');
DROP TEMPORARY TABLE tmp.ticket;
END$$
DELIMITER ;