diff --git a/AstuteSystem/sql/astute.sql b/AstuteSystem/sql/astute.sql index 50708e3..29a07ec 100644 --- a/AstuteSystem/sql/astute.sql +++ b/AstuteSystem/sql/astute.sql @@ -755,6 +755,20 @@ DECLARE CONTINUE HANDLER FOR NOT FOUND SET p_finished = 1; END// DELIMITER ; +CREATE FUNCTION astute.`get_draft_remaining_qty_fun`(inv_num_in varchar(40), item_no_in int) RETURNS double +BEGIN +DECLARE draft_qty double; +DECLARE ponum varchar(20); +DECLARE submitted_qty double; +DECLARE po_item_no_in int; + +SELECT po_line_item_num into po_item_no_in from invoice_detail where inv_num = inv_num_in and line_item_num = item_no_in; +SELECT po_num into ponum from invoice where inv_no = inv_num_in; +SELECT sum(qty) into draft_qty from invoice_detail where inv_num = inv_num_in and po_line_item_num = po_item_no_in; +SELECT remaining_qty into submitted_qty from po_detail where PO_num = ponum and line_item_no = po_item_no_in; +return submitted_qty-draft_qty; +END; + -- Dumping structure for function astute.update_remaining_qty_fun DELIMITER // CREATE DEFINER=`root`@`localhost` FUNCTION `update_remaining_qty_fun`(po_no_in varchar(40), inv_num_in varchar(40), item_no_in int) RETURNS double diff --git a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java index 64b9cd7..28577dc 100644 --- a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java +++ b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java @@ -485,7 +485,13 @@ public class SqlDAO extends DAO { PO po = getPOMaster(PONo, null, null, null).get(0); String customerId = po.getCustomerId(); Customer customer = getCustomers(customerId).get(0); + Double previouslyBilledAmt = getPreviouslyBilledAmount(PONo); + + if (invoice.getInvoiceStatus()==2) { + // TODO substract current invoice's bill amount from previouslyBilledAmt + // if it is a submitted invoice + } Double toBeBilledAmt = po.getContractAmt() - previouslyBilledAmt - invoice.getBillAmt(); generatedInvoice = new GeneratedInvoice(invoice, invoiceDetail, po, customer, previouslyBilledAmt, toBeBilledAmt ); return generatedInvoice; @@ -541,7 +547,7 @@ public class SqlDAO extends DAO { try { List services = new ArrayList<>(); Statement stmt = conn.createStatement(); - String sql = "SELECT inv_num, line_item_num, PO_line_item_num, service_type_id, description, fee_type_id, fee, qty FROM INVOICE_DETAIL "; + String sql = "SELECT inv_num, line_item_num, PO_line_item_num, service_type_id, description, fee_type_id, fee, qty, get_draft_remaining_qty_fun('"+invoiceNum+"',"+ lineItemNo + ") as draftRemainingQty FROM INVOICE_DETAIL "; String whereClause = " WHERE "; boolean whereClauseIndicator = false; @@ -567,7 +573,8 @@ public class SqlDAO extends DAO { int feeTypeId = rs.getInt(6); Double fee = rs.getDouble(7); Double qty = rs.getDouble(8); - InvoiceDetail service = new InvoiceDetail(invNo, lineItemNum, POLineItemNum, serviceTypeId, desc, qty, fee, feeTypeId); + Double draftRemainingQty = rs.getDouble(9); + InvoiceDetail service = new InvoiceDetail(invNo, lineItemNum, POLineItemNum, serviceTypeId, desc, qty, fee, feeTypeId,draftRemainingQty); services.add(service); } return services; diff --git a/AstuteSystem/src/main/java/com/astute/model/InvoiceDetail.java b/AstuteSystem/src/main/java/com/astute/model/InvoiceDetail.java index 9a3d3e2..9e1d61e 100644 --- a/AstuteSystem/src/main/java/com/astute/model/InvoiceDetail.java +++ b/AstuteSystem/src/main/java/com/astute/model/InvoiceDetail.java @@ -9,8 +9,9 @@ public class InvoiceDetail { double qty; double fee; int feeTypeId; + double draftRemainingQty; - public InvoiceDetail(String invoiceNum, int lineItemNum, int poLineItemNum, int serviceTypeId, String desc, double qty, double fee, int feeTypeId) { + public InvoiceDetail(String invoiceNum, int lineItemNum, int poLineItemNum, int serviceTypeId, String desc, double qty, double fee, int feeTypeId, double draftRemainingQty) { this.invoiceNum = invoiceNum; this.lineItemNum = lineItemNum; this.poLineItemNum = poLineItemNum; @@ -19,6 +20,7 @@ public class InvoiceDetail { this.qty = qty; this.fee = fee; this.feeTypeId = feeTypeId; + this.draftRemainingQty = draftRemainingQty; } public String getInvoiceNum() { @@ -84,4 +86,12 @@ public class InvoiceDetail { public void setFeeTypeId(int feeTypeId) { this.feeTypeId = feeTypeId; } + + public double getDraftRemainingQty() { + return draftRemainingQty; + } + + public void setDraftRemainingQty(double draftRemainingQty) { + this.draftRemainingQty = draftRemainingQty; + } } \ No newline at end of file