From f38d50848565a3a22104276c2298dd196d0005cb Mon Sep 17 00:00:00 2001 From: gopi17701 <41270090+gopi17701@users.noreply.github.com> Date: Tue, 17 Jul 2018 22:30:09 -0400 Subject: [PATCH] Add files via upload --- .../src/main/java/com/astute/dao/SqlDAO.java | 123 +++++++++++++++--- 1 file changed, 106 insertions(+), 17 deletions(-) diff --git a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java index 9b23762..57527bd 100644 --- a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java +++ b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java @@ -35,6 +35,10 @@ public class SqlDAO extends DAO { } } + /* + =============================== PO Methods =============================================== + */ + public List getPOMaster(String PONum, String contractNum, Date PODate) throws AstuteException { try { List pos = new ArrayList<>(); @@ -197,9 +201,7 @@ public class SqlDAO extends DAO { public void createPOMaster(String PONum, String contractNum, Date PODate, Double contractAmt, int customerId) throws AstuteException { try { - System.out.println("Calling create_PO Procedure"); - System.out.println("PONum is " + PONum); - CallableStatement stmt = conn.prepareCall("{call create_PO(?,?,?,?)}"); + CallableStatement stmt = conn.prepareCall("{call create_PO(?,?,?,?,?)}"); stmt.setString(1, PONum); stmt.setString(2, contractNum); stmt.setDate(3, PODate); @@ -232,6 +234,10 @@ public class SqlDAO extends DAO { } } + /* + =============================== Invoice Methods =============================================== + */ + public Double getPreviouslyBilledAmount(String poNum) throws AstuteException { try { Double billedAmt = new Double(0); @@ -495,6 +501,10 @@ public class SqlDAO extends DAO { } } + /* +=============================== Customer Methods =============================================== + */ + public List getCustomers(int customerId) throws AstuteException { try { List customers = new ArrayList<>(); @@ -611,6 +621,9 @@ public class SqlDAO extends DAO { throw new AstuteException(DB_ERROR,e.getMessage()); } } +/* +=============================== User/Session Methods =============================================== + */ // user and session methods public ResultSet executeQuery(String sessionId, String sql) throws AstuteException { @@ -680,6 +693,10 @@ public class SqlDAO extends DAO { } } + /* + =============================== Change Order =============================================== + */ + public List getChangeOrders(String poNum) throws AstuteException { try { @@ -707,7 +724,7 @@ public class SqlDAO extends DAO { }; public void updateChangeOrder(String poNum, int changeOrderNum, double changeOrderAmt, Date changeOrderDate, String description) throws AstuteException { - try { + try { String sql = "UPDATE CHANGE_ORDER "; String updateClause = " SET "; String whereClause = ""; @@ -728,27 +745,99 @@ public class SqlDAO extends DAO { System.out.println(sql); Statement stmt = conn.createStatement(); stmt.executeUpdate(sql); - } catch (SQLException e) { - e.printStackTrace(); - throw new AstuteException(DB_ERROR,e.getMessage()); - } + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } } public int createChangeOrder(String poNum, int changeOrderNum, double changeOrderAmt, Date changeOrderDate, String description) throws AstuteException{ - try { - String dateString = "STR_TO_DATE(" + changeOrderDate + ", '%Y-%m-%d')"; - String sql = "insert into change_order (po_num, change_order_num, change_order_amt, change_order_date, description) values ('" + poNum + "', " + changeOrderNum + ", " + changeOrderAmt + ", " + dateString + ", '" + description + "')"; - Statement stmt = conn.createStatement(); - stmt.execute(sql); - return changeOrderNum; - } catch (SQLException e) { - e.printStackTrace(); - throw new AstuteException(DB_ERROR,e.getMessage()); + try { + String dateString = "STR_TO_DATE(" + changeOrderDate + ", '%Y-%m-%d')"; + String sql = "insert into change_order (po_num, change_order_num, change_order_amt, change_order_date, description) values ('" + poNum + "', " + changeOrderNum + ", " + changeOrderAmt + ", " + dateString + ", '" + description + "')"; + Statement stmt = conn.createStatement(); + stmt.execute(sql); + return changeOrderNum; + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } } + + /* + =============================== Invoice Payment =============================================== + */ + + + public List getInvoicePayments(String invoiceNum) throws AstuteException { + try { + List invoicePayments = new ArrayList(); + Statement stmt = conn.createStatement(); + String sql = "SELECT invoice_payment_id, invoice_payment_type, get_payment_type(invoice_payment_type), invoice_amount, payment_date FROM invoice_payment "; + if (invoiceNum != null) { + sql += " WHERE inv_no = '" + invoiceNum + "'"; + } + ResultSet rs = stmt.executeQuery(sql); + while (rs.next()) { + int invoicePaymentId = rs.getInt(1); + int invoicePaymentTypeId = rs.getInt(2); + String invoicePaymentType = rs.getString(3); + Double paymentAmount = rs.getDouble(4); + Date paymentDate = rs.getDate(5); + InvoicePayment invoicePayment = new InvoicePayment(invoiceNum, invoicePaymentId, invoicePaymentTypeId, invoicePaymentType, paymentDate, paymentAmount); + invoicePayments.add(invoicePayment); + } + return invoicePayments; + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } + }; + + public void updateInvoicePayment(String invoiceNum, int invoicePaymentId, Double paymentAmount, Date paymentDate) throws AstuteException { + try { + String sql = "UPDATE INVOICE_PAYMENT "; + String updateClause = " SET "; + String whereClause = ""; + if (invoiceNum == null || invoiceNum.isEmpty() || invoicePaymentId <=0 ) { + throw new AstuteException(DB_ERROR,"Invoice Number can't be null and Invoice Payment Id should be a positive number! "); + } else { + whereClause = " WHERE UPPER(inv_no) ='" + invoiceNum.toUpperCase() + "' and invoice_amount = " + paymentAmount; + } + + updateClause = updateClause + " payment_amount = " + paymentAmount ; + if (paymentDate != null) { + updateClause = "payment_date " + ", paymentDate = STR_TO_DATE(" + paymentDate + ", '%Y-%m-%d')"; + } + + sql = sql + updateClause + whereClause; + 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 createInvoicePayment(String invoiceNum, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate) 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) values ('" + invoiceNum + "', " + paymentAmount + ", " + dateString + "')"; + Statement stmt = conn.createStatement(); + stmt.execute(sql); + } catch (SQLException e) { + e.printStackTrace(); + throw new AstuteException(DB_ERROR,e.getMessage()); + } } + /* + =============================== Utility Methods =============================================== + */ public String login(String username, String password) throws AstuteException{ User user = dao.getUser(username); boolean check = false;