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

18 lines
537 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`expedition_beforeUpdate`
BEFORE UPDATE ON `expedition`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
IF NEW.counter <> OLD.counter THEN
IF (SELECT COUNT(*) FROM expedition e
INNER JOIN ticket t1 ON e.ticketFk = t1.id
INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped)
WHERE t1.id = NEW.ticketFk AND counter = NEW.counter) > 0 THEN
SET NEW.id = NULL;
END IF;
END IF;
END$$
DELIMITER ;