2024-04-16 15:01:14 +00:00
|
|
|
DELIMITER $$
|
2024-05-13 07:54:27 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittleItemCost`(
|
2024-04-16 15:01:14 +00:00
|
|
|
vItemFk INT
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-05-02 16:13:12 +00:00
|
|
|
* Update the problems when the ticket is too small or is no longer so,
|
|
|
|
* derived from changes in the itemCost table
|
2024-04-16 15:01:14 +00:00
|
|
|
*
|
2024-05-13 08:06:00 +00:00
|
|
|
* @param vItemFk Id del item, NULL ALL items
|
2024-04-16 15:01:14 +00:00
|
|
|
*/
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
|
|
|
(INDEX(ticketFk))
|
|
|
|
ENGINE = MEMORY
|
2024-05-02 15:05:10 +00:00
|
|
|
WITH tickets AS(
|
|
|
|
SELECT t.id ticketFk
|
|
|
|
FROM vn.ticket t
|
|
|
|
JOIN vn.sale s ON s.ticketFk = t.id
|
2024-05-13 08:06:00 +00:00
|
|
|
WHERE t.shipped >= util.midnight()
|
2024-05-13 12:21:01 +00:00
|
|
|
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
2024-05-02 15:05:10 +00:00
|
|
|
GROUP BY t.id
|
|
|
|
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
|
|
|
FROM tickets;
|
2024-04-16 15:01:14 +00:00
|
|
|
|
|
|
|
CALL ticket_setProblem('isTooLittle');
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.ticket;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|