Commit 257731bd authored by prane's avatar prane

Used Big decimal instead of double for amounts in getData() method and rounded by 3 decimal.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@194309 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 6bd59d3b
......@@ -7,7 +7,7 @@ import java.util.*;
import java.lang.*;
import javax.ejb.*;
import org.w3c.dom.*;
import java.math.BigDecimal;
import javax.xml.parsers.*;
import java.util.HashMap;
import java.rmi.RemoteException;
......@@ -245,14 +245,21 @@ Put a validation chq amount in filter and total of details matches in case heade
String chequeNo = "";
String reasDetail = "";
String groupCode = "";
double totAmt = 0.0;
//Pavan R 11dec18[to use Big decimal instead of double]
/*double totAmt = 0.0;
double balAmt = 0.0;
double adjAmt = 0.0;
double adjustedAmt = 0.0;
double invAmt = 0.0;
double chqAmount = 0.0;
double custRefAmt = 0.0;
double custRefAmt = 0.0;*/
BigDecimal totAmt = new BigDecimal(0.0);
BigDecimal balAmt = new BigDecimal(0.0);
BigDecimal adjAmt = new BigDecimal(0.0);
BigDecimal adjustedAmt = new BigDecimal(0.0);
BigDecimal invAmt = new BigDecimal(0.0);
BigDecimal chqAmount = new BigDecimal(0.0);
BigDecimal custRefAmt = new BigDecimal(0.0);
Timestamp tranDate = null;
Timestamp chequeDate = null;
......@@ -267,23 +274,29 @@ Put a validation chq amount in filter and total of details matches in case heade
conn = getConnection();
}*/
sdf=new SimpleDateFormat(genericUtility.getApplDateFormat());
DatabaseMetaData dbmd = conn.getMetaData();
//DatabaseMetaData dbmd = conn.getMetaData();
suggestAdj = genericUtility.getColumnValue("suggest_adj",headerDom);
if(suggestAdj == null || suggestAdj.trim().length() == 0 || "null".equals(suggestAdj))
{
suggestAdj = "N";
}
siteCode = genericUtility.getColumnValue("site_code",headerDom);
System.out.println("siteCode------>"+ siteCode);
System.out.println("siteCode------>"+ siteCode+"suggestAdj----->"+suggestAdj);
System.out.println("Serialize Dom["+genericUtility.serializeDom(headerDom));
StringBuffer xmlBuffStr = new StringBuffer("<?xml version = \"1.0\"?>");
NodeList parentNodeList = headerDom.getElementsByTagName("Detail1");
Node parentNode = parentNodeList.item(0);
objName = getObjName(parentNode);
if("generate_receipt_process".equals(objName))
System.out.println("Inside getData ObjName::["+objName+"]");
if("generate_receipt_process".equals(objName))
{
xmlBuffStr.append("<DocumentRoot>");
xmlBuffStr.append("<description>").append("Datawindow Root").append("</description>");
xmlBuffStr.append("<group0>");
xmlBuffStr.append("<description>").append("Group0 description").append("</description>");
xmlBuffStr.append("<Header0>");
xmlBuffStr.append("<Header0>");
suggestAdj = "Y";
}
if(siteCode == null || siteCode.trim().length() == 0)
......@@ -382,7 +395,7 @@ Put a validation chq amount in filter and total of details matches in case heade
dueDateTo = java.sql.Timestamp.valueOf(sdueDate + " 00:00:00");
System.out.println("Due Date **..........................**:"+dueDate);
suggestAdj = genericUtility.getColumnValue("suggest_adj",headerDom);
//suggestAdj = genericUtility.getColumnValue("suggest_adj",headerDom);
System.out.println("suggest_adj........["+suggestAdj+"]");
HashMap<String, ArrayList<ReceiptBean>> custGrpMap = new HashMap<String, ArrayList<ReceiptBean>>();
......@@ -417,22 +430,22 @@ Put a validation chq amount in filter and total of details matches in case heade
tranSer = checkNull(rs.getString("TRAN_SER"));
custRefNo = checkNull(rs.getString("CUST_REF_NO"));
tranDate = rs.getTimestamp("REF_DATE");
totAmt = rs.getDouble("TOT_AMT");
balAmt = rs.getDouble(4);
adjAmt = rs.getDouble(4);
adjustedAmt = rs.getDouble("ADJ_AMT");
invAmt = rs.getDouble(4);
totAmt = new BigDecimal(rs.getDouble("TOT_AMT"));//rs.getDouble("TOT_AMT");
balAmt = new BigDecimal(rs.getDouble(4));//rs.getDouble(4);
adjAmt = new BigDecimal(rs.getDouble(4));//rs.getDouble(4);
adjustedAmt = new BigDecimal(rs.getDouble("ADJ_AMT"));//rs.getDouble("ADJ_AMT");
invAmt = new BigDecimal(rs.getDouble(4));//rs.getDouble(4);
reasCode = checkNull(rs.getString("REAS_CODE"));
custName = checkNull(rs.getString("CUST_NAME"));
custCode = checkNull(rs.getString("CUST_CODE"));
bankCode = checkNull(rs.getString("BANK_CODE"));
chequeDate = rs.getTimestamp("TRAN_DATE");
chequeNo = checkNull(rs.getString("CHEQUE_NO"));
chqAmount = rs.getDouble("CHQ_AMOUNT");
chqAmount = new BigDecimal(rs.getDouble("CHQ_AMOUNT"));//rs.getDouble("CHQ_AMOUNT");
custRefDate= rs.getTimestamp("CUST_REF_DATE");
dueDate = rs.getTimestamp("DUE_DATE");
reasDetail = checkNull(rs.getString("REAS_DETAIL"));
custRefAmt = rs.getDouble("CUST_REF_AMT");
custRefAmt = new BigDecimal(rs.getDouble("CUST_REF_AMT"));//rs.getDouble("CUST_REF_AMT");
//Added by Pavan R on 24MAY18 [F18BGTP001]- "Suggest adjustments" in Automatic AR settlement filter screen.
groupCode = checkNull(rs.getString("GROUP_CODE"));
......@@ -495,11 +508,11 @@ Put a validation chq amount in filter and total of details matches in case heade
System.out.println(sdf.format(rs.getTimestamp(3)));
retTabSepStrBuff.append("<tran_date>").append("<![CDATA[" +sdf.format(tranDate) +"]]>").append("</tran_date>");
}
retTabSepStrBuff.append("<tot_amt>").append("<![CDATA["+ totAmt +"]]>").append("</tot_amt>");
retTabSepStrBuff.append("<bal_amt>").append("<![CDATA[" +Math.abs(balAmt) +"]]>").append("</bal_amt>");
retTabSepStrBuff.append("<adj_amt>").append("<![CDATA[" + adjAmt +"]]>").append("</adj_amt>");
retTabSepStrBuff.append("<adjusted_amt>").append("<![CDATA["+ adjustedAmt +"]]>").append("</adjusted_amt>");
retTabSepStrBuff.append("<inv_amt>").append("<![CDATA[" + invAmt +"]]>").append("</inv_amt>");
retTabSepStrBuff.append("<tot_amt>").append("<![CDATA["+ rounded(totAmt,3) +"]]>").append("</tot_amt>");
retTabSepStrBuff.append("<bal_amt>").append("<![CDATA[" +rounded(balAmt,3) +"]]>").append("</bal_amt>");
retTabSepStrBuff.append("<adj_amt>").append("<![CDATA[" + rounded(adjAmt,3) +"]]>").append("</adj_amt>");
retTabSepStrBuff.append("<adjusted_amt>").append("<![CDATA["+ rounded(adjustedAmt,3) +"]]>").append("</adjusted_amt>");
retTabSepStrBuff.append("<inv_amt>").append("<![CDATA[" + rounded(invAmt,3) +"]]>").append("</inv_amt>");
if ( reasCode == null || reasCode.trim().length() == 0)
{
retTabSepStrBuff.append("<reas_code>").append("<![CDATA[]]>").append("</reas_code>");
......@@ -521,7 +534,7 @@ Put a validation chq amount in filter and total of details matches in case heade
}else{
retTabSepStrBuff.append("<cheque_no>").append("<![CDATA[" +(chequeNo==null?" ":chequeNo.trim()) +"]]>").append("</cheque_no>");
}
retTabSepStrBuff.append("<chq_amount>").append("<![CDATA["+chqAmount+"]]>").append("</chq_amount>");
retTabSepStrBuff.append("<chq_amount>").append("<![CDATA["+rounded(chqAmount,3)+"]]>").append("</chq_amount>");
if(custRefDate == null)
{
retTabSepStrBuff.append("<cust_ref_date>").append("<![CDATA[]]>").append("</cust_ref_date>");
......@@ -540,7 +553,7 @@ Put a validation chq amount in filter and total of details matches in case heade
}else{
retTabSepStrBuff.append("<reas_detail>").append("<![CDATA["+ reasDetail +"]]>").append("</reas_detail>");
}
retTabSepStrBuff.append("<cust_ref_amt>").append("<![CDATA["+ custRefAmt +"]]>").append("</cust_ref_amt>");
retTabSepStrBuff.append("<cust_ref_amt>").append("<![CDATA["+ rounded(custRefAmt,3) +"]]>").append("</cust_ref_amt>");
retTabSepStrBuff.append("<remarks>").append("<![CDATA["+remarks+"]]>").append("</remarks>");
retTabSepStrBuff.append("</Detail2>");
......@@ -563,6 +576,7 @@ Put a validation chq amount in filter and total of details matches in case heade
int gCnt = 1;
for (ArrayList<ReceiptBean> templist : custGrpMap.values())
{
BigDecimal tmpVal = new BigDecimal(-1);
System.out.println("Global dom count["+gCnt+"]");
selectedList = new ArrayList<ReceiptBean>();
Collections.sort(templist, ReceiptBean.receiptComparator);
......@@ -570,7 +584,9 @@ Put a validation chq amount in filter and total of details matches in case heade
ArrayList<ReceiptBean> posList = new ArrayList<ReceiptBean>();
ArrayList<ReceiptBean> negList = new ArrayList<ReceiptBean>();
System.out.println("^^^^^^^templist Size["+ templist.size() + "]^^^^^^^^^^");
double totNegAmt = 0.0, totPosAmt = 0.0;
//double totNegAmt = 0.0, totPosAmt = 0.0;
BigDecimal totNegAmt = new BigDecimal(0.0);
BigDecimal totPosAmt = new BigDecimal(0.0);
// Storing Positive amounts List as posList
for (int i = 0; i < templist.size(); i++) {
......@@ -580,9 +596,11 @@ Put a validation chq amount in filter and total of details matches in case heade
adjAmt = rcpBean.getAdjAmt();
adjustedAmt = rcpBean.getAdjustedAmt();
invAmt = rcpBean.getInvAmt();
if (balAmt > 0)
//if (balAmt > 0)
if ((balAmt.compareTo(BigDecimal.ZERO) == 1))
{
totPosAmt = totPosAmt + balAmt;
//totPosAmt = totPosAmt + balAmt;
totPosAmt = totPosAmt.add(balAmt);
posList.add(rcpBean);
}
}
......@@ -594,16 +612,19 @@ Put a validation chq amount in filter and total of details matches in case heade
adjAmt = rcpBean.getAdjAmt();
adjustedAmt = rcpBean.getAdjustedAmt();
invAmt = rcpBean.getInvAmt();
if (balAmt < 0)
//if (balAmt < 0)
if ((balAmt.compareTo(BigDecimal.ZERO) == -1))
{
totNegAmt = getRequiredDecimal(totNegAmt, 3) + balAmt;
//totNegAmt = getRequiredDecimal(totNegAmt, 3) + balAmt;
totNegAmt = rounded(totNegAmt.add(balAmt),3);
negList.add(rcpBean);
}
}
System.out.println("***Total Amount Positive[" + totPosAmt + "]Negative[" + totNegAmt + "]");
System.out.println("****POSListSize[" + posList.size()+ "]****NEGListSize[" + negList.size() + "]");
System.out.println("****POSListSize[" + posList.size()+ "]****NEGListSize[" + negList.size() + "]");
// If positive Amt is greater than negative
if (totPosAmt > totNegAmt*(-1))
//if (totPosAmt > totNegAmt*(-1))
if (totPosAmt.compareTo(totNegAmt.multiply(tmpVal)) == 1)
{
System.out.println("544::totNegAmt["+totNegAmt+"]");
// If positive Amt is greater then select all negative and match and select value with positive
......@@ -616,26 +637,33 @@ Put a validation chq amount in filter and total of details matches in case heade
for (int i = 0; i < posList.size(); i++)
{
ReceiptBean posBean = posList.get(i);
double balsAmt = posBean.getBalAmt();
double temp = totNegAmt;
totNegAmt = getRequiredDecimal(totNegAmt,3) + balsAmt;
//double balsAmt = posBean.getBalAmt();
BigDecimal balsAmt = posBean.getBalAmt();
//double temp = totNegAmt;
BigDecimal temp = totNegAmt;
//totNegAmt = getRequiredDecimal(totNegAmt,3) + balsAmt;
totNegAmt = rounded(totNegAmt.add(balsAmt),3);
System.out.println("555::totNegAmt["+totNegAmt+"]balsAmt["+balsAmt+"]cnt["+i+"]");
posBean.setIsSelected("Y");
posList.set(i, posBean);
if (totNegAmt > 0) //to updated the to be adjusted amt
//if (totNegAmt > 0) //to updated the to be adjusted amt
if ((totNegAmt.compareTo(BigDecimal.ZERO) == 1))
{
System.out.println("before break...totPosAmt::"+totNegAmt);
ReceiptBean posBean2 = posList.get(i);
posBean2.setAdjAmt(temp*(-1));
//posBean2.setAdjAmt(temp*(-1));
posBean2.setAdjAmt(temp.multiply(tmpVal));
posList.set(i, posBean2);
break;
}else if (totNegAmt == 0){
}//else if (totNegAmt == 0){
else if (totNegAmt.compareTo(BigDecimal.ZERO) == 0){
System.out.println("only break....!!!");
break;
}
}
} // If negative Amt is greater than positive
else if (totNegAmt*(-1) >= totPosAmt)
//else if (totNegAmt*(-1) >= totPosAmt)
else if ((totNegAmt.multiply(tmpVal)).compareTo(totPosAmt) == 1 || (totNegAmt.multiply(tmpVal)).compareTo(totPosAmt) == 0)
{
// If negative Amt is greater then select all positive and match and select value with negative
for (int i = 0; i < posList.size(); i++)
......@@ -647,20 +675,24 @@ Put a validation chq amount in filter and total of details matches in case heade
for (int i = 0; i < negList.size(); i++)
{
ReceiptBean negBean = negList.get(i);
double balsAmt = negBean.getBalAmt();
double temp = totPosAmt;
totPosAmt = getRequiredDecimal(totPosAmt, 3) + balsAmt;
//double balsAmt = negBean.getBalAmt();
BigDecimal balsAmt = negBean.getBalAmt();
//double temp = totPosAmt;
BigDecimal temp = totPosAmt;
//totPosAmt = getRequiredDecimal(totPosAmt, 3) + balsAmt;
totPosAmt = rounded(totPosAmt.add(balsAmt),3);
System.out.println("589::totNegAmt["+totPosAmt+"]Negative amt["+balsAmt+"]cnt["+i+"]");
negBean.setIsSelected("Y");
negList.set(i, negBean);
if (totPosAmt < 0) //to updated the to be adjusted amt
//if (totPosAmt < 0) //to updated the to be adjusted amt
if (totPosAmt.compareTo(BigDecimal.ZERO)== -1)
{
System.out.println("before break...totPosAmt::"+totPosAmt);
ReceiptBean negBean2 = negList.get(i);
negBean2.setAdjAmt(temp*(-1));
negBean2.setAdjAmt(temp.multiply(tmpVal));
negList.set(i, negBean2);
break;
}else if(totPosAmt == 0)
}else if(totPosAmt.compareTo(BigDecimal.ZERO) == 0)
{
System.out.println("only break...");
break;
......@@ -3036,14 +3068,22 @@ conn = getConnection();
String reasDetail = "";
String groupCode = "";
String filterChqNo = "";
double totAmt = 0.0;
/*double totAmt = 0.0;
double balAmt = 0.0;
double adjAmt = 0.0;
double adjustedAmt = 0.0;
double invAmt = 0.0;
double chqAmount = 0.0;
double custRefAmt = 0.0;
double totAmount = 0.0;
double totAmount = 0.0;*/
BigDecimal totAmt = new BigDecimal(0.0);
BigDecimal balAmt = new BigDecimal(0.0);
BigDecimal adjAmt = new BigDecimal(0.0);
BigDecimal adjustedAmt = new BigDecimal(0.0);
BigDecimal invAmt = new BigDecimal(0.0);
BigDecimal chqAmount = new BigDecimal(0.0);
BigDecimal custRefAmt = new BigDecimal(0.0);
BigDecimal totAmount = new BigDecimal(0.0);
Timestamp tranDate = null;
Timestamp chequeDate = null;
......@@ -3095,11 +3135,12 @@ conn = getConnection();
}else{
xmlBuff.append("<tran_date>").append("<![CDATA[" +sdf.format(tranDate) +"]]>").append("</tran_date>");
}
xmlBuff.append("<tot_amt>").append("<![CDATA["+ totAmt +"]]>").append("</tot_amt>");
xmlBuff.append("<bal_amt>").append("<![CDATA[" +Math.abs(balAmt) +"]]>").append("</bal_amt>");
xmlBuff.append("<adj_amt>").append("<![CDATA[" + adjAmt +"]]>").append("</adj_amt>");
xmlBuff.append("<adjusted_amt>").append("<![CDATA["+ adjustedAmt +"]]>").append("</adjusted_amt>");
xmlBuff.append("<inv_amt>").append("<![CDATA[" + invAmt +"]]>").append("</inv_amt>");
xmlBuff.append("<tot_amt>").append("<![CDATA["+ rounded(totAmt,3) +"]]>").append("</tot_amt>");
//xmlBuff.append("<bal_amt>").append("<![CDATA[" +Math.abs(balAmt) +"]]>").append("</bal_amt>");
xmlBuff.append("<bal_amt>").append("<![CDATA[" +rounded(balAmt,3) +"]]>").append("</bal_amt>");
xmlBuff.append("<adj_amt>").append("<![CDATA[" + rounded(adjAmt,3) +"]]>").append("</adj_amt>");
xmlBuff.append("<adjusted_amt>").append("<![CDATA["+ rounded(adjustedAmt,3) +"]]>").append("</adjusted_amt>");
xmlBuff.append("<inv_amt>").append("<![CDATA[" + rounded(invAmt,3) +"]]>").append("</inv_amt>");
if ( reasCode == null || reasCode.trim().length() == 0)
{
xmlBuff.append("<reas_code>").append("<![CDATA[]]>").append("</reas_code>");
......@@ -3141,7 +3182,7 @@ conn = getConnection();
}else{
xmlBuff.append("<reas_detail>").append("<![CDATA["+ reasDetail +"]]>").append("</reas_detail>");
}
xmlBuff.append("<cust_ref_amt>").append("<![CDATA["+ custRefAmt +"]]>").append("</cust_ref_amt>");
xmlBuff.append("<cust_ref_amt>").append("<![CDATA["+ rounded(custRefAmt,3) +"]]>").append("</cust_ref_amt>");
xmlBuff.append("<remarks>").append("<![CDATA["+remarks+"]]>").append("</remarks>");
xmlBuff.append("</Detail2>");
}catch (SQLException se)
......@@ -3180,6 +3221,10 @@ conn = getConnection();
}
//Pavan R on 24MAY18 End
public static BigDecimal rounded(BigDecimal aNumber, int prec)
{
return aNumber.setScale(prec, BigDecimal.ROUND_HALF_EVEN);
}
}//class
......@@ -3193,25 +3238,36 @@ class ReceiptBean
private String tranSer = "";
private String custRefNo = "";
private Timestamp tranDate = null;
private double totAmt = 0;
/*private double totAmt = 0;
private double balAmt = 0;
private double adjAmt = 0;
private double adjustedAmt = 0;
private double invAmt = 0;
private double invAmt = 0;*/
private String reasCode = "";
private String custName = "";
private String custCode = "";
private String bankCode = "";
private Timestamp chequeDate = null;
private String chequeNo = "";
private double chqAmount = 0;
//private double chqAmount = 0;
private Timestamp custRefDate = null;
private Timestamp dueDate = null;
private String reasDetail = "";
private double custRefAmt = 0;
private double runningTotal = 0;
//private double custRefAmt = 0;
//private double runningTotal = 0;
private String isSelected = "";
private int domId = 0;
private BigDecimal totAmt = new BigDecimal(0.0);
private BigDecimal balAmt = new BigDecimal(0.0);
private BigDecimal adjAmt = new BigDecimal(0.0);
private BigDecimal adjustedAmt = new BigDecimal(0.0);
private BigDecimal invAmt = new BigDecimal(0.0);
private BigDecimal chqAmount = new BigDecimal(0.0);
private BigDecimal custRefAmt = new BigDecimal(0.0);
private BigDecimal runningTotal = new BigDecimal(0.0);
public String getInvoiceId() {
return invoiceId;
}
......@@ -3236,7 +3292,7 @@ class ReceiptBean
public void setTranDate(Timestamp tranDate) {
this.tranDate = tranDate;
}
public double getTotAmt() {
/*public double getTotAmt() {
return totAmt;
}
public void setTotAmt(double totAmt) {
......@@ -3265,7 +3321,7 @@ class ReceiptBean
}
public void setInvAmt(double invAmt) {
this.invAmt = invAmt;
}
}*/
public String getReasCode() {
return reasCode;
}
......@@ -3302,12 +3358,12 @@ class ReceiptBean
public void setChequeNo(String chequeNo) {
this.chequeNo = chequeNo;
}
public double getChqAmount() {
/*public double getChqAmount() {
return chqAmount;
}
public void setChqAmount(double chqAmount) {
this.chqAmount = chqAmount;
}
}*/
public Timestamp getCustRefDate() {
return custRefDate;
}
......@@ -3326,7 +3382,7 @@ class ReceiptBean
public void setReasDetail(String reasDetail) {
this.reasDetail = reasDetail;
}
public double getCustRefAmt() {
/*public double getCustRefAmt() {
return custRefAmt;
}
public void setCustRefAmt(double custRefAmt) {
......@@ -3338,7 +3394,7 @@ class ReceiptBean
}
public void setRunningTotal(double runningTotal) {
this.runningTotal = runningTotal;
}
}*/
public String getIsSelected() {
return isSelected;
}
......@@ -3351,6 +3407,55 @@ class ReceiptBean
public void setDomId(int domId) {
this.domId = domId;
}
public BigDecimal getTotAmt() {
return totAmt;
}
public void setTotAmt(BigDecimal totAmt) {
this.totAmt = totAmt;
}
public BigDecimal getBalAmt() {
return balAmt;
}
public void setBalAmt(BigDecimal balAmt) {
this.balAmt = balAmt;
}
public BigDecimal getAdjAmt() {
return adjAmt;
}
public void setAdjAmt(BigDecimal adjAmt) {
this.adjAmt = adjAmt;
}
public BigDecimal getAdjustedAmt() {
return adjustedAmt;
}
public void setAdjustedAmt(BigDecimal adjustedAmt) {
this.adjustedAmt = adjustedAmt;
}
public BigDecimal getInvAmt() {
return invAmt;
}
public void setInvAmt(BigDecimal invAmt) {
this.invAmt = invAmt;
}
public BigDecimal getChqAmount() {
return chqAmount;
}
public void setChqAmount(BigDecimal chqAmount) {
this.chqAmount = chqAmount;
}
public BigDecimal getCustRefAmt() {
return custRefAmt;
}
public void setCustRefAmt(BigDecimal custRefAmt) {
this.custRefAmt = custRefAmt;
}
public BigDecimal getRunningTotal() {
return runningTotal;
}
public void setRunningTotal(BigDecimal runningTotal) {
this.runningTotal = runningTotal;
}
public static Comparator<ReceiptBean> receiptComparator = new Comparator<ReceiptBean>() {
public int compare(ReceiptBean rcpBean1, ReceiptBean rcpBean2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment