From b497b7bdc3aede275ca9bc158e66f53359575b73 Mon Sep 17 00:00:00 2001 From: gopi17701 <GopiKatwala@gmail.com> Date: Sat, 26 Jan 2019 21:01:30 -0500 Subject: [PATCH] Fixed defects. --- .../invoice-payment.component.html | 32 +++- .../invoice-payment.component.ts | 13 +- .../src/app/invoice/invoice.component.html | 5 +- .../src/app/invoice/invoice.component.ts | 5 +- AstuteSystem/sql/astute.sql | 91 ++++++++-- .../src/main/java/com/astute/dao/DAO.java | 28 ++- .../src/main/java/com/astute/dao/SqlDAO.java | 164 ++++++++++++++++-- .../main/java/com/astute/model/Invoice.java | 12 +- .../java/com/astute/model/InvoicePayment.java | 25 ++- .../requests/InvoicePaymentRequest.java | 24 ++- .../resources/InvoicePaymentResource.java | 4 +- .../astute/service/InvoicePaymentService.java | 8 +- 12 files changed, 345 insertions(+), 66 deletions(-) diff --git a/AstuteClient2/src/app/invoice-payment/invoice-payment.component.html b/AstuteClient2/src/app/invoice-payment/invoice-payment.component.html index c0ee27b..230c8e3 100644 --- a/AstuteClient2/src/app/invoice-payment/invoice-payment.component.html +++ b/AstuteClient2/src/app/invoice-payment/invoice-payment.component.html @@ -80,10 +80,19 @@ <tr> <td style="width: 10%"> - <span class="input-group-text">Check# / ACH transaction#*</span> + <span class="input-group-text">Check#</span> </td> <td colspan="7"> - <input type="text" class="form-control" #incheckTransactionNo> + <input type="text" class="form-control" #incheckNo> + </td> + </tr> + + <tr> + <td style="width: 10%"> + <span class="input-group-text">Transaction#</span> + </td> + <td colspan="7"> + <input type="text" class="form-control" #inTransactionNo> </td> </tr> @@ -94,7 +103,7 @@ <div class="modal-footer"> <button class="btn btn-success" type="button" [disabled]="!(chosenInv && inPaymentReceived.value && chosenPaymentType && inDateReceived.value)" - (click)="addInvoicePayment(chosenInv, null, chosenPaymentType, inDateReceived.value, inPaymentReceived.value.replace('$', '').replace(',', ''), incheckTransactionNo.value,new)"> + (click)="addInvoicePayment(chosenInv, null, chosenPaymentType, inDateReceived.value, inPaymentReceived.value.replace('$', '').replace(',', ''), incheckNo.value, inTransactionNo.value, new)"> <!--(click)="addInvoicePayment(chosenInv, null, chosenPaymentType, null, inDateReceived.value, inPaymentReceived.value, new)">--> Add </button> @@ -154,10 +163,19 @@ <tr> <td style="width: 10%"> - <span class="input-group-text">Check# / ACH transaction#*</span> + <span class="input-group-text">Check#</span> </td> <td colspan="7"> - <input type="text" class="form-control" #incheckTransactionNo [value]="selected.checkTransactionNo"> + <input type="text" class="form-control" #incheckNo [value]="selected.checkNo"> + </td> + </tr> + + <tr> + <td style="width: 10%"> + <span class="input-group-text">Transaction#</span> + </td> + <td colspan="7"> + <input type="text" class="form-control" #intransactionNo [value]="selected.transactionNo"> </td> </tr> @@ -166,8 +184,8 @@ </div> <div class="modal-footer"> <button class="btn btn-warning" type="button" - [disabled]="!(invoiceSelect.value && inPaymentReceived.value && inDateReceived.value && incheckTransactionNo)" - (click)="updateInvoicePayment(invoiceSelect.value, selected.invoicePaymentId, selected.paymentTypeId, inDateReceived.value, inPaymentReceived.value.substr(1).replace(',', ''), incheckTransactionNo.value, edit)"> + [disabled]="!(invoiceSelect.value && inPaymentReceived.value && inDateReceived.value)" + (click)="updateInvoicePayment(invoiceSelect.value, selected.invoicePaymentId, selected.paymentTypeId, inDateReceived.value, inPaymentReceived.value.substr(1).replace(',', ''), incheckNo.value, intransactionNo.value, edit)"> Update </button> <button type="button" class="btn btn-danger" (click)="close(edit)">Cancel</button> diff --git a/AstuteClient2/src/app/invoice-payment/invoice-payment.component.ts b/AstuteClient2/src/app/invoice-payment/invoice-payment.component.ts index c2472ff..a791af5 100644 --- a/AstuteClient2/src/app/invoice-payment/invoice-payment.component.ts +++ b/AstuteClient2/src/app/invoice-payment/invoice-payment.component.ts @@ -22,7 +22,8 @@ export class InvoicePaymentComponent implements OnInit { {headerName: 'Payment Received', field: 'invoiceAmount'}, {headerName: 'Date Received', field: 'paymentDate'}, {headerName: 'Payment Type', field: 'paymentType'}, - {headerName: 'Check / ACH Transaction #', field: 'checkTransactionNo'} + {headerName: 'Check / ACH #', field: 'checkNo'}, + {headerName: 'Transaction #', field: 'transactionNo'} ]; @@ -50,14 +51,15 @@ export class InvoicePaymentComponent implements OnInit { } } - addInvoicePayment(invoiceNum, invoicePaymentId, paymentTypeId, paymentDate, paymentReceived, checkTransactionNo, ref) { + addInvoicePayment(invoiceNum, invoicePaymentId, paymentTypeId, paymentDate, paymentReceived, checkNo, transactionNo, ref) { let invoicePaymentData = { "invoiceNum": invoiceNum, "invoicePaymentId":invoicePaymentId, "paymentTypeId":paymentTypeId, "paymentDate": paymentDate, "invoiceAmount": paymentReceived, - "checkTransactionNo": checkTransactionNo + "checkNo": checkNo, + "transactionNo": transactionNo }; this.astuteClientService.addInvoicePayment(invoicePaymentData).then((data) => { if (data) { @@ -71,14 +73,15 @@ export class InvoicePaymentComponent implements OnInit { }); } - updateInvoicePayment(invoiceNum, invoicePaymentId, paymentTypeId, dateReceived, paymentReceived, checkTransactionNo, ref) { + updateInvoicePayment(invoiceNum, invoicePaymentId, paymentTypeId, dateReceived, paymentReceived, checkNo, transactionNo, ref) { const invoicePaymentData = { "invoiceNum": invoiceNum, "invoicePaymentId": invoicePaymentId, "paymentTypeId": paymentTypeId, "paymentDate": dateReceived, "invoiceAmount": paymentReceived, - "checkTransactionNo": checkTransactionNo + "checkNo": checkNo, + "transactionNo": transactionNo }; this.astuteClientService.updateInvoicePayment(invoiceNum, invoicePaymentId, invoicePaymentData).then((data) => { diff --git a/AstuteClient2/src/app/invoice/invoice.component.html b/AstuteClient2/src/app/invoice/invoice.component.html index df723b2..2bb50f2 100644 --- a/AstuteClient2/src/app/invoice/invoice.component.html +++ b/AstuteClient2/src/app/invoice/invoice.component.html @@ -272,8 +272,8 @@ <!--<p *ngIf="chosenInv.invoiceStatus == 1">--> <!--<select class="custom-select"--> <!--(change)="pushOntoSelectedDetail(inNumIn.value, newInDetails.length + 1, selectedPODetails[poDetSelec.value].lineItemNo,--> - <!--selectedPODetails[poDetSelec.value].feeTypeId, selectedPODetails[poDetSelec.value].serviceTypeId,--> - <!--selectedPODetails[poDetSelec.value].serviceDesc, 1, 0, selectedPODetails[poDetSelec.value].remainingQty)"--> + <!--selectedPODetails[poDetSelec.value].feeTypeId,--> + <!--selectedPODetails[poDetSelec.value].serviceDesc, 0, selectedPODetails[poDetSelec.value].fee)"--> <!--[disabled]="!selectedPODetails.length && chosenInv.invoiceStatus !== 1"--> <!--#poDetSelec>--> <!--<option>Add new line item...</option>--> @@ -356,7 +356,6 @@ <!--Invoice Footer--> <div class="modal-body" *ngIf="chosenInv"> - <p class="h4 text-right">Footer</p> <hr> <div class="input-group mb-3"> <div class="input-group-prepend"> diff --git a/AstuteClient2/src/app/invoice/invoice.component.ts b/AstuteClient2/src/app/invoice/invoice.component.ts index 25df705..04482e0 100644 --- a/AstuteClient2/src/app/invoice/invoice.component.ts +++ b/AstuteClient2/src/app/invoice/invoice.component.ts @@ -28,7 +28,7 @@ export class InvoiceComponent implements OnInit { {headerName: 'Date', field: 'invoiceDate'}, {headerName: 'Sales Order Number', field: 'poNum'}, {headerName: 'Change Order Number', field: 'changeOrderNum'}, - {headerName: 'Payment', field: 'pmtStatusDesc'}, + {headerName: 'Outstanding Balance', field: 'outstandingBalance'}, {headerName: 'Bll Amount', field: 'billAmt'} ]; newInDetails = []; @@ -150,6 +150,9 @@ export class InvoiceComponent implements OnInit { this.source.forEach((row) => { row.billAmt = formatCurrency(row.billAmt, 'en-US', '$', 'USD'); }); + this.source.forEach((row) => { + row.outstandingBalance = formatCurrency(row.outstandingBalance, 'en-US', '$', 'USD'); + }); }); this.astuteClientService.getCustomers().then((data) => { diff --git a/AstuteSystem/sql/astute.sql b/AstuteSystem/sql/astute.sql index b1274d7..56b50e4 100644 --- a/AstuteSystem/sql/astute.sql +++ b/AstuteSystem/sql/astute.sql @@ -32,6 +32,19 @@ CREATE TABLE IF NOT EXISTS `change_order` ( /*!40000 ALTER TABLE `change_order` DISABLE KEYS */; /*!40000 ALTER TABLE `change_order` ENABLE KEYS */; +-- Dumping structure for function astute.create_customer_contact_fun +DELIMITER // +CREATE DEFINER=`root`@`localhost` FUNCTION `create_customer_contact_fun`(customer_id varchar(20), contact_id int, name varchar(100), title varchar(50), work_phone int, work_phone_ext int, mobile int, fax int, email varchar(100), address varchar(500)) RETURNS varchar(20) CHARSET utf8 +BEGIN +DECLARE last_inserted_id varchar(20); +INSERT INTO astute.customer_contact +(customer_id, contact_id, name, title, work_phone, work_phone_ext, mobile, fax, email, address) +VALUES ('customer_id', contact_id, 'name', 'title', work_phone, work_phone_ext, mobile, fax, 'email', 'address'); +SELECT LAST_INSERT_ID() into last_inserted_id; +return last_inserted_id; +END// +DELIMITER ; + -- Dumping structure for function astute.create_customer_fun DELIMITER // CREATE DEFINER=`root`@`localhost` FUNCTION `create_customer_fun`(customerid varchar(20), customerName varchar(100), billToDept varchar(100), add1In varchar(100), add2In varchar(100), cityIn varchar(50), stateIn varchar(20), zipIn int(5), zipLast4In int(4), emailIn varchar(50), phoneIn varchar(20), faxIn varchar(20)) RETURNS varchar(20) CHARSET utf8 @@ -107,6 +120,25 @@ 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', NULL); /*!40000 ALTER TABLE `customer` ENABLE KEYS */; +-- Dumping structure for table astute.customer_contact +CREATE TABLE IF NOT EXISTS `customer_contact` ( + `customer_id` varchar(20) NOT NULL, + `contact_id` int(11) NOT NULL, + `name` varchar(100) NOT NULL, + `title` varchar(50) NOT NULL, + `work_phone` int(10) DEFAULT NULL, + `work_phone_ext` int(10) DEFAULT NULL, + `mobile` int(10) DEFAULT NULL, + `fax` int(10) DEFAULT NULL, + `email` varchar(100) DEFAULT NULL, + `address` varchar(500) DEFAULT NULL, + PRIMARY KEY (`customer_id`,`contact_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Dumping data for table astute.customer_contact: ~0 rows (approximately) +/*!40000 ALTER TABLE `customer_contact` DISABLE KEYS */; +/*!40000 ALTER TABLE `customer_contact` ENABLE KEYS */; + -- Dumping structure for function astute.delete_custmer DELIMITER // CREATE DEFINER=`root`@`localhost` FUNCTION `delete_custmer`(customer_id_in varchar(20)) RETURNS varchar(40) CHARSET utf8 @@ -130,6 +162,15 @@ BEGIN END// DELIMITER ; +-- Dumping structure for function astute.delete_custmer_contact +DELIMITER // +CREATE DEFINER=`root`@`localhost` FUNCTION `delete_custmer_contact`(customer_id_in varchar(20), customer_contact_id int) RETURNS varchar(40) CHARSET utf8 +BEGIN + delete from customer_contact where customer_id = customer_id_in and contact_id = customer_contact_id; + RETURN 'SUCCESS'; +END// +DELIMITER ; + -- 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 @@ -280,6 +321,20 @@ declare customer_id_out varchar(20); END// DELIMITER ; +-- Dumping structure for function astute.get_outstanding_inv_balance +DELIMITER // +CREATE DEFINER=`root`@`localhost` FUNCTION `get_outstanding_inv_balance`(invno varchar(20)) RETURNS double(10,2) +BEGIN + declare outstanding_amt double(10,2); + SELECT invoice.bill_amt - sum(invoice_amount) INTO outstanding_amt + FROM invoice join invoice_payment on invoice.inv_no = invoice_payment.inv_no + where invoice.inv_no = invno + group by invoice_payment.inv_no; + + return outstanding_amt; +END// +DELIMITER ; + -- Dumping structure for function astute.get_payment_status_name DELIMITER // CREATE DEFINER=`root`@`localhost` FUNCTION `get_payment_status_name`(pmt_status int) RETURNS varchar(20) CHARSET utf8 @@ -325,11 +380,12 @@ CREATE TABLE IF NOT EXISTS `invoice` ( CONSTRAINT `fk_InvMaster_POnum` FOREIGN KEY (`PO_num`) REFERENCES `po` (`PO_num`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- Dumping data for table astute.invoice: ~4 rows (approximately) +-- Dumping data for table astute.invoice: ~3 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 ('MDO-01_0108_1', '2019-01-08', 'MDOT-123', 30250, 'Test', 'Certified that the above items and rates are in accordance with the contractual agreement as verified by the undersigned', 3, 1), ('MDO-01_DRAFT_157', '2019-01-15', 'MDOT-123', 2500, 'Trest', 'Certified that the above items and rates are in accordance with the contractual agreement as verified by the undersigned', 1, 1), + ('VDO-01_DRAFT_351', '2019-01-22', 'VDOT-54321', 2000, 'Test', 'Certified that the above items and rates are in accordance with the contractual agreement as verified by the undersigned', 1, 1), ('VDO-02_0107_2', '2019-01-07', 'ABC-123', 1450, 'Test', 'Certified that the above items and rates are in accordance with the contractual agreement as verified by the undersigned', 3, 1), ('VDO-02_0108_3', '2019-01-08', 'ABC-123', 5250, 'Test', 'Certified that the above items and rates are in accordance with the contractual agreement as verified by the undersigned', 2, 1); /*!40000 ALTER TABLE `invoice` ENABLE KEYS */; @@ -350,7 +406,7 @@ 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: ~12 rows (approximately) +-- 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 ('MDO-01_0108_1', 1, 1, 2, 'Design', 0.5, 2500, 1), @@ -360,6 +416,9 @@ INSERT INTO `invoice_detail` (`inv_num`, `line_item_num`, `PO_line_item_num`, `s ('MDO-01_0108_1', 5, 5, 5, 'Forensic Investigation', 0.5, 5000, 1), ('MDO-01_0108_1', 6, -1, 1, 'Out of Pocket Expenses - gas', 50, 20, 1), ('MDO-01_DRAFT_157', 1, 1, 2, 'Design', 1, 2500, 1), + ('VDO-01_DRAFT_351', 1, 1, 1, 'Study existing designs', 0.5, 1000, 1), + ('VDO-01_DRAFT_351', 2, 2, 2, 'Modify design', 0.5, 2000, 1), + ('VDO-01_DRAFT_351', 3, 3, 4, 'Cost estimation', 0.5, 1000, 1), ('VDO-02_0107_2', 1, 1, 2, 'Design', 0.25, 5000, 1), ('VDO-02_0107_2', 2, -1, 1, 'Out of Pocket Expenses', 20, 10, 1), ('VDO-02_0108_3', 1, 1, 2, 'Design', 0.25, 5000, 1), @@ -385,20 +444,22 @@ CREATE TABLE IF NOT EXISTS `invoice_payment` ( `invoice_amount` double NOT NULL, `payment_date` date NOT NULL, `invoice_payment_id` int(11) NOT NULL AUTO_INCREMENT, - `check_transaction_no` varchar(50) NOT NULL, + `check_no` varchar(50) DEFAULT NULL, `void_payment_status` int(11) NOT NULL DEFAULT '0', + `transaction_no` varchar(50) DEFAULT NULL, PRIMARY KEY (`invoice_payment_id`), KEY `fk_inv_pmt_inv_no` (`inv_no`), KEY `fk_pinv_pmt_type` (`invoice_payment_type`), CONSTRAINT `fk_inv_pmt_inv_no` FOREIGN KEY (`inv_no`) REFERENCES `invoice` (`inv_no`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_pinv_pmt_type` FOREIGN KEY (`invoice_payment_type`) REFERENCES `payment_type` (`payment_type_id`) -) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8; --- Dumping data for table astute.invoice_payment: ~0 rows (approximately) +-- Dumping data for table astute.invoice_payment: ~2 rows (approximately) /*!40000 ALTER TABLE `invoice_payment` DISABLE KEYS */; -INSERT INTO `invoice_payment` (`inv_no`, `invoice_payment_type`, `invoice_amount`, `payment_date`, `invoice_payment_id`, `check_transaction_no`, `void_payment_status`) VALUES - ('VDO-02_0107_2', 2, 5000, '2019-01-09', 13, '123456', 0), - ('VDO-02_0107_2', 2, 5000, '2019-01-08', 15, '123123', 0); +INSERT INTO `invoice_payment` (`inv_no`, `invoice_payment_type`, `invoice_amount`, `payment_date`, `invoice_payment_id`, `check_no`, `void_payment_status`, `transaction_no`) VALUES + ('VDO-02_0107_2', 2, 5000, '2019-01-09', 13, '123123', 0, '456456'), + ('VDO-02_0107_2', 2, 5000, '2019-01-08', 15, '123124', 0, '456457'), + ('VDO-02_0108_3', 2, 0.1, '2019-01-22', 16, 'asdfasdf', 0, 'asdfasdf'); /*!40000 ALTER TABLE `invoice_payment` ENABLE KEYS */; -- Dumping structure for table astute.invoice_status @@ -512,9 +573,9 @@ INSERT INTO `po_detail` (`PO_num`, `line_item_no`, `service_desc`, `fee_type_id` ('MDOT-123', 3, 'Peer Review', 2, 100, 3, 250, 100), ('MDOT-123', 4, 'Cost Estimation', 2, 100, 4, 250, 100), ('MDOT-123', 5, 'Forensic Investigation', 1, 1, 5, 5000, 1), - ('VDOT-54321', 1, 'Study existing designs', 1, 1, 1, 1000, 1), - ('VDOT-54321', 2, 'Modify design', 1, 1, 2, 2000, 1), - ('VDOT-54321', 3, 'Cost estimation', 1, 1, 4, 1000, 1), + ('VDOT-54321', 1, 'Study existing designs', 1, 1, 1, 1000, 0.5), + ('VDOT-54321', 2, 'Modify design', 1, 1, 2, 2000, 0.5), + ('VDOT-54321', 3, 'Cost estimation', 1, 1, 4, 1000, 0.5), ('VDOT-54321', 4, 'Peer Review', 2, 100, 3, 100, 100); /*!40000 ALTER TABLE `po_detail` ENABLE KEYS */; @@ -533,7 +594,8 @@ INSERT INTO `service_type` (`service_type_id`, `desc`) VALUES (3, 'Peer Review'), (4, 'Cost Estimation'), (5, 'Forensic Investigation'), - (6, 'Out-of-pocket Expense'); + (6, 'Out-of-pocket Expense'), + (7, 'TEMP'); /*!40000 ALTER TABLE `service_type` ENABLE KEYS */; -- Dumping structure for table astute.session @@ -547,13 +609,14 @@ CREATE TABLE IF NOT EXISTS `session` ( CONSTRAINT `fk_session_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- Dumping data for table astute.session: ~22 rows (approximately) +-- Dumping data for table astute.session: ~21 rows (approximately) /*!40000 ALTER TABLE `session` DISABLE KEYS */; INSERT INTO `session` (`session_id`, `user_id`, `session_start_date`, `session_end_date`) VALUES ('042ef08346f84d52b98a22dab48c7b1c', 1, NULL, NULL), ('058cdb87447645da9ec265e566af834c', 1, NULL, NULL), ('2b4382383bd143f9b995c4321fa6d1ac', 1, NULL, NULL), ('3492c28027db4033987a62d80714b8d0', 1, NULL, NULL), + ('3779d52b38ea42898e268ad0f151ae64', 1, NULL, NULL), ('37ac54b5cf5241b080b019d23c151fd8', 1, NULL, NULL), ('46d91a474f4544a2ab60002f799383a7', 1, NULL, NULL), ('4f48b60481ab4729a26b809c077fc7c0', 1, NULL, NULL), @@ -567,7 +630,9 @@ INSERT INTO `session` (`session_id`, `user_id`, `session_start_date`, `session_e ('a067451faf5f401680562bb291295629', 1, NULL, NULL), ('abeefc05fe8e48e5bac7ffab65c85ca6', 1, NULL, NULL), ('b356aab1dbe84d4f9eea9c1cd965c9a4', 1, NULL, NULL), + ('b77de6ef2b4b4e0487689c689f246ab5', 1, NULL, NULL), ('b9e4507fcc8f487eaf3eb3a9f3b378ed', 1, NULL, NULL), + ('d14cb15f91454c3ba3bbfda60444bb05', 1, NULL, NULL), ('d6387d93d84341fc91a0c4a5cbf266db', 1, NULL, NULL), ('d98f7e0c9a934afaa89f0f0545c1c81c', 1, NULL, NULL), ('dcb4b261f925464bb69ff685c1c6134d', 1, NULL, NULL), diff --git a/AstuteSystem/src/main/java/com/astute/dao/DAO.java b/AstuteSystem/src/main/java/com/astute/dao/DAO.java index 2101c25..ec86c52 100644 --- a/AstuteSystem/src/main/java/com/astute/dao/DAO.java +++ b/AstuteSystem/src/main/java/com/astute/dao/DAO.java @@ -3,12 +3,13 @@ package com.astute.dao; import com.astute.exceptions.AstuteException; import com.astute.model.*; -import java.sql.Connection; -import java.sql.Date; -import java.sql.ResultSet; +import java.sql.*; import java.text.ParseException; +import java.util.ArrayList; import java.util.List; +import static com.astute.exceptions.AstuteException.DB_ERROR; + public abstract class DAO { public static DAO dao; @@ -102,6 +103,11 @@ public abstract class DAO { public abstract List<ServiceType> getServiceTypes() throws AstuteException; + public abstract void createServiceType(String desc) throws AstuteException; + + public abstract void updateServiceType(int serviceTypeId, String desc) throws AstuteException; + + public abstract void deleteServiceType(int serviceTypeId) throws AstuteException; public abstract List<Invoice> getInvoiceMaster(String invoiceNumber, int pmtStatus) throws AstuteException; @@ -129,6 +135,8 @@ public abstract class DAO { public abstract List<Invoice> getSubmittedInvoiceNumbers() throws AstuteException; + public abstract List<PaymentStatus> getPaymentStatuses() throws AstuteException; + public abstract List<Customer> getCustomers(String customerId) throws AstuteException; public abstract Customer getCustomer(String poNumber) throws AstuteException; @@ -139,7 +147,15 @@ public abstract class DAO { public abstract void deleteCustomer(String customerId) throws AstuteException; - public abstract List<PaymentStatus> getPaymentStatuses() throws AstuteException; + /*=============================== Customer Contacts Methods =============================================== + */ + public abstract List<CustomerContact> getCustomerContacts(String customerId) throws AstuteException; + + public abstract String createCustomerContact(String customerId, String name,String title,int workPhone,int phExt,int mobile, int fax, String email, String address) throws AstuteException; + + public abstract void updateCustomerContact(String customerId, int contactId, String name,String title,int workPhone,int phExt,int mobile, int fax, String email, String address) throws AstuteException; + + public abstract void deleteCustomerContact(String customerId, int contactId) throws AstuteException; // User and session method implementation @@ -163,9 +179,9 @@ public abstract class DAO { public abstract List<InvoicePayment> getInvoicePayments(String invoiceNum) throws AstuteException; - public abstract void updateInvoicePayment(String invoiceNum, int invoicePaymentId, int InvoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkTransactionNo) throws AstuteException; + public abstract void updateInvoicePayment(String invoiceNum, int invoicePaymentId, int InvoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkNo, String transactionNo) throws AstuteException; - public abstract void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkTransactionNo) throws AstuteException; + public abstract void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkNo, String transactionNo) throws AstuteException; public abstract List<PaymentType> getPaymentTypes() throws AstuteException; } \ No newline at end of file diff --git a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java index 7b3d29c..42103b9 100644 --- a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java +++ b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java @@ -267,6 +267,38 @@ public class SqlDAO extends DAO { } } + public void createServiceType(String desc) throws AstuteException { + try { + Statement stmt = conn.createStatement(); + String sql = "INSERT INTO service_type (service_type_id, `desc`) VALUES ((SELECT MAX(service_type_id)+1 FROM SERVICE_TYPE B), desc)"; + stmt.executeUpdate(sql); + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } + } + public void deleteServiceType(int serviceTypeId) throws AstuteException { + try { + Statement stmt = conn.createStatement(); + String sql = "delete from service_type where service_type_id = '" + serviceTypeId; + stmt.executeUpdate(sql); + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } + + }; + + public void updateServiceType(int serviceTypeId, String desc) throws AstuteException { + try { + Statement stmt = conn.createStatement(); + String sql = "UPDATE service_type desc = '" + desc + "' WHERE service_type_id = " + serviceTypeId; + stmt.executeUpdate(sql); + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } +} /* =============================== Invoice Methods =============================================== */ @@ -345,7 +377,8 @@ public class SqlDAO extends DAO { Statement stmt = conn.createStatement(); String whereClause = " WHERE "; boolean whereClauseIndicator = false; - String sql = "SELECT inv_no, inv_date, PO_num, pmt_status, bill_amt, special_notes, certification, inv_status, get_payment_status_name(pmt_status), get_customer_from_po(PO_num) FROM INVOICE "; + + String sql = "SELECT inv_no, inv_date, PO_num, pmt_status, bill_amt, special_notes, certification, inv_status, get_payment_status_name(pmt_status), get_customer_from_po(PO_num), ifnull(get_outstanding_inv_balance(inv_no), bill_amt) FROM INVOICE "; if (invoiceNumber != null && !invoiceNumber.isEmpty()) { whereClause = whereClause + " UPPER(inv_no) = '"+ invoiceNumber.toUpperCase() +"'"; whereClauseIndicator = true; @@ -373,7 +406,8 @@ public class SqlDAO extends DAO { int invoiceStatus = rs.getInt(8); String paymentStatusDesc = rs.getString(9); String customerId = rs.getString(10); - Invoice invoice = new Invoice(invNo, invdDate, PONo, paymentStatus, billAmt, specialNotes, certification, invoiceStatus, paymentStatusDesc, customerId); + double outstandingBalance = rs.getDouble(11); + Invoice invoice = new Invoice(invNo, invdDate, PONo, paymentStatus, billAmt, specialNotes, certification, invoiceStatus, paymentStatusDesc, customerId, outstandingBalance); invoices.add(invoice); } return invoices; @@ -636,7 +670,7 @@ public class SqlDAO extends DAO { while (resultSet.next()) { invoiceNumber = resultSet.getString(1); - invoice = new Invoice(invoiceNumber,null,null,1,null,null,null,0, "Outstanding",""); + invoice = new Invoice(invoiceNumber,null,null,1,null,null,null,0, "Outstanding","", 0); invoices.add(invoice); } } catch (SQLException e) { @@ -791,6 +825,115 @@ public class SqlDAO extends DAO { throw new AstuteException(DB_ERROR, e.getMessage()); } } +/*=============================== Customer Contacts Methods =============================================== +*/ + + public List<CustomerContact> getCustomerContacts(String customerId) throws AstuteException { + try { + List<CustomerContact> contacts = new ArrayList<>(); + Statement stmt = conn.createStatement(); + String sql = "SELECT customer_id, contact_id, name, title, work_phone, work_phone_ext, mobile, fax, email, address, FROM astute.customer_contact"; + if (customerId!=null && !customerId.isEmpty()) { + sql += " WHERE customer_id = '" + customerId + "'"; + } + ResultSet rs = stmt.executeQuery(sql); + while (rs.next()) { + String customerID = rs.getString(1); + int contactId = rs.getInt(2); + String name = rs.getString(3); + String title = rs.getString(4); + int workPhone = rs.getInt(5); + int phoneExt = rs.getInt(6); + int mobile = rs.getInt(7); + int fax = rs.getInt(8); + String email = rs.getString(9); + String address = rs.getString(10); + CustomerContact contact = new CustomerContact(customerID, contactId, name, title, workPhone, phoneExt, mobile, fax, email, address); + contacts.add(contact); + } + return contacts; + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } + } + + public String createCustomerContact(String customerId, String name,String title, int workPhone,int phExt,int mobile, int fax, String email, String address) throws AstuteException { + try { + CallableStatement stmt = conn.prepareCall("{? = call create_customer_contact_fun(?,?,?,?,?,?,?,?,?)}"); + stmt.registerOutParameter(1, Types.INTEGER); + stmt.setString(2, customerId); + stmt.setString(3, name); + stmt.setString(4, title); + stmt.setInt(5, workPhone); + stmt.setInt(6, phExt); + stmt.setInt(7, mobile); + stmt.setInt(8, fax); + stmt.setString(9, email); + stmt.setString(10, address); + stmt.executeUpdate(); + String customerIdOut = stmt.getString(1); + return customerIdOut; + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } + } + public void updateCustomerContact(String customerId, int contactId, String name,String title,int workPhone,int phExt,int mobile, int fax, String email, String address) throws + AstuteException { + try { + String sql = "UPDATE CUSTOMER_CONTACT "; + String updateClause = " SET "; + String whereClause = ""; + if (customerId==null || customerId.isEmpty() || contactId <=0 ) { + throw new AstuteException(0, "CustomerId or contactId can't be null."); + } else { + whereClause = " WHERE customer_id ='" + customerId + "' and contact_id = " + contactId; + } + + updateClause = updateClause + " name = '" + name + "',"; + updateClause = updateClause + " title = '" + title + "',"; + updateClause = updateClause + " workPhone = " + workPhone + ","; + updateClause = updateClause + " phext = " + phExt + ","; + updateClause = updateClause + " mobile = " + mobile + ","; + updateClause = updateClause + " fax = " + fax + ","; + updateClause = updateClause + " address = '" + address + "',"; + updateClause = updateClause + " email = '" + email + "',"; + if (!updateClause.equalsIgnoreCase(" SET ")) { + sql = sql + trimLastCharacter(updateClause, ",") + whereClause; + + } else { + System.out.println(updateClause); + throw new AstuteException(0, "No values to update."); + } + System.out.println(sql); + Statement stmt = conn.createStatement(); + stmt.executeUpdate(sql); + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } + } + + public void deleteCustomerContact(String customerId, int contactId) throws AstuteException { + String result = ""; + try { + System.out.println("Calling delete_customer_contact DB function"); + CallableStatement stmt = conn.prepareCall("{? = call delete_customer_contact(?,?)}"); + stmt.registerOutParameter(1, Types.VARCHAR); + stmt.setString(2, customerId); + stmt.setInt(2, contactId); + stmt.executeUpdate(); + result = stmt.getString(1); + System.out.println(result); + if (!result.equals("SUCCESS")) { + throw new AstuteException(DB_ERROR, result); + } + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR, e.getMessage()); + } + } /* =============================== User/Session Methods =============================================== */ @@ -948,7 +1091,7 @@ public class SqlDAO extends DAO { try { List<InvoicePayment> invoicePayments = new ArrayList<InvoicePayment>(); Statement stmt = conn.createStatement(); - String sql = "SELECT invoice_payment_id, invoice_payment_type, get_payment_type(invoice_payment_type), invoice_amount, payment_date, inv_no, check_transaction_no FROM invoice_payment "; + String sql = "SELECT invoice_payment_id, invoice_payment_type, get_payment_type(invoice_payment_type), invoice_amount, payment_date, inv_no, check_no, transaction_no FROM invoice_payment "; if (invoiceNum != null) { sql += " WHERE inv_no = '" + invoiceNum + "'"; } @@ -960,8 +1103,9 @@ public class SqlDAO extends DAO { Double paymentAmount = rs.getDouble(4); Date paymentDate = rs.getDate(5); String invNo = rs.getString(6); - String checkTransactionNo = rs.getString(7); - InvoicePayment invoicePayment = new InvoicePayment(invNo, invoicePaymentId, invoicePaymentTypeId, invoicePaymentType, paymentDate, paymentAmount, checkTransactionNo); + String checkNo = rs.getString(7); + String transactionNo = rs.getString(8); + InvoicePayment invoicePayment = new InvoicePayment(invNo, invoicePaymentId, invoicePaymentTypeId, invoicePaymentType, paymentDate, paymentAmount, checkNo, transactionNo); invoicePayments.add(invoicePayment); } return invoicePayments; @@ -971,7 +1115,7 @@ public class SqlDAO extends DAO { } }; - public void updateInvoicePayment(String invoiceNum, int invoicePaymentId, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkTransactionNo) throws AstuteException { + public void updateInvoicePayment(String invoiceNum, int invoicePaymentId, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkNo, String transactionNo) throws AstuteException { try { String sql = "UPDATE INVOICE_PAYMENT "; String updateClause = " SET "; @@ -981,7 +1125,7 @@ public class SqlDAO extends DAO { } - updateClause = updateClause + " invoice_payment_type = " + invoicePaymentTypeId + ", invoice_amount = " + paymentAmount + ", check_Transaction_No = '" + checkTransactionNo + "'"; + updateClause = updateClause + " invoice_payment_type = " + invoicePaymentTypeId + ", invoice_amount = " + paymentAmount + ", check_No = '" + checkNo + "', transaction_no = '" + transactionNo + "'"; // if (paymentDate != null) { updateClause = updateClause + ", payment_date = STR_TO_DATE('" + paymentDate + "', '%Y-%m-%d')"; // } @@ -998,10 +1142,10 @@ public class SqlDAO extends DAO { } - public void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkTransactionNo) throws AstuteException{ + public void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkNo, String transactionNo) throws AstuteException{ try { String dateString = "STR_TO_DATE('" + paymentDate + "', '%Y-%m-%d')"; - String sql = "insert into invoice_payment (inv_no, invoice_payment_type, invoice_amount, payment_date, check_transaction_no) values ('" + invoiceNum + "', " + invoicePaymentTypeId + ", " + paymentAmount + ", " + dateString + ", " + checkTransactionNo +")"; + String sql = "insert into invoice_payment (inv_no, invoice_payment_type, invoice_amount, payment_date, check_no, transaction_no) values ('" + invoiceNum + "', " + invoicePaymentTypeId + ", " + paymentAmount + ", " + dateString + ", '" + checkNo +"', '" + transactionNo + "')"; Statement stmt = conn.createStatement(); System.out.println(sql); stmt.execute(sql); diff --git a/AstuteSystem/src/main/java/com/astute/model/Invoice.java b/AstuteSystem/src/main/java/com/astute/model/Invoice.java index f0829e3..d84b5f9 100644 --- a/AstuteSystem/src/main/java/com/astute/model/Invoice.java +++ b/AstuteSystem/src/main/java/com/astute/model/Invoice.java @@ -12,8 +12,9 @@ public class Invoice { String certification; int invoiceStatus; String customerId; + double outstandingBalance; - public Invoice(String invoiceNumber, String invoiceDate, String poNum, int pmtStatus, Double billAmt, String specialNotes, String certification, int invoiceStatus, String pmtStatusDesc, String customerId) { + public Invoice(String invoiceNumber, String invoiceDate, String poNum, int pmtStatus, Double billAmt, String specialNotes, String certification, int invoiceStatus, String pmtStatusDesc, String customerId, double outstandingBalance) { this.invoiceNumber = invoiceNumber; this.invoiceDate = invoiceDate; this.poNum = poNum; @@ -24,6 +25,7 @@ public class Invoice { this.invoiceStatus = invoiceStatus; this.pmtStatusDesc = pmtStatusDesc; this.customerId = customerId; + this.outstandingBalance = outstandingBalance; } public String getInvoiceNumber() { @@ -114,4 +116,12 @@ public class Invoice { public void setCustomerId(String customerId) { this.customerId = customerId; } + + public double getOutstandingBalance() { + return outstandingBalance; + } + + public void setOutstandingBalance(double outstandingBalance) { + this.outstandingBalance = outstandingBalance; + } } diff --git a/AstuteSystem/src/main/java/com/astute/model/InvoicePayment.java b/AstuteSystem/src/main/java/com/astute/model/InvoicePayment.java index a8f70cd..2a3f7a3 100644 --- a/AstuteSystem/src/main/java/com/astute/model/InvoicePayment.java +++ b/AstuteSystem/src/main/java/com/astute/model/InvoicePayment.java @@ -9,15 +9,18 @@ public class InvoicePayment { String paymentType; Date paymentDate; Double invoiceAmount; - String checkTransactionNo; - public InvoicePayment(String invoiceNum, int invoicePaymentId, int paymentTypeId, String paymentType, Date paymentDate, Double invoiceAmount, String checkTransactionNo) { + String checkNo; + String transactionNo; + + public InvoicePayment(String invoiceNum, int invoicePaymentId, int paymentTypeId, String paymentType, Date paymentDate, Double invoiceAmount, String checkNo, String transactionNo) { this.invoiceNum = invoiceNum; this.invoicePaymentId = invoicePaymentId; this.paymentTypeId = paymentTypeId; this.paymentType = paymentType; this.paymentDate = paymentDate; this.invoiceAmount = invoiceAmount; - this.checkTransactionNo = checkTransactionNo; + this.checkNo = checkNo; + this.transactionNo = transactionNo; } public String getInvoiceNum() { @@ -68,11 +71,19 @@ public class InvoicePayment { this.invoiceAmount = invoiceAmount; } - public String getCheckTransactionNo() { - return checkTransactionNo; + public String getCheckNo() { + return checkNo; } - public void setCheckTransactionNo(String checkTransactionNo) { - this.checkTransactionNo = checkTransactionNo; + public void setCheckNo(String checkNo) { + this.checkNo = checkNo; + } + + public String getTransactionNo() { + return transactionNo; + } + + public void setTransactionNo(String transactionNo) { + this.transactionNo = transactionNo; } } diff --git a/AstuteSystem/src/main/java/com/astute/requests/InvoicePaymentRequest.java b/AstuteSystem/src/main/java/com/astute/requests/InvoicePaymentRequest.java index ad1c192..7ebcdd7 100644 --- a/AstuteSystem/src/main/java/com/astute/requests/InvoicePaymentRequest.java +++ b/AstuteSystem/src/main/java/com/astute/requests/InvoicePaymentRequest.java @@ -8,16 +8,18 @@ public class InvoicePaymentRequest { String paymentType; String paymentDate; Double invoiceAmount; - String checkTransactionNo; + String checkNo; + String transactionNo; - public InvoicePaymentRequest(String invoiceNum, int invoicePaymentId, int paymentTypeId, String paymentType, String paymentDate, Double invoiceAmount, String checkTransactionNo) { + public InvoicePaymentRequest(String invoiceNum, int invoicePaymentId, int paymentTypeId, String paymentType, String paymentDate, Double invoiceAmount, String checNo, String transactionNo) { this.invoiceNum = invoiceNum; this.invoicePaymentId = invoicePaymentId; this.paymentTypeId = paymentTypeId; this.paymentType = paymentType; this.paymentDate = paymentDate; this.invoiceAmount = invoiceAmount; - this.checkTransactionNo = checkTransactionNo; + this.checkNo = checkNo; + this.transactionNo = transactionNo; } public InvoicePaymentRequest() { @@ -72,11 +74,19 @@ public class InvoicePaymentRequest { this.invoiceAmount = invoiceAmount; } - public String getCheckTransactionNo() { - return checkTransactionNo; + public String getCheckNo() { + return checkNo; } - public void setCheckTransactionNo(String checkTransactionNo) { - this.checkTransactionNo = checkTransactionNo; + public void setCheckNo(String checkNo) { + this.checkNo = checkNo; + } + + public String getTransactionNo() { + return transactionNo; + } + + public void setTransactionNo(String transactionNo) { + this.transactionNo = transactionNo; } } diff --git a/AstuteSystem/src/main/java/com/astute/resources/InvoicePaymentResource.java b/AstuteSystem/src/main/java/com/astute/resources/InvoicePaymentResource.java index fb85016..4373ae1 100644 --- a/AstuteSystem/src/main/java/com/astute/resources/InvoicePaymentResource.java +++ b/AstuteSystem/src/main/java/com/astute/resources/InvoicePaymentResource.java @@ -36,7 +36,7 @@ public class InvoicePaymentResource { String dateStr = request.getPaymentDate(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date date = new java.sql.Date(df.parse(dateStr).getTime()); - service.updateInvoicePayment(invoiceNum,invoicePaymentId, request.getPaymentTypeId(), request.getInvoiceAmount(), date, request.getCheckTransactionNo()); + service.updateInvoicePayment(invoiceNum,invoicePaymentId, request.getPaymentTypeId(), request.getInvoiceAmount(), date, request.getCheckNo(), request.getTransactionNo()); return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse(); } @@ -46,7 +46,7 @@ public class InvoicePaymentResource { String dateStr = request.getPaymentDate(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date date = new java.sql.Date(df.parse(dateStr).getTime()); - service.createInvoicePayment(request.getInvoiceNum(), request.getPaymentTypeId(), request.getInvoiceAmount(),date,request.getCheckTransactionNo()); + service.createInvoicePayment(request.getInvoiceNum(), request.getPaymentTypeId(), request.getInvoiceAmount(),date, request.getCheckNo(), request.getTransactionNo()); return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse(); } diff --git a/AstuteSystem/src/main/java/com/astute/service/InvoicePaymentService.java b/AstuteSystem/src/main/java/com/astute/service/InvoicePaymentService.java index f498ae9..625d042 100644 --- a/AstuteSystem/src/main/java/com/astute/service/InvoicePaymentService.java +++ b/AstuteSystem/src/main/java/com/astute/service/InvoicePaymentService.java @@ -19,15 +19,15 @@ public class InvoicePaymentService extends Service{ return getDao().getInvoicePayments(invoiceNum); } - public void updateInvoicePayment(String invoiceNum, int invoicePaymentId, int InvoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkTransactionNo) + public void updateInvoicePayment(String invoiceNum, int invoicePaymentId, int InvoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkNo, String transactionNo) throws AstuteException { - getDao().updateInvoicePayment(invoiceNum, invoicePaymentId, InvoicePaymentTypeId, paymentAmount, paymentDate, checkTransactionNo); + getDao().updateInvoicePayment(invoiceNum, invoicePaymentId, InvoicePaymentTypeId, paymentAmount, paymentDate, checkNo, transactionNo); } - public void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkTransactionNo) + public void createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkNo, String transactionNo) throws AstuteException { - getDao().createInvoicePayment(invoiceNum, invoicePaymentTypeId, paymentAmount, paymentDate, checkTransactionNo); + getDao().createInvoicePayment(invoiceNum, invoicePaymentTypeId, paymentAmount, paymentDate, checkNo, transactionNo); } public List<PaymentType> getPaymentTypes() throws AstuteException {