34 lines
891 B
SQL
34 lines
891 B
SQL
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
|
|
*/
|
|
DECLARE vTicketIsTooLittle BOOL;
|
|
|
|
SELECT ticket_isTooLittle(vSelf) INTO vTicketIsTooLittle;
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
|
ENGINE = MEMORY
|
|
WITH ticketData AS (
|
|
SELECT addressFk, DATE(shipped) dated
|
|
FROM vn.ticket
|
|
WHERE id = vSelf
|
|
)
|
|
SELECT t.id ticketFk,
|
|
vTicketIsTooLittle hasProblem,
|
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
|
FROM vn.ticket t
|
|
JOIN ticketData td ON td.addressFk = t.addressFk
|
|
WHERE t.shipped BETWEEN td.dated AND util.dayEnd(td.dated);
|
|
|
|
CALL ticket_setProblem('isTooLittle');
|
|
|
|
DROP TEMPORARY TABLE tmp.ticket;
|
|
END$$
|
|
DELIMITER ; |