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

18 lines
539 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`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 ;