29 lines
776 B
SQL
29 lines
776 B
SQL
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))
|
|
ENGINE = MEMORY
|
|
WITH tickets AS(
|
|
SELECT t.id ticketFk
|
|
FROM vn.ticket t
|
|
JOIN vn.sale s ON s.ticketFk = t.id
|
|
WHERE t.shipped >= util.midnight()
|
|
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
|
GROUP BY t.id
|
|
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
|
FROM tickets;
|
|
|
|
CALL ticket_setProblem('isTooLittle');
|
|
|
|
DROP TEMPORARY TABLE tmp.ticket;
|
|
END$$
|
|
DELIMITER ; |