salix/db/routines/vn/triggers/awbInvoiceIn_afterDelete.sql

16 lines
475 B
MySQL
Raw Normal View History

2024-01-30 06:48:29 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`awbInvoiceIn_afterDelete`
AFTER DELETE ON `awbInvoiceIn`
FOR EACH ROW
BEGIN
IF (SELECT COUNT(*) FROM invoiceInTax where invoiceInFk = OLD.invoiceInFk) = 0
AND
(SELECT COUNT(*) FROM invoiceInDueDay where invoiceInFk = OLD.invoiceInFk) = 0
AND
(SELECT isBooked FROM invoiceIn WHERE id = OLD.invoiceInFk) = 0
THEN
DELETE FROM invoiceIn WHERE id = OLD.invoiceInFk;
END IF;
END$$
DELIMITER ;