37 lines
826 B
MySQL
37 lines
826 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collection_BEFORE_UPDATE`
|
||
|
BEFORE UPDATE ON `collection`
|
||
|
FOR EACH ROW
|
||
|
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 ;
|