salix/db/routines/edi/triggers/putOrder_beforeUpdate.sql

39 lines
977 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-01-25 16:33:54 +00:00
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`putOrder_beforeUpdate`
BEFORE UPDATE ON `putOrder`
FOR EACH ROW
BEGIN
DECLARE vError VARCHAR(100) DEFAULT 'Orderregel niet meer teruggevonden op basis van de orderps';
DECLARE vVmpIdError INT DEFAULT 7;
DECLARE vVmpFk INT;
DECLARE vSupplyResponseNumberOfUnits INT;
SELECT sr.vmpID INTO vVmpFk
FROM edi.supplyResponse sr
WHERE sr.id = NEW.supplyResponseID;
IF NEW.OrderStatus = 3
AND NOT (NEW.OrderStatus <=> OLD.OrderStatus)
AND NEW.error = vError
AND vVmpFk = vVmpIdError
THEN
SET NEW.OrderStatus = 2;
END IF;
-- Error de disponible menor de lo solicitado
IF NEW.error LIKE 'error2602%' THEN
SELECT NumberOfUnits INTO vSupplyResponseNumberOfUnits
FROM edi.supplyResponse sr
WHERE sr.ID = NEW.supplyResponseID;
SET NEW.error = CONCAT('(',vSupplyResponseNumberOfUnits,') ', NEW.error);
END IF;
END$$
DELIMITER ;