In java script :
function adjustments()
{
//validation
var st1="";
var st2="";
var gridsData;
var mygridOne=new Array();
var mygridTwo=new Array();
var mygrid1Arry=null;
var mygrid2Arry=null;
if(document.getElementById("adjNature").value!='FIFO')
{
mygrid1Arry=mygrid1.getSelectedRecords();
mygrid2Arry=mygrid2.getSelectedRecords();
}
else
{
mygrid1Arry=Sigma.Grid.getAllRows(mygrid1);
mygrid2Arry=Sigma.Grid.getAllRows(mygrid2);
}
if(mygrid1Arry.length>0 && mygrid2Arry.length>0)
{
if(beforeAdjustvalidate())
{
for(var i=0;i
{
var docType1= mygrid1Arry[i].doctype;
if(docType1==undefined) { docType1=mygrid1.getColumnValue('doctype', i);}
var docNum1= mygrid1Arry[i].docno;
if(docNum1==undefined) { docNum1=mygrid1.getColumnValue('docno', i);}
var docDate1= mygrid1Arry[i].docdate;
if(docDate1==undefined) { docDate1=mygrid1.getColumnValue('docdate', i);}
var docAmount1= mygrid1Arry[i].docamt;
if(docAmount1==undefined) { docAmount1=mygrid1.getColumnValue('docamt', i);}
var amtAdjusted1= mygrid1Arry[i].amtadjusted;
if(amtAdjusted1==undefined) { amtAdjusted1=mygrid1.getColumnValue('amtadjusted', i);}
var balance1= mygrid1Arry[i].balance;
if(balance1==undefined) { balance1=mygrid1.getColumnValue('balance', i);}
var currentAdjustment1= mygrid1Arry[i].curradj;
if(currentAdjustment1==undefined) { currentAdjustment1=mygrid1.getColumnValue('curradj', i);}
if(i==(mygrid1Arry.length-1))
{
st1+="{docType:'"+docType1+"',docNum:'"+docNum1+"',docDate:'"+docDate1+"',docAmount:'"+docAmount1+"',amtAdjusted:'"+amtAdjusted1+"',balance:'"+balance1+"',currentAdjustment:'"+currentAdjustment1+"'}";
}else
st1+="{docType:'"+docType1+"',docNum:'"+docNum1+"',docDate:'"+docDate1+"',docAmount:'"+docAmount1+"',amtAdjusted:'"+amtAdjusted1+"',balance:'"+balance1+"',currentAdjustment:'"+currentAdjustment1+"'},";
}
for(var j=0;j
{
var docType2= mygrid2Arry[j].doctype;
if(docType2==undefined) { docType2=mygrid2.getColumnValue('doctype', j);}
var docNum2= mygrid2Arry[j].docno;
if(docNum2==undefined) { docNum2=mygrid2.getColumnValue('docno', j);}
var docDate2= mygrid2Arry[j].docdate;
if(docDate2==undefined) { docDate2=mygrid2.getColumnValue('docdate', j);}
var docAmount2= mygrid2Arry[j].docamt;
if(docAmount2==undefined) { docAmount2=mygrid2.getColumnValue('docamt', j);}
var amtAdjusted2= mygrid2Arry[j].amtadjusted;
if(amtAdjusted2==undefined) { amtAdjusted2=mygrid2.getColumnValue('amtadjusted', j);}
var balance2= mygrid2Arry[j].balance;
if(balance2==undefined) { balance2=mygrid2.getColumnValue('balance', j);}
var currentAdjustment2= mygrid2Arry[j].curradj;
if(currentAdjustment2==undefined) { currentAdjustment2=mygrid2.getColumnValue('curradj', j);}
if(j==(mygrid2Arry.length-1))
{ //alert("docType2-----"+docType2+"---");
st2+="{docType:'"+docType2+"',docNum:'"+docNum2+"',docDate:'"+docDate2+"',docAmount:'"+docAmount2+"',amtAdjusted:'"+amtAdjusted2+"',balance:'"+balance2+"',currentAdjustment:'"+currentAdjustment2+"'}";
}
else
st2+="{docType:'"+docType2+"',docNum:'"+docNum2+"',docDate:'"+docDate2+"',docAmount:'"+docAmount2+"',amtAdjusted:'"+amtAdjusted2+"',balance:'"+balance2+"',currentAdjustment:'"+currentAdjustment2+"'},";
}
st1="["+st1+"],";
st2="["+st2+"]";
gridsData='{"grid1-dr":'+ st1;
gridsData+='"grid2-cr":'+ st2+'}';
var toServer=gridsData;
/* code started sending JSON Object to server */
xmlhttp = false;
if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null) {
url=appsPath+"/finance/adjustCrDrdocs?adjNature="+encodeURIComponent(document.getElementById("adjNature").value);
xmlhttp.onreadystatechange= function () {
getAdjDetailsCallback(xmlhttp);
};
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(toServer);
} else {
alert("Your browser does not support XMLHTTP.");
}
}
/* code ended sending JSON Object to server */
}
else
{
alert("Please select corresponding Cr/Dr documents");
return false;
}
}
function getAdjDetailsCallback()
{
if (xmlhttp.readyState == 4)
{ // Complete
alert(xmlhttp.responseText);
var message=xmlhttp.responseXML;
var recordlength=message.getElementsByTagName("grid").length;
var docsArray=new Array();
var amtAdjustedArray=new Array();
var amtadjusted1=0;
for(var i=0;i
{
var amtadjusted="";
var record=message.getElementsByTagName("grid");
var docnum=record[i].getElementsByTagName("docnum")[0].childNodes[0].nodeValue;
amtadjusted=record[i].getElementsByTagName("amtadjusted")[0].childNodes[0].nodeValue;
var balance=record[i].getElementsByTagName("balance")[0].childNodes[0].nodeValue;
var index;
var totaldrRecords = Sigma.Grid.getAllRows(mygrid1).size();
for(var t=0;t
{
var docNumDr= mygrid1.getColumnValue("docno",t);
if(docnum==docNumDr)
{
index=t;
mygrid1.setColumnValue("amtadjusted", index,amtadjusted);
mygrid1.setColumnValue("balance", index,balance);
mygrid1.refresh();
}
}
var index1;
var totalcrRecords = Sigma.Grid.getAllRows(mygrid2).size();
for(var t1=0;t1
{
var docNumDr= mygrid2.getColumnValue("docno",t1);
if(docnum==docNumDr)
{
index1=t1;
mygrid2.setColumnValue("amtadjusted", index1,amtadjusted);
mygrid2.setColumnValue("balance", index1,balance);
mygrid2.refresh();
}
}
}
}
}
In Java :
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("-----------------in AdjustmentAction--execute");
String gridsData = readJSON(request);
String adjNature = request.getParameter("adjNature") != null ? request.getParameter("adjNature") : "";
System.out.println("adjNature---------"+adjNature);
//Use the JSON-Java binding library to create a JSON object in Java
JSONObject jsonObject = null;
StringBuffer sb = new StringBuffer();
response.setContentType("text/xml");
JSONArray gridOneArray;
JSONArray gridOneTwo;
try {
jsonObject = new JSONObject(gridsData);
System.out.println("jsonObject-----" + jsonObject);
System.out.println("grid1------" + jsonObject.get("grid1-dr"));
System.out.println("grid2------" + jsonObject.get("grid2-cr"));
System.out.println("grid1-getJSONArray-----" + jsonObject.getJSONArray("grid1-dr"));
System.out.println("grid2--getJSONArray----" + jsonObject.getJSONArray("grid2-cr"));
gridOneArray = jsonObject.getJSONArray("grid1-dr");
gridOneTwo = jsonObject.getJSONArray("grid2-cr");
sb.append("<message>");
sb.append("<grids>");
for (int i = 0; i < gridOneArray.length(); i++) {
System.out.println("outer for loop 1");
JSONObject record1 = (JSONObject) gridOneArray.get(i);
String docType1 = record1.getString("docType");
Double balance1 = record1.getDouble("balance");
Double currentAdjustment1;
try{
currentAdjustment1= record1.getDouble("currentAdjustment");
}catch(Exception e){ currentAdjustment1=0.0d;}
Double docAmount1 = record1.getDouble("docAmount");
Double amtAdjusted1 = record1.getDouble("amtAdjusted");
String docDate1 = record1.getString("docDate");
String docNum1 = record1.getString("docNum");
System.out.println("outer for loop 2");
for (int j = 0; j < gridOneTwo.length(); j++) {
JSONObject record2 = (JSONObject) gridOneTwo.get(j);
String docType2 = record2.getString("docType");
Double balance2 = record2.getDouble("balance");
Double currentAdjustment2;
try{
currentAdjustment2= record2.getDouble("currentAdjustment");
}catch(Exception e){ currentAdjustment2=0.0d;}
Double docAmount2 = record2.getDouble("docAmount");
Double amtAdjusted2 = record2.getDouble("amtAdjusted");
String docDate2 = record2.getString("docDate");
String docNum2 = record2.getString("docNum");
System.out.println("inner for loop");
/*
* Respose XML
<message><grids>
<grid><docnum>CR0000081</docnum><amtadjusted>9000.0</amtadjusted><balance>3000.0</balance><adjustedDoc>CI0000061</adjustedDoc></grid>
<grid><docnum>CI0000061</docnum><amtadjusted>19000.0</amtadjusted><balance>0.0</balance></grid>
<grid><docnum>CR0000051</docnum><amtadjusted>10000.0</amtadjusted><balance>10000.0</balance><adjustedDoc>CI0000061</adjustedDoc></grid>
</grids></message>
*
*/
//business logic for manual adjustment starts here
if (adjNature != null && adjNature.equals("manual")) {
if (currentAdjustment1 <= currentAdjustment2) { // Step 1 : deduct currentadj1 in balance2,then if balance1=0 then close the status of doctype1
//Step 2 : if balance1!=0,then go to next credit document
//Step 1 execution starts here
System.out.println("if currentAdjustment1<=balance2--strats");
balance2 = balance2 - currentAdjustment2;
amtAdjusted2 = amtAdjusted2 + currentAdjustment2;
amtAdjusted1 += currentAdjustment1;
balance1 = balance1 - currentAdjustment1;
sb.append("<grid>");
sb.append("<docnum>" + docNum1 + "</docnum>");
sb.append("<amtadjusted>" + amtAdjusted1 + "</amtadjusted>");
sb.append("<balance>" + balance1 + "</balance>");
sb.append("</grid>");
sb.append("<grid>");
sb.append("<docnum>" + docNum2 + "</docnum>");
sb.append("<amtadjusted>" + amtAdjusted2 + "</amtadjusted>");
sb.append("<balance>" + balance2 + "</balance>");
sb.append("<adjustedDoc>" + docNum1 + "</adjustedDoc>");
sb.append("</grid>");
System.out.println("if currentAdjustment1<=balance2--ends");
} else if (currentAdjustment1 > currentAdjustment2) {
//Step 1 : deduct balance2 in currentAdjustment1 then if balance2=0, then close doctype2
System.out.println("if currentAdjustment1>balance2--strats");
amtAdjusted2 = amtAdjusted2 + currentAdjustment2;
amtAdjusted1 += currentAdjustment2;
currentAdjustment1 = currentAdjustment1 - currentAdjustment2;
System.out.println("currentAdjustment1-2--" + currentAdjustment1);
balance1 = balance1 - currentAdjustment2;
balance2 = balance2 - currentAdjustment2;
sb.append("<grid>");
sb.append("<docnum>" + docNum2 + "</docnum>");
sb.append("<amtadjusted>" + amtAdjusted2 + "</amtadjusted>");
sb.append("<balance>" + balance2 + "</balance>");
sb.append("<adjustedDoc>" + docNum1 + "</adjustedDoc>");
sb.append("</grid>");
System.out.println("if currentAdjustment1>balance2--ends");
}
// manual end
}// END MANUAL IF
// FIFO STARTS
else if (adjNature != null && adjNature.equals("FIFO")) {
if(balance1<=balance2)
{ // Step 1 : deduct balance1 in balance2,then if balance1=0 then close the status of doctype1
//Step 2 : if balance1!=0,then go to next credit document
//Step 1 execution starts here
System.out.println("if balance1<=balance2--strats");
balance2=balance2-balance1;
amtAdjusted2=amtAdjusted2+balance1;
amtAdjusted1+=balance1;
balance1=balance1-balance1;
sb.append("<grid>");
sb.append("<docnum>"+docNum1+"</docnum>");
sb.append("<amtadjusted>"+amtAdjusted1+"</amtadjusted>");
sb.append("<balance>"+balance1+"</balance>");
sb.append("</grid>");
sb.append("<grid>");
sb.append("<docnum>"+docNum2+"</docnum>");
sb.append("<amtadjusted>"+amtAdjusted2+"</amtadjusted>");
sb.append("<balance>"+balance2+"</balance>");
sb.append("<adjustedDoc>"+docNum1+"</adjustedDoc>");
sb.append("</grid>");
System.out.println("if currentAdjustment1<=balance2--ends");
}
else if(balance1>balance2)
{
//Step 1 : deduct balance2 in currentAdjustment1 then if balance2=0, then close doctype2
System.out.println("if currentAdjustment1>balance2--strats");
amtAdjusted2=amtAdjusted2+balance2;
amtAdjusted1+=balance2;
currentAdjustment1=currentAdjustment1-balance2;
System.out.println("currentAdjustment1-2--"+currentAdjustment1);
balance1=balance1-balance2;
balance2=balance2-balance2;
sb.append("<grid>");
sb.append("<docnum>"+docNum1+"</docnum>");
sb.append("<amtadjusted>"+amtAdjusted1+"</amtadjusted>");
sb.append("<balance>"+balance1+"</balance>");
sb.append("</grid>");
sb.append("<grid>");
sb.append("<docnum>"+docNum2+"</docnum>");
sb.append("<amtadjusted>"+amtAdjusted2+"</amtadjusted>");
sb.append("<balance>"+balance2+"</balance>");
sb.append("<adjustedDoc>"+docNum1+"</adjustedDoc>");
sb.append("</grid>");
System.out.println("if currentAdjustment1>balance2--ends");
}
} //FIFO end
} //inner for loop
} //outer for loop
sb.append("</grids>");
sb.append("</message>");
} //try
catch (Exception pe) {
pe.printStackTrace();
}
System.out.println("sb.toString()-----" + sb.toString());
response.getWriter().write(sb.toString());
return null;
}
private String readJSON(HttpServletRequest request) {
StringBuffer json = new StringBuffer();
String line = null;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
json.append(line);
}
} catch (Exception e) {
System.out.println("Error reading JSON String: " + e.toString());
}
return json.toString();
}
function adjustments()
{
//validation
var st1="";
var st2="";
var gridsData;
var mygridOne=new Array();
var mygridTwo=new Array();
var mygrid1Arry=null;
var mygrid2Arry=null;
if(document.getElementById("adjNature").value!='FIFO')
{
mygrid1Arry=mygrid1.getSelectedRecords();
mygrid2Arry=mygrid2.getSelectedRecords();
}
else
{
mygrid1Arry=Sigma.Grid.getAllRows(mygrid1);
mygrid2Arry=Sigma.Grid.getAllRows(mygrid2);
}
if(mygrid1Arry.length>0 && mygrid2Arry.length>0)
{
if(beforeAdjustvalidate())
{
for(var i=0;i
{
var docType1= mygrid1Arry[i].doctype;
if(docType1==undefined) { docType1=mygrid1.getColumnValue('doctype', i);}
var docNum1= mygrid1Arry[i].docno;
if(docNum1==undefined) { docNum1=mygrid1.getColumnValue('docno', i);}
var docDate1= mygrid1Arry[i].docdate;
if(docDate1==undefined) { docDate1=mygrid1.getColumnValue('docdate', i);}
var docAmount1= mygrid1Arry[i].docamt;
if(docAmount1==undefined) { docAmount1=mygrid1.getColumnValue('docamt', i);}
var amtAdjusted1= mygrid1Arry[i].amtadjusted;
if(amtAdjusted1==undefined) { amtAdjusted1=mygrid1.getColumnValue('amtadjusted', i);}
var balance1= mygrid1Arry[i].balance;
if(balance1==undefined) { balance1=mygrid1.getColumnValue('balance', i);}
var currentAdjustment1= mygrid1Arry[i].curradj;
if(currentAdjustment1==undefined) { currentAdjustment1=mygrid1.getColumnValue('curradj', i);}
if(i==(mygrid1Arry.length-1))
{
st1+="{docType:'"+docType1+"',docNum:'"+docNum1+"',docDate:'"+docDate1+"',docAmount:'"+docAmount1+"',amtAdjusted:'"+amtAdjusted1+"',balance:'"+balance1+"',currentAdjustment:'"+currentAdjustment1+"'}";
}else
st1+="{docType:'"+docType1+"',docNum:'"+docNum1+"',docDate:'"+docDate1+"',docAmount:'"+docAmount1+"',amtAdjusted:'"+amtAdjusted1+"',balance:'"+balance1+"',currentAdjustment:'"+currentAdjustment1+"'},";
}
for(var j=0;j
{
var docType2= mygrid2Arry[j].doctype;
if(docType2==undefined) { docType2=mygrid2.getColumnValue('doctype', j);}
var docNum2= mygrid2Arry[j].docno;
if(docNum2==undefined) { docNum2=mygrid2.getColumnValue('docno', j);}
var docDate2= mygrid2Arry[j].docdate;
if(docDate2==undefined) { docDate2=mygrid2.getColumnValue('docdate', j);}
var docAmount2= mygrid2Arry[j].docamt;
if(docAmount2==undefined) { docAmount2=mygrid2.getColumnValue('docamt', j);}
var amtAdjusted2= mygrid2Arry[j].amtadjusted;
if(amtAdjusted2==undefined) { amtAdjusted2=mygrid2.getColumnValue('amtadjusted', j);}
var balance2= mygrid2Arry[j].balance;
if(balance2==undefined) { balance2=mygrid2.getColumnValue('balance', j);}
var currentAdjustment2= mygrid2Arry[j].curradj;
if(currentAdjustment2==undefined) { currentAdjustment2=mygrid2.getColumnValue('curradj', j);}
if(j==(mygrid2Arry.length-1))
{ //alert("docType2-----"+docType2+"---");
st2+="{docType:'"+docType2+"',docNum:'"+docNum2+"',docDate:'"+docDate2+"',docAmount:'"+docAmount2+"',amtAdjusted:'"+amtAdjusted2+"',balance:'"+balance2+"',currentAdjustment:'"+currentAdjustment2+"'}";
}
else
st2+="{docType:'"+docType2+"',docNum:'"+docNum2+"',docDate:'"+docDate2+"',docAmount:'"+docAmount2+"',amtAdjusted:'"+amtAdjusted2+"',balance:'"+balance2+"',currentAdjustment:'"+currentAdjustment2+"'},";
}
st1="["+st1+"],";
st2="["+st2+"]";
gridsData='{"grid1-dr":'+ st1;
gridsData+='"grid2-cr":'+ st2+'}';
var toServer=gridsData;
/* code started sending JSON Object to server */
xmlhttp = false;
if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null) {
url=appsPath+"/finance/adjustCrDrdocs?adjNature="+encodeURIComponent(document.getElementById("adjNature").value);
xmlhttp.onreadystatechange= function () {
getAdjDetailsCallback(xmlhttp);
};
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(toServer);
} else {
alert("Your browser does not support XMLHTTP.");
}
}
/* code ended sending JSON Object to server */
}
else
{
alert("Please select corresponding Cr/Dr documents");
return false;
}
}
function getAdjDetailsCallback()
{
if (xmlhttp.readyState == 4)
{ // Complete
alert(xmlhttp.responseText);
var message=xmlhttp.responseXML;
var recordlength=message.getElementsByTagName("grid").length;
var docsArray=new Array();
var amtAdjustedArray=new Array();
var amtadjusted1=0;
for(var i=0;i
{
var amtadjusted="";
var record=message.getElementsByTagName("grid");
var docnum=record[i].getElementsByTagName("docnum")[0].childNodes[0].nodeValue;
amtadjusted=record[i].getElementsByTagName("amtadjusted")[0].childNodes[0].nodeValue;
var balance=record[i].getElementsByTagName("balance")[0].childNodes[0].nodeValue;
var index;
var totaldrRecords = Sigma.Grid.getAllRows(mygrid1).size();
for(var t=0;t
{
var docNumDr= mygrid1.getColumnValue("docno",t);
if(docnum==docNumDr)
{
index=t;
mygrid1.setColumnValue("amtadjusted", index,amtadjusted);
mygrid1.setColumnValue("balance", index,balance);
mygrid1.refresh();
}
}
var index1;
var totalcrRecords = Sigma.Grid.getAllRows(mygrid2).size();
for(var t1=0;t1
{
var docNumDr= mygrid2.getColumnValue("docno",t1);
if(docnum==docNumDr)
{
index1=t1;
mygrid2.setColumnValue("amtadjusted", index1,amtadjusted);
mygrid2.setColumnValue("balance", index1,balance);
mygrid2.refresh();
}
}
}
}
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("-----------------in AdjustmentAction--execute");
String gridsData = readJSON(request);
String adjNature = request.getParameter("adjNature") != null ? request.getParameter("adjNature") : "";
System.out.println("adjNature---------"+adjNature);
//Use the JSON-Java binding library to create a JSON object in Java
JSONObject jsonObject = null;
StringBuffer sb = new StringBuffer();
response.setContentType("text/xml");
JSONArray gridOneArray;
JSONArray gridOneTwo;
try {
jsonObject = new JSONObject(gridsData);
System.out.println("jsonObject-----" + jsonObject);
System.out.println("grid1------" + jsonObject.get("grid1-dr"));
System.out.println("grid2------" + jsonObject.get("grid2-cr"));
System.out.println("grid1-getJSONArray-----" + jsonObject.getJSONArray("grid1-dr"));
System.out.println("grid2--getJSONArray----" + jsonObject.getJSONArray("grid2-cr"));
gridOneArray = jsonObject.getJSONArray("grid1-dr");
gridOneTwo = jsonObject.getJSONArray("grid2-cr");
sb.append("<message>");
sb.append("<grids>");
for (int i = 0; i < gridOneArray.length(); i++) {
System.out.println("outer for loop 1");
JSONObject record1 = (JSONObject) gridOneArray.get(i);
String docType1 = record1.getString("docType");
Double balance1 = record1.getDouble("balance");
Double currentAdjustment1;
try{
currentAdjustment1= record1.getDouble("currentAdjustment");
}catch(Exception e){ currentAdjustment1=0.0d;}
Double docAmount1 = record1.getDouble("docAmount");
Double amtAdjusted1 = record1.getDouble("amtAdjusted");
String docDate1 = record1.getString("docDate");
String docNum1 = record1.getString("docNum");
System.out.println("outer for loop 2");
for (int j = 0; j < gridOneTwo.length(); j++) {
JSONObject record2 = (JSONObject) gridOneTwo.get(j);
String docType2 = record2.getString("docType");
Double balance2 = record2.getDouble("balance");
Double currentAdjustment2;
try{
currentAdjustment2= record2.getDouble("currentAdjustment");
}catch(Exception e){ currentAdjustment2=0.0d;}
Double docAmount2 = record2.getDouble("docAmount");
Double amtAdjusted2 = record2.getDouble("amtAdjusted");
String docDate2 = record2.getString("docDate");
String docNum2 = record2.getString("docNum");
System.out.println("inner for loop");
/*
* Respose XML
<message><grids>
<grid><docnum>CR0000081</docnum><amtadjusted>9000.0</amtadjusted><balance>3000.0</balance><adjustedDoc>CI0000061</adjustedDoc></grid>
<grid><docnum>CI0000061</docnum><amtadjusted>19000.0</amtadjusted><balance>0.0</balance></grid>
<grid><docnum>CR0000051</docnum><amtadjusted>10000.0</amtadjusted><balance>10000.0</balance><adjustedDoc>CI0000061</adjustedDoc></grid>
</grids></message>
*
*/
//business logic for manual adjustment starts here
if (adjNature != null && adjNature.equals("manual")) {
if (currentAdjustment1 <= currentAdjustment2) { // Step 1 : deduct currentadj1 in balance2,then if balance1=0 then close the status of doctype1
//Step 2 : if balance1!=0,then go to next credit document
//Step 1 execution starts here
System.out.println("if currentAdjustment1<=balance2--strats");
balance2 = balance2 - currentAdjustment2;
amtAdjusted2 = amtAdjusted2 + currentAdjustment2;
amtAdjusted1 += currentAdjustment1;
balance1 = balance1 - currentAdjustment1;
sb.append("<grid>");
sb.append("<docnum>" + docNum1 + "</docnum>");
sb.append("<amtadjusted>" + amtAdjusted1 + "</amtadjusted>");
sb.append("<balance>" + balance1 + "</balance>");
sb.append("</grid>");
sb.append("<grid>");
sb.append("<docnum>" + docNum2 + "</docnum>");
sb.append("<amtadjusted>" + amtAdjusted2 + "</amtadjusted>");
sb.append("<balance>" + balance2 + "</balance>");
sb.append("<adjustedDoc>" + docNum1 + "</adjustedDoc>");
sb.append("</grid>");
System.out.println("if currentAdjustment1<=balance2--ends");
} else if (currentAdjustment1 > currentAdjustment2) {
//Step 1 : deduct balance2 in currentAdjustment1 then if balance2=0, then close doctype2
System.out.println("if currentAdjustment1>balance2--strats");
amtAdjusted2 = amtAdjusted2 + currentAdjustment2;
amtAdjusted1 += currentAdjustment2;
currentAdjustment1 = currentAdjustment1 - currentAdjustment2;
System.out.println("currentAdjustment1-2--" + currentAdjustment1);
balance1 = balance1 - currentAdjustment2;
balance2 = balance2 - currentAdjustment2;
sb.append("<grid>");
sb.append("<docnum>" + docNum2 + "</docnum>");
sb.append("<amtadjusted>" + amtAdjusted2 + "</amtadjusted>");
sb.append("<balance>" + balance2 + "</balance>");
sb.append("<adjustedDoc>" + docNum1 + "</adjustedDoc>");
sb.append("</grid>");
System.out.println("if currentAdjustment1>balance2--ends");
}
// manual end
}// END MANUAL IF
// FIFO STARTS
else if (adjNature != null && adjNature.equals("FIFO")) {
if(balance1<=balance2)
{ // Step 1 : deduct balance1 in balance2,then if balance1=0 then close the status of doctype1
//Step 2 : if balance1!=0,then go to next credit document
//Step 1 execution starts here
System.out.println("if balance1<=balance2--strats");
balance2=balance2-balance1;
amtAdjusted2=amtAdjusted2+balance1;
amtAdjusted1+=balance1;
balance1=balance1-balance1;
sb.append("<grid>");
sb.append("<docnum>"+docNum1+"</docnum>");
sb.append("<amtadjusted>"+amtAdjusted1+"</amtadjusted>");
sb.append("<balance>"+balance1+"</balance>");
sb.append("</grid>");
sb.append("<grid>");
sb.append("<docnum>"+docNum2+"</docnum>");
sb.append("<amtadjusted>"+amtAdjusted2+"</amtadjusted>");
sb.append("<balance>"+balance2+"</balance>");
sb.append("<adjustedDoc>"+docNum1+"</adjustedDoc>");
sb.append("</grid>");
System.out.println("if currentAdjustment1<=balance2--ends");
}
else if(balance1>balance2)
{
//Step 1 : deduct balance2 in currentAdjustment1 then if balance2=0, then close doctype2
System.out.println("if currentAdjustment1>balance2--strats");
amtAdjusted2=amtAdjusted2+balance2;
amtAdjusted1+=balance2;
currentAdjustment1=currentAdjustment1-balance2;
System.out.println("currentAdjustment1-2--"+currentAdjustment1);
balance1=balance1-balance2;
balance2=balance2-balance2;
sb.append("<grid>");
sb.append("<docnum>"+docNum1+"</docnum>");
sb.append("<amtadjusted>"+amtAdjusted1+"</amtadjusted>");
sb.append("<balance>"+balance1+"</balance>");
sb.append("</grid>");
sb.append("<grid>");
sb.append("<docnum>"+docNum2+"</docnum>");
sb.append("<amtadjusted>"+amtAdjusted2+"</amtadjusted>");
sb.append("<balance>"+balance2+"</balance>");
sb.append("<adjustedDoc>"+docNum1+"</adjustedDoc>");
sb.append("</grid>");
System.out.println("if currentAdjustment1>balance2--ends");
}
} //FIFO end
} //inner for loop
} //outer for loop
sb.append("</grids>");
sb.append("</message>");
} //try
catch (Exception pe) {
pe.printStackTrace();
}
System.out.println("sb.toString()-----" + sb.toString());
response.getWriter().write(sb.toString());
return null;
}
private String readJSON(HttpServletRequest request) {
StringBuffer json = new StringBuffer();
String line = null;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
json.append(line);
}
} catch (Exception e) {
System.out.println("Error reading JSON String: " + e.toString());
}
return json.toString();
}
No comments:
Post a Comment