2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`collection_beforeUpdate`
|
2024-01-15 11:31:03 +00:00
|
|
|
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;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|