salix/db/routines/vn/triggers/sale_beforeDelete.sql

19 lines
467 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`sale_beforeDelete`
BEFORE DELETE ON `sale`
FOR EACH ROW
BEGIN
IF OLD.quantity > 0 THEN
INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`)
SELECT r.id
FROM vn.sale s
JOIN vn.ticket t ON t.id = s.ticketFk
JOIN vn.route r ON r.id = t.routeFk
WHERE r.isOk = FALSE
AND s.id = OLD.id
AND r.created >= util.VN_CURDATE()
GROUP BY r.id;
END IF;
END$$
DELIMITER ;