2024-07-22 09:52:42 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`dms_beforeUpdate`
|
2024-07-22 09:52:42 +00:00
|
|
|
BEFORE UPDATE ON `dms`
|
|
|
|
FOR EACH ROW
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
DECLARE vHardCopyNumber INT;
|
|
|
|
|
|
|
|
IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL)
|
|
|
|
OR
|
|
|
|
(NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN
|
|
|
|
|
|
|
|
IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN
|
|
|
|
SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi');
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber
|
|
|
|
FROM dms
|
|
|
|
WHERE warehouseFk = NEW.warehouseFk;
|
|
|
|
|
|
|
|
SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1);
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN
|
|
|
|
|
|
|
|
SET NEW.hasFile = 0;
|
|
|
|
END IF;
|
2024-07-22 09:52:42 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|