2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-01-25 16:33:54 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_beforeUpdate`
|
2024-01-15 11:31:03 +00:00
|
|
|
BEFORE UPDATE ON `invoiceIn`
|
|
|
|
FOR EACH ROW
|
|
|
|
BEGIN
|
|
|
|
DECLARE vWithholdingSageFk INT;
|
|
|
|
|
2024-04-16 06:44:50 +00:00
|
|
|
IF NEW.isBooked = OLD.isBooked THEN
|
|
|
|
CALL invoiceIn_checkBooked(OLD.id);
|
|
|
|
END IF;
|
2024-04-04 13:04:23 +00:00
|
|
|
|
2024-02-23 15:01:55 +00:00
|
|
|
IF NOT (NEW.supplierRef <=> OLD.supplierRef) AND NOT util.checkPrintableChars(NEW.supplierRef) THEN
|
2024-02-23 14:58:00 +00:00
|
|
|
CALL util.throw('The invoiceIn reference contains invalid characters');
|
2024-02-23 14:41:30 +00:00
|
|
|
END IF;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
SET NEW.editorFk = account.myUser_getId();
|
|
|
|
|
|
|
|
IF (SELECT COUNT(*) FROM vn.invoiceIn
|
|
|
|
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
|
|
|
|
FROM vn.supplier
|
|
|
|
WHERE id = NEW.supplierFk;
|
|
|
|
SET NEW.withholdingSageFk = vWithholdingSageFk;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|