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

37 lines
793 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`collection_beforeUpdate`
BEFORE UPDATE ON `collection`
FOR EACH ROW
2024-01-25 16:33:54 +00:00
BEGIN
DECLARE vStateFk INT;
DECLARE vTotalLines INT;
DECLARE vPickedLines INT;
IF NEW.saleTotalCount <= NEW.salePickedCount
AND (NEW.saleTotalCount != OLD.saleTotalCount
OR NEW.salePickedCount != OLD.salePickedCount)
THEN
SELECT id INTO vStateFk
FROM vn.state
WHERE code = 'PREPARED';
SET NEW.stateFk = vStateFk;
END IF;
IF NEW.saleTotalCount > NEW.salePickedCount
AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN
SELECT id INTO vStateFk
FROM vn.state
WHERE code = 'ON_PREPARATION';
SET NEW.stateFk = vStateFk;
END IF;
END$$
DELIMITER ;