Added triggers for invoice_detail

This commit is contained in:
Gopi Katwala 2019-06-19 23:41:42 -04:00
parent 716a69ba82
commit b02ad814d0

View File

@ -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