salix/db/changes/10140-kings/00-triggerInvoiceOut.sql

28 lines
883 B
SQL

DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_afterInsert` AFTER INSERT ON `vn`.`invoiceOut` FOR EACH ROW BEGIN
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount);
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_beforeUpdate`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_beforeUpdate` BEFORE UPDATE ON `vn`.`invoiceOut` FOR EACH ROW
BEGIN
CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount);
CALL clientRisk_update (NEW.clientFk, NEW.companyFk, NEW.amount);
END$$
DELIMITER ;
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_beforeDelete`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_beforeDelete` BEFORE DELETE ON `invoiceOut` FOR EACH ROW BEGIN
CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount);
END$$
DELIMITER ;