salix/db/routines/vn/procedures/ticket_setProblemTooLittleI...

31 lines
867 B
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittleItemCost`(
vItemFk INT
)
BEGIN
/**
* Update the problems when the ticket is too small or is no longer so,
* derived from changes in the itemCost table
*
* @param vItemFk Id del item, NULL ALL items
*/
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk, isProblemCalcNeeded))
ENGINE = MEMORY
WITH tickets AS(
SELECT t.id ticketFk
FROM vn.ticket t
LEFT JOIN vn.sale s ON s.ticketFk = t.id
WHERE t.shipped >= util.VN_CURDATE()
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
GROUP BY t.id
)SELECT ticketFk,
ticket_isTooLittle(ticketFk) hasProblem,
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
FROM tickets;
CALL ticket_setProblem('isTooLittle');
DROP TEMPORARY TABLE tmp.ticket;
END$$
DELIMITER ;