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
|
2024-06-27 11:01:42 +00:00
|
|
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
2024-04-16 15:01:14 +00:00
|
|
|
ENGINE = MEMORY
|
2024-05-02 15:05:10 +00:00
|
|
|
WITH tickets AS(
|
|
|
|
SELECT t.id ticketFk
|
|
|
|
FROM vn.ticket t
|
2024-05-22 12:50:45 +00:00
|
|
|
LEFT JOIN vn.sale s ON s.ticketFk = t.id
|
2024-06-05 08:03:37 +00:00
|
|
|
WHERE t.shipped >= util.VN_CURDATE()
|
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
|
2024-06-27 11:01:42 +00:00
|
|
|
)SELECT ticketFk,
|
|
|
|
ticket_isTooLittle(ticketFk) hasProblem,
|
2024-07-16 13:14:10 +00:00
|
|
|
ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded
|
2024-05-02 15:05:10 +00:00
|
|
|
FROM tickets;
|
2024-04-16 15:01:14 +00:00
|
|
|
|
|
|
|
CALL ticket_setProblem('isTooLittle');
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.ticket;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|