Fixed triggers for invoice_detail

This commit is contained in:
Gopi Katwala 2019-06-20 00:11:30 -04:00
parent b02ad814d0
commit ac46e2eb75

View File

@ -455,24 +455,26 @@ CREATE TABLE IF NOT EXISTS `invoice_detail` (
CONSTRAINT `fk_InvDetail_InvNum` FOREIGN KEY (`inv_num`) REFERENCES `invoice` (`inv_no`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE DEFINER=`root`@`localhost` TRIGGER `astute`.`after_invoice_detail_update` AFTER UPDATE ON astute.invoice_detail FOR EACH ROW
CREATE DEFINER=`root`@`localhost` TRIGGER `astute`.`after_invoice_detail_delete` AFTER DELETE ON astute.invoice_detail FOR EACH ROW
BEGIN
UPDATE invoice
SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = OLD.inv_num);
SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = OLD.inv_num)
WHERE inv_no = OLD.inv_num;
END;
CREATE DEFINER=`root`@`localhost` TRIGGER `astute`.`after_invoice_detail_insert` AFTER INSERT ON astute.invoice_detail FOR EACH ROW
BEGIN
UPDATE invoice
SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = NEW.inv_num);
SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = NEW.inv_num)
WHERE inv_no = NEW.inv_num;
END;
CREATE DEFINER=`root`@`localhost` TRIGGER `astute`.`after_invoice_detail_delete` AFTER DELETE ON astute.invoice_detail FOR EACH ROW
CREATE DEFINER=`root`@`localhost` TRIGGER `astute`.`after_invoice_detail_update` AFTER UPDATE ON astute.invoice_detail FOR EACH ROW
BEGIN
UPDATE invoice
SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = OLD.inv_num);
SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = OLD.inv_num)
WHERE inv_no = OLD.inv_num;
END;
-- Dumping data for table astute.invoice_detail: ~14 rows (approximately)
/*!40000 ALTER TABLE `invoice_detail` DISABLE KEYS */;