From b02ad814d04edf6d80c26711992059837ce68c99 Mon Sep 17 00:00:00 2001 From: Gopi Katwala Date: Wed, 19 Jun 2019 23:41:42 -0400 Subject: [PATCH] Added triggers for invoice_detail --- AstuteSystem/sql/astute.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/AstuteSystem/sql/astute.sql b/AstuteSystem/sql/astute.sql index 2530a41..db0b0b8 100644 --- a/AstuteSystem/sql/astute.sql +++ b/AstuteSystem/sql/astute.sql @@ -455,6 +455,25 @@ 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 +BEGIN + UPDATE invoice + SET bill_amt = (SELECT SUM(QTY*FEE) FROM invoice_detail WHERE invoice_detail.inv_num = 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); +END; + +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); +END; + + -- Dumping data for table astute.invoice_detail: ~14 rows (approximately) /*!40000 ALTER TABLE `invoice_detail` DISABLE KEYS */; INSERT INTO `invoice_detail` (`inv_num`, `line_item_num`, `PO_line_item_num`, `service_type_id`, `description`, `qty`, `fee`, `fee_type_id`) VALUES