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

19 lines
469 B
MySQL
Raw Normal View History

DELIMITER $$
2024-01-25 16:33:54 +00:00
CREATE OR REPLACE DEFINER=`root`@`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 ;