From b7f9398e264b784193945f4446d4298953166141 Mon Sep 17 00:00:00 2001 From: gopi17701 <41270090+gopi17701@users.noreply.github.com> Date: Sun, 23 Sep 2018 19:01:35 -0400 Subject: [PATCH] Add files via upload --- AstuteSystem/sql/astute.sql | 45 ++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/AstuteSystem/sql/astute.sql b/AstuteSystem/sql/astute.sql index 41b1fc6..d35c5c4 100644 --- a/AstuteSystem/sql/astute.sql +++ b/AstuteSystem/sql/astute.sql @@ -105,6 +105,31 @@ INSERT INTO `customer` (`customer_id`, `customer_name`, `bill_to_dept`, `add1`, ('VDOT', 'Virginia Depart of Transportation', 'Billing Department', '13134 Saturn Drive', 'Unit 100', 'McLean', 'VA', 22043, 0, 'Billing@vdot.gov', '(703) 122-1234', '(703) 122-1212'); /*!40000 ALTER TABLE `customer` ENABLE KEYS */; +-- Dumping structure for function astute.delete_invoice +DELIMITER // +CREATE DEFINER=`root`@`localhost` FUNCTION `delete_invoice`(inv_no_in varchar(20)) RETURNS varchar(40) CHARSET utf8 +BEGIN + + DECLARE inv_status_in int; + + SELECT inv_status + INTO inv_status_in + FROM invoice + WHERE inv_no = inv_no_in; + + IF inv_status_in <> 0 THEN + RETURN 'ERROR - ONLY DRAFT INVOICE CAN BE DELETED'; + END IF; + + UPDATE INVOICE_DETAIL SET QTY = 0 WHERE inv_num = inv_no_in; + CALL update_all_remaining_quantities(inv_no_in); + DELETE FROM INVOICE WHERE inv_no = inv_no_in; + + RETURN 'SUCCESS'; + +END// +DELIMITER ; + -- Dumping structure for function astute.duplicate_invoice DELIMITER // CREATE DEFINER=`root`@`localhost` FUNCTION `duplicate_invoice`(inv_no_in varchar(20)) RETURNS varchar(20) CHARSET utf8 @@ -215,9 +240,9 @@ BEGIN SELECT inv_seq + 1 INTO inv_count FROM PO - WHERE PO.PO_num = po_num_in; + WHERE PO.PO_num = po_num_in; - SELECT concat(customer_code, '-',LPAD(po_count, 2, '0'), '_DRAFT_',date_format(now(),'%j')) INTO inv_number; + SELECT concat(customer_code, '-',LPAD(po_count, 2, '0'), '_DRAFT_',FLOOR(RAND()*(999))) INTO inv_number; RETURN inv_number; END// @@ -260,6 +285,8 @@ CREATE TABLE IF NOT EXISTS `invoice` ( -- Dumping data for table astute.invoice: ~1 rows (approximately) /*!40000 ALTER TABLE `invoice` DISABLE KEYS */; +INSERT INTO `invoice` (`inv_no`, `inv_date`, `PO_num`, `bill_amt`, `special_notes`, `certification`, `inv_status`, `pmt_status`) VALUES + ('VDO-01_DRAFT_220', '2018-09-23', 'VDOT-54321', 250, 'First Invoice', 'Certified that the above items and rates are in accordance with the contractual agreement as verified by the undersigned', 1, 0); /*!40000 ALTER TABLE `invoice` ENABLE KEYS */; -- Dumping structure for table astute.invoice_detail @@ -278,8 +305,10 @@ 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; --- Dumping data for table astute.invoice_detail: ~4 rows (approximately) +-- Dumping data for table astute.invoice_detail: ~1 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 + ('VDO-01_DRAFT_220', 1, 1, 1, 'Study existing designs', 0.25, 1000, 1); /*!40000 ALTER TABLE `invoice_detail` ENABLE KEYS */; -- Dumping structure for table astute.invoice_notes @@ -368,7 +397,7 @@ CREATE TABLE IF NOT EXISTS `po` ( `astute_project_num` varchar(20) NOT NULL, `po_id` int(11) NOT NULL, `title` varchar(200) DEFAULT NULL, - `inv_seq` int(3) DEFAULT NULL, + `inv_seq` int(3) NOT NULL DEFAULT '0', PRIMARY KEY (`PO_num`), KEY `ind_pomaster_contractno` (`contract_num`), KEY `ind_pomaster_podate` (`PO_date`), @@ -376,7 +405,7 @@ CREATE TABLE IF NOT EXISTS `po` ( CONSTRAINT `po_customer_id_fk` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- Dumping data for table astute.po: ~1 rows (approximately) +-- Dumping data for table astute.po: ~2 rows (approximately) /*!40000 ALTER TABLE `po` DISABLE KEYS */; INSERT INTO `po` (`PO_num`, `contract_num`, `PO_date`, `contract_amt`, `customer_id`, `astute_project_num`, `po_id`, `title`, `inv_seq`) VALUES ('ABC-123', 'ABC-123', '2018-09-23', 5000.00, 'VDOT', 'ABC-123', 2, 'ABC-123', 0), @@ -399,11 +428,11 @@ CREATE TABLE IF NOT EXISTS `po_detail` ( CONSTRAINT `fk_PODetail_ServType` FOREIGN KEY (`service_type_id`) REFERENCES `service_type` (`service_type_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- Dumping data for table astute.po_detail: ~4 rows (approximately) +-- Dumping data for table astute.po_detail: ~5 rows (approximately) /*!40000 ALTER TABLE `po_detail` DISABLE KEYS */; INSERT INTO `po_detail` (`PO_num`, `line_item_no`, `service_desc`, `fee_type_id`, `qty`, `service_type_id`, `fee`, `remaining_qty`) VALUES ('ABC-123', 1, 'Design', 1, 1, 2, 5000, 1), - ('VDOT-54321', 1, 'Study existing designs', 1, 1, 1, 1000, 1), + ('VDOT-54321', 1, 'Study existing designs', 1, 1, 1, 1000, 0.75), ('VDOT-54321', 2, 'Modify design', 1, 1, 2, 2000, 1), ('VDOT-54321', 3, 'Cost estimation', 1, 1, 4, 1000, 1), ('VDOT-54321', 4, 'Peer Review', 2, 100, 3, 100, 100); @@ -488,7 +517,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `update_remaining_qty_fun`(po_no_in v BEGIN DECLARE rem_qty double; DECLARE po_no varchar(40); -if po_no_in = null or po_no_in = '' THEN +if inv_num_in <> null or inv_num_in <> '' THEN SELECT po_num INTO po_no FROM invoice where inv_no = inv_num_in; else set po_no = po_no_in;