diff --git a/AstuteSystem/src/main/java/com/astute/dao/DAO.java b/AstuteSystem/src/main/java/com/astute/dao/DAO.java index 7d50517..4569a32 100644 --- a/AstuteSystem/src/main/java/com/astute/dao/DAO.java +++ b/AstuteSystem/src/main/java/com/astute/dao/DAO.java @@ -130,9 +130,9 @@ public abstract class DAO { public abstract List getCustomers(String customerId) throws AstuteException; - public abstract String createCustomer(String customerId, String customerName, String billToDept, String add1, String add2, String city, String state, int zip, int ziplast4, String email, Long phone, Long fax) throws AstuteException; + public abstract String createCustomer(String customerId, String customerName, String billToDept, String add1, String add2, String city, String state, int zip, int ziplast4, String email, String phone, String fax) throws AstuteException; - public abstract void updateCustomer(String customerId, String customerName, String billToDept, String add1, String add2, String city, String state, int zip, int ziplast4, String email, Long phone, Long fax) throws AstuteException; + public abstract void updateCustomer(String customerId, String customerName, String billToDept, String add1, String add2, String city, String state, int zip, int ziplast4, String email, String phone, String fax) throws AstuteException; // User and session method implementation diff --git a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java index 7559ecf..3740339 100644 --- a/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java +++ b/AstuteSystem/src/main/java/com/astute/dao/SqlDAO.java @@ -65,7 +65,7 @@ public class SqlDAO extends DAO { Double previouslyBilledAmount = rs.getDouble(8); String date = null; if (poDate != null) { - SimpleDateFormat formatter = new SimpleDateFormat("MM/DD/YYYY"); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); date = formatter.format(poDate); } PO po = new PO(poNum, cntrctNum, date, customerId, contractAmt,astuteProjectNum,title,previouslyBilledAmount); @@ -107,7 +107,7 @@ public class SqlDAO extends DAO { Double fee = rs.getDouble(6); int serviceTypeId = rs.getInt(7); double remainingQty = rs.getInt(8); - PODetail poDetail = new PODetail(poNum, lineItemNum, serviceDesc, feeTypeId, qty, fee, serviceTypeId, remainingQty); + PODetail poDetail = new PODetail(poNum, lineItemNum, serviceDesc, feeTypeId, qty, fee, serviceTypeId, qty); poDetails.add(poDetail); } return poDetails; @@ -156,7 +156,7 @@ public class SqlDAO extends DAO { public void updatePODetail(String POnum, int lineItemNo, String serviceDesc, int feeTypeId, Double qty, Double fee, int serviceTypeId, Double remainingQuantity) throws AstuteException { try { - + // remainingQuantity is not used , need to take it out from signature eventually String sql = "UPDATE PO_DETAIL "; String updateClause = " SET "; String whereClause = " WHERE UPPER(PO_num) = '" + POnum.toUpperCase() + "' AND line_item_no = " + lineItemNo; @@ -172,14 +172,14 @@ public class SqlDAO extends DAO { List lineItem = getPODetail(POnum, lineItemNo); if (lineItem.size() == 0) { // new line item - createPODetail(POnum, lineItemNo, serviceDesc, feeTypeId, qty, fee, serviceTypeId, remainingQuantity); + createPODetail(POnum, lineItemNo, serviceDesc, feeTypeId, qty, fee, serviceTypeId, qty); } else { updateClause += " service_desc = '" + serviceDesc + "',"; updateClause += " fee_type_id = " + feeTypeId + ","; updateClause += " qty = " + qty + ","; updateClause += " fee = " + fee + ","; updateClause += " service_type_id = " + serviceTypeId + ","; - updateClause += " remaining_qty = " + remainingQuantity + ","; + updateClause += " remaining_qty = get_remaining_qty_fun('" + POnum + "'," + lineItemNo + ")"; if (!updateClause.equalsIgnoreCase(" SET ")) { sql = sql + trimLastCharacter(updateClause, ",") + whereClause; @@ -199,12 +199,12 @@ public class SqlDAO extends DAO { public void createPOMaster(String PONum, String contractNum, String PODate, Double contractAmt, String customerId, String astuteProjectNumber, String title) throws AstuteException, ParseException { try { - Date date= (Date) new SimpleDateFormat("yyyy/mm/dd").parse(PODate); - + java.util.Date date= new SimpleDateFormat("yyyy-mm-dd").parse(PODate); + java.sql.Date poDate = new java.sql.Date(date.getTime()); CallableStatement stmt = conn.prepareCall("{call create_PO(?,?,?,?,?,?,?)}"); stmt.setString(1, PONum); stmt.setString(2, contractNum); - stmt.setDate(3, date); + stmt.setDate(3, poDate); stmt.setDouble(4, contractAmt); stmt.setString(5, customerId); stmt.setString(6, astuteProjectNumber); @@ -218,6 +218,7 @@ public class SqlDAO extends DAO { public void createPODetail(String POnum, int lineItemNo, String serviceDesc, int feeTypeId, Double qty, Double fee, int serviceTypeId, Double remainingQuantity) throws AstuteException { try { + // TODO remainingQuantity not used, need to take it out from signature System.out.println("Calling create_po_detail Procedure"); System.out.println("POnum is " + POnum); CallableStatement stmt = conn.prepareCall("{call create_po_detail(?,?,?,?,?,?,?,?)}"); @@ -228,7 +229,7 @@ public class SqlDAO extends DAO { stmt.setDouble(5, qty); stmt.setDouble(6, fee); stmt.setInt(7, serviceTypeId); - stmt.setDouble(8, remainingQuantity); + stmt.setDouble(8, qty); stmt.executeUpdate(); } catch (SQLException e) { @@ -400,34 +401,44 @@ public class SqlDAO extends DAO { } } + public void updateRemainingQty(String poNum, int lineItemNo) throws AstuteException { + try { + String sql = " UPDATE PO SET remaining_qty = get_remaining_qty_fun('" + poNum + "'," + lineItemNo + ")"; + + 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 updateInvRemainingQty(String invNum, int poLineItemNo) throws AstuteException { + try { + String sql = " UPDATE PO SET remaining_qty = get_inv_remaining_qty_fun('" + invNum + "'," + poLineItemNo + ")"; + 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 updateInvoiceDetail(String invoiceNum, int lineItemNum, int POLineItemNum, int serviceTypeId, String desc, double qty, double fee, int feeTypeId)throws AstuteException { try { String sql = "UPDATE INVOICE_DETAIL "; String updateClause = " SET "; String whereClause = ""; if(invoiceNum == null || invoiceNum.isEmpty() || lineItemNum < 0) { - throw new AstuteException(0, "PO Number should not be null and line item number must be greater than 0."); + throw new AstuteException(0, "Invoice Number should not be null and line item number must be greater than 0."); } else { whereClause = " WHERE UPPER(inv_num) = '" + invoiceNum.toUpperCase() + "' AND line_item_num = " + lineItemNum; } - if(POLineItemNum >0) { - updateClause += " PO_line_item_num = " + POLineItemNum + ","; - } - if(serviceTypeId >0) { - updateClause += " service_type_id = " + serviceTypeId + ","; - } - if(desc != null && !desc.isEmpty()) { - updateClause += " description = '" + desc + "',"; - } - if(qty >0) { - updateClause += " qty = " + qty + ","; - } - if(fee > 0) { - updateClause += " fee = " + fee + ","; - } - if(feeTypeId > 0) { - updateClause += " fee_type_id = " + feeTypeId + ","; - } + updateClause += " service_type_id = " + serviceTypeId + ","; + updateClause += " description = '" + desc + "',"; + updateClause += " qty = " + qty + ","; + updateClause += " fee = " + fee + ","; + updateClause += " fee_type_id = " + feeTypeId + ","; if (!updateClause.equalsIgnoreCase(" SET ")) { sql = sql + trimLastCharacter(updateClause,",") + whereClause; @@ -437,6 +448,7 @@ public class SqlDAO extends DAO { System.out.println(sql); Statement stmt = conn.createStatement(); stmt.executeUpdate(sql); + updateInvRemainingQty(invoiceNum, POLineItemNum); } catch (SQLException e) { e.printStackTrace(); throw new AstuteException(DB_ERROR,e.getMessage()); @@ -477,6 +489,7 @@ public class SqlDAO extends DAO { stmt.setDouble(7, fee); stmt.setInt(8, feeTypeId); stmt.executeUpdate(); + updateInvRemainingQty(invoiceNum, POLineItemNum); } catch (SQLException e) { e.printStackTrace(); throw new AstuteException(DB_ERROR,e.getMessage()); @@ -488,7 +501,7 @@ public class SqlDAO extends DAO { if (InvoiceNumber == null || InvoiceNumber.isEmpty()) { throw new AstuteException(0, "Invoice Number should not be null!"); } else { - String sql = "UPDATE INVOICE SET INV_STATUS = 2 WHERE UPPER(INV_NO) = 'UPPER(" + InvoiceNumber + ")'"; + String sql = "UPDATE INVOICE SET INV_STATUS = 2 WHERE UPPER(INV_NO) = 'UPPER('" + InvoiceNumber + "')"; Statement stmt = conn.createStatement(); stmt.executeUpdate(sql); } @@ -503,7 +516,7 @@ public class SqlDAO extends DAO { if (InvoiceNumber == null || InvoiceNumber.isEmpty()) { throw new AstuteException(0, "Invoice Number should not be null!"); } else { - String sql = "UPDATE INVOICE SET INV_STATUS = 3 WHERE UPPER(INV_NO) = 'UPPER(" + InvoiceNumber + ")'"; + String sql = "UPDATE INVOICE SET INV_STATUS = 3 WHERE UPPER(INV_NO) = 'UPPER('" + InvoiceNumber + "')"; Statement stmt = conn.createStatement(); stmt.executeUpdate(sql); } @@ -551,8 +564,8 @@ public class SqlDAO extends DAO { int zip = rs.getInt(8); int ziplast4 = rs.getInt(9); String email = rs.getString(10); - Long phone = rs.getLong(11); - Long fax = rs.getLong(12); + String phone = rs.getString(11); + String fax = rs.getString(12); Customer customer = new Customer(customerID, customerName,billToDept, add1, add2, city, state, zip, ziplast4, email, phone, fax); customers.add(customer); } @@ -563,7 +576,7 @@ public class SqlDAO extends DAO { } } - public String createCustomer(String customerId, String customerName, String billToDept, String add1, String add2, String city, String state, int zip, int ziplast4, String email, Long phone, Long fax) throws AstuteException { + public String createCustomer(String customerId, String customerName, String billToDept, String add1, String add2, String city, String state, int zip, int ziplast4, String email, String phone, String fax) throws AstuteException { try { CallableStatement stmt = conn.prepareCall("{? = call create_customer_fun(?,?,?,?,?,?,?,?,?,?,?,?)}"); stmt.registerOutParameter(1, Types.INTEGER); @@ -577,8 +590,8 @@ public class SqlDAO extends DAO { stmt.setInt(9, zip); stmt.setInt(10, ziplast4); stmt.setString(11, email); - stmt.setLong(12, phone); - stmt.setLong(13, fax); + stmt.setString(12, phone); + stmt.setString(13, fax); stmt.executeUpdate(); String customerIdOut = stmt.getString(1); return customerIdOut; @@ -588,7 +601,7 @@ public class SqlDAO extends DAO { } } public void updateCustomer( String customerId, String customerName, String billToDept, String add1, String - add2, String city, String state, int zip, int ziplast4, String email,Long phone, Long fax) throws + add2, String city, String state, int zip, int ziplast4, String email,String phone, String fax) throws AstuteException { try { String sql = "UPDATE CUSTOMER "; @@ -609,8 +622,8 @@ public class SqlDAO extends DAO { updateClause = updateClause + " zip = " + zip + ","; updateClause = updateClause + " zip_last_4 = " + ziplast4 + ","; updateClause = updateClause + " email = '" + email + "',"; - updateClause = updateClause + " phone = " + phone + ","; - updateClause = updateClause + " fax = " + fax + ","; + updateClause = updateClause + " phone = '" + phone + "',"; + updateClause = updateClause + " fax = '" + fax + "',"; if (!updateClause.equalsIgnoreCase(" SET ")) { sql = sql + trimLastCharacter(updateClause, ",") + whereClause;