* Added delete methods for invoicedetail and podetail

* Added check for invoice payment - should not exceed outstanding invoice balance
This commit is contained in:
Gopi Katwala 2019-07-16 13:00:50 -04:00
parent 22d345cfc1
commit c402bb00f2
6 changed files with 127 additions and 3 deletions

View File

@ -97,6 +97,10 @@ public abstract class DAO {
public abstract void updatePODetail(String POnum, int lineItemNo, String serviceDesc, int feeTypeId, Double qty, Double fee, int serviceTypeId, Double remainingQuantity) throws AstuteException; public abstract void updatePODetail(String POnum, int lineItemNo, String serviceDesc, int feeTypeId, Double qty, Double fee, int serviceTypeId, Double remainingQuantity) throws AstuteException;
public abstract void deletePODetail(String POnum, int lineItemNo) throws AstuteException;
public abstract boolean isPOFinalized(String POnum) throws AstuteException;
public abstract void createPOMaster(String PONum, String contractNum, String PODate, Double contractAmt, String customerId, String astuteProjectNumber, String title, String notes) throws AstuteException, ParseException; public abstract void createPOMaster(String PONum, String contractNum, String PODate, Double contractAmt, String customerId, String astuteProjectNumber, String title, String notes) throws AstuteException, ParseException;
public abstract void createPODetail(String POnum, int lineItemNo, String serviceDesc, int feeTypeId, Double qty, Double fee, int serviceTypeId, Double remainingQuantity) throws AstuteException; public abstract void createPODetail(String POnum, int lineItemNo, String serviceDesc, int feeTypeId, Double qty, Double fee, int serviceTypeId, Double remainingQuantity) throws AstuteException;
@ -125,6 +129,8 @@ public abstract class DAO {
public abstract void updateInvoiceDetail(String invoiceNum, int lineItemNum, int POLineItemNum, int serviceTypeId, String desc, double qty, double fee, int feeTypeId) throws AstuteException; public abstract void updateInvoiceDetail(String invoiceNum, int lineItemNum, int POLineItemNum, int serviceTypeId, String desc, double qty, double fee, int feeTypeId) throws AstuteException;
public abstract void deleteInvoiceDetail(String invoiceNum, int lineItemNum, int poLineItemNum) throws AstuteException;
public abstract void createInvoiceMaster(String invoiceNum, String invoiceDate, String PONum, int pmtStatus, Double billAmt, String specialNotes, String certification, int invoiceStatus) throws AstuteException, ParseException; public abstract void createInvoiceMaster(String invoiceNum, String invoiceDate, String PONum, int pmtStatus, Double billAmt, String specialNotes, String certification, int invoiceStatus) throws AstuteException, ParseException;
public abstract void createInvoiceDetail(String invoiceNum, int lineItemNum, int POLineItemNum, int serviceTypeId, String desc, double qty, double fee, int feeTypeId) throws AstuteException; public abstract void createInvoiceDetail(String invoiceNum, int lineItemNum, int POLineItemNum, int serviceTypeId, String desc, double qty, double fee, int feeTypeId) throws AstuteException;
@ -143,6 +149,8 @@ public abstract class DAO {
public abstract List<PaymentStatus> getPaymentStatuses() throws AstuteException; public abstract List<PaymentStatus> getPaymentStatuses() throws AstuteException;
public abstract double getOutstandingBalance(String InvoiceNumber) throws AstuteException;
public abstract List<Customer> getCustomers(String customerId) throws AstuteException; public abstract List<Customer> getCustomers(String customerId) throws AstuteException;
public abstract Customer getCustomer(String poNumber) throws AstuteException; public abstract Customer getCustomer(String poNumber) throws AstuteException;
@ -153,6 +161,7 @@ public abstract class DAO {
public abstract void deleteCustomer(String customerId) throws AstuteException; public abstract void deleteCustomer(String customerId) throws AstuteException;
/*=============================== Customer Contacts Methods =============================================== /*=============================== Customer Contacts Methods ===============================================
*/ */
public abstract List<CustomerContact> getCustomerContacts(String customerId) throws AstuteException; public abstract List<CustomerContact> getCustomerContacts(String customerId) throws AstuteException;

View File

@ -172,7 +172,6 @@ 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 { public void updatePODetail(String POnum, int lineItemNo, String serviceDesc, int feeTypeId, Double qty, Double fee, int serviceTypeId, Double remainingQuantity) throws AstuteException {
try { try {
// remainingQuantity is not used , need to take it out from signature eventually // remainingQuantity is not used , need to take it out from signature eventually
@ -217,6 +216,53 @@ public class SqlDAO extends DAO {
} }
} }
public boolean isPOFinalized(String POnum) throws AstuteException {
boolean flag = false;
int finalIndicator = 0;
String sql = "SELECT final from PO ";
try {
Statement stmt = conn.createStatement();
if (POnum == null || POnum.isEmpty()) {
throw new AstuteException(0, "PO Number should not be null.");
}
sql+= "WHERE UPPER(PO_num) = '" + POnum.toUpperCase() + "'";
System.out.println(sql);
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
finalIndicator = rs.getInt(1);
}
if (finalIndicator > 0) {
flag = true;
}
return flag;
} catch (SQLException e) {
e.printStackTrace();
throw new AstuteException(DB_ERROR,e.getMessage());
}
}
public void deletePODetail(String POnum, int lineItemNo) throws AstuteException {
try {
if (!isPOFinalized(POnum)) {
throw new AstuteException(0, "PO " + POnum + " is already finalyzed and can not be changed.");
}
if (POnum == null || POnum.isEmpty() || lineItemNo <= 0) {
throw new AstuteException(0, "PO Number should not be null and line item number must be greater than 0.");
}
String sql = "DELETE FROM PO_DETAIL ";
sql += " WHERE UPPER(PO_num) = '" + POnum.toUpperCase() + "' AND line_item_no = " + lineItemNo;
System.out.println(sql);
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
updateRemainingQty(POnum,null, lineItemNo);
updateContractAmount(POnum);
} catch (SQLException e) {
e.printStackTrace();
throw new AstuteException(DB_ERROR,e.getMessage());
}
}
public void createPOMaster(String PONum, String contractNum, String PODate, Double contractAmt, String customerId, String astuteProjectNumber, String title, String notes) throws AstuteException, ParseException { public void createPOMaster(String PONum, String contractNum, String PODate, Double contractAmt, String customerId, String astuteProjectNumber, String title, String notes) throws AstuteException, ParseException {
try { try {
java.util.Date date = null; java.util.Date date = null;
@ -415,6 +461,22 @@ public class SqlDAO extends DAO {
} }
} }
public double getOutstandingBalance(String InvoiceNumber) throws AstuteException {
double balance;
try {
System.out.println("Calling delete_invoice DB function");
CallableStatement stmt = conn.prepareCall("{? = call get_outstanding_inv_balance(?)}");
stmt.registerOutParameter(1, Types.VARCHAR);
stmt.setString(2, InvoiceNumber);
stmt.executeUpdate();
balance = stmt.getDouble(1);
return balance;
} catch (SQLException e) {
e.printStackTrace();
throw new AstuteException(DB_ERROR,e.getMessage());
}
};
public GeneratedInvoice getGeneratedInvoice(String invoiceNumber) throws AstuteException{ public GeneratedInvoice getGeneratedInvoice(String invoiceNumber) throws AstuteException{
GeneratedInvoice generatedInvoice = null; GeneratedInvoice generatedInvoice = null;
Invoice invoice = getInvoiceMaster(invoiceNumber, 0).get(0); Invoice invoice = getInvoiceMaster(invoiceNumber, 0).get(0);
@ -554,12 +616,12 @@ public class SqlDAO extends DAO {
if (!result.equals("SUCCESS")) { if (!result.equals("SUCCESS")) {
throw new AstuteException(DB_ERROR,result); throw new AstuteException(DB_ERROR,result);
} }
updateAllRemainingQuantities(invoiceNum);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
throw new AstuteException(DB_ERROR,e.getMessage()); throw new AstuteException(DB_ERROR,e.getMessage());
} }
} }
public void updateAllRemainingQuantities(String invNo) throws AstuteException { public void updateAllRemainingQuantities(String invNo) throws AstuteException {
try { try {
@ -622,6 +684,27 @@ public class SqlDAO extends DAO {
throw new AstuteException(DB_ERROR,e.getMessage()); throw new AstuteException(DB_ERROR,e.getMessage());
} }
} }
public void deleteInvoiceDetail(String invoiceNum, int lineItemNum, int poLineItemNum)throws AstuteException {
try {
String sql = "DELETE FROM INVOICE_DETAIL ";
String whereClause = "";
if(invoiceNum == null || invoiceNum.isEmpty() || lineItemNum < 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;
}
System.out.println(sql);
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
updateAllRemainingQuantities(invoiceNum);
} catch (SQLException e) {
e.printStackTrace();
throw new AstuteException(DB_ERROR,e.getMessage());
}
}
public void createInvoiceMaster(String invoiceNum, String invoiceDate, String PONum, int pmtStatus, Double billAmt, String specialNotes, String certification, int invoiceStatus) throws AstuteException, ParseException { public void createInvoiceMaster(String invoiceNum, String invoiceDate, String PONum, int pmtStatus, Double billAmt, String specialNotes, String certification, int invoiceStatus) throws AstuteException, ParseException {
try { try {
java.util.Date date = null; java.util.Date date = null;
@ -1208,6 +1291,9 @@ public class SqlDAO extends DAO {
public void updateInvoicePayment(String invoiceNum, int invoicePaymentId, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkNo, String transactionNo) throws AstuteException { public void updateInvoicePayment(String invoiceNum, int invoicePaymentId, int invoicePaymentTypeId, Double paymentAmount, Date paymentDate, String checkNo, String transactionNo) throws AstuteException {
try { try {
if (paymentAmount > getOutstandingBalance(invoiceNum) ) {
throw new AstuteException(DB_ERROR,"Payment amount can't be greater than outstanding balance for Invoice " + invoiceNum);
}
String sql = "UPDATE INVOICE_PAYMENT "; String sql = "UPDATE INVOICE_PAYMENT ";
String updateClause = " SET "; String updateClause = " SET ";
String whereClause = ""; String whereClause = "";

View File

@ -79,6 +79,16 @@ public class InvoiceResource {
request.getDesc(), request.getQty(), request.getFee(), request.getFeeTypeId()); request.getDesc(), request.getQty(), request.getFee(), request.getFeeTypeId());
return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse(); return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse();
} }
@Path("/detail/{InvoiceNum}/{lineItemNum}")
@DELETE
public Response deleteInvoiceDetail(@QueryParam("sessionId") String sessionId, @PathParam("InvoiceNum") String InvoiceNum, @PathParam("lineItemNum") int lineItemNum, @QueryParam("poLineItemNum") int poLineItemNum)
throws AstuteException {
authService.authenticateSession(sessionId);
service.deleteInvoiceDetail(InvoiceNum, lineItemNum,poLineItemNum);
return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse();
}
@POST @POST
public Response createInvoiceMaster(@QueryParam("sessionId") String sessionId, InvoiceMasterRequest request) public Response createInvoiceMaster(@QueryParam("sessionId") String sessionId, InvoiceMasterRequest request)
throws AstuteException, ParseException { throws AstuteException, ParseException {

View File

@ -63,6 +63,15 @@ public class POResource {
return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse(); return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse();
} }
@Path("/detail/{PONum}/{lineItemNo}")
@DELETE
public Response deletePODetail(@QueryParam("sessionId") String sessionId, @PathParam("PONum") String PONum, @PathParam("lineItemNo") int lineItemNo)
throws AstuteException {
authService.authenticateSession(sessionId);
POService.deletePODetail(PONum, lineItemNo);
return new ApiResponse(ApiResponse.UPDATE_ACCESS_SUCESS).toResponse();
}
@POST @POST
public Response createPOMaster(@QueryParam("sessionId") String sessionId, POMasterRequest request) public Response createPOMaster(@QueryParam("sessionId") String sessionId, POMasterRequest request)
throws AstuteException, ParseException { throws AstuteException, ParseException {

View File

@ -43,6 +43,12 @@ public class InvoiceService extends Service{
qty, fee, feeTypeId); qty, fee, feeTypeId);
} }
public void deleteInvoiceDetail(String invoiceNum, int lineItemNum, int poLineItemNum)
throws AstuteException {
getDao().deleteInvoiceDetail(invoiceNum, lineItemNum, poLineItemNum);
}
public void createInvoiceMaster(String invoiceNum, String invoiceDate, String PONum, public void createInvoiceMaster(String invoiceNum, String invoiceDate, String PONum,
int pmtStatus, Double billAmt, String specialNotes, String certification, int invoiceStatus) int pmtStatus, Double billAmt, String specialNotes, String certification, int invoiceStatus)
throws AstuteException, ParseException { throws AstuteException, ParseException {

View File

@ -59,6 +59,10 @@ public class POService extends Service{
getDao().finalizePO(PONum); getDao().finalizePO(PONum);
} }
public void deletePODetail(String PONum, int lineItemNo) throws AstuteException {
getDao().deletePODetail(PONum, lineItemNo);
}
public List<ServiceType> getServiceTypes() throws AstuteException { public List<ServiceType> getServiceTypes() throws AstuteException {
return getDao().getServiceTypes(); return getDao().getServiceTypes();
} }