salix/db/versions/11368-whiteAspidistra/00-firstScript.sql

49 lines
1.2 KiB
MySQL
Raw Normal View History

2024-10-01 14:37:12 +00:00
USE vn;
DROP TRIGGER IF EXISTS invoiceIn_beforeUpdate;
2024-12-09 13:03:45 +00:00
UPDATE invoiceIn
2024-10-01 14:37:12 +00:00
SET cplusRectificationTypeFk = NULL
WHERE cplusRectificationTypeFk = 1;
2024-12-09 13:03:45 +00:00
DELETE IGNORE FROM cplusRectificationType WHERE id = 1;
2024-10-01 14:37:12 +00:00
2024-12-09 13:03:45 +00:00
UPDATE cplusRectificationType
2024-10-01 14:37:12 +00:00
SET id = 1
WHERE id = 3;
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`invoiceIn_beforeUpdate`
BEFORE UPDATE ON `invoiceIn`
FOR EACH ROW
BEGIN
DECLARE vWithholdingSageFk INT;
IF NOT (NEW.supplierRef <=> OLD.supplierRef) AND NOT util.checkPrintableChars(NEW.supplierRef) THEN
CALL util.throw('The invoiceIn reference contains invalid characters');
END IF;
SET NEW.editorFk = account.myUser_getId();
2024-12-09 13:03:45 +00:00
IF (SELECT COUNT(*) FROM invoiceIn
2024-10-01 14:37:12 +00:00
WHERE supplierRef = NEW.supplierRef
AND supplierFk = NEW.supplierFk
AND YEAR(issued) = YEAR(NEW.issued)
AND id <> NEW.id
) THEN
CALL util.throw('reference duplicated');
END IF;
IF NEW.supplierFk != OLD.supplierFk THEN
CALL supplier_checkIsActive(NEW.supplierFk);
SELECT withholdingSageFk INTO vWithholdingSageFk
2024-12-09 13:03:45 +00:00
FROM supplier
2024-10-01 14:37:12 +00:00
WHERE id = NEW.supplierFk;
SET NEW.withholdingSageFk = vWithholdingSageFk;
END IF;
END$$
DELIMITER ;