Commit 3b9dd520 authored by asant's avatar asant

Added all new changes req by client

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@192059 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 48291ee9
......@@ -23,9 +23,11 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Stateless;
import javax.xml.transform.OutputKeys;
......@@ -33,6 +35,7 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import org.json.simple.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
......@@ -50,14 +53,21 @@ import ibase.webitm.utility.ITMException;
public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposalLocal, SalesQuotProposalRemote
{
E12GenericUtility genericUtility = new E12GenericUtility();
ArrayList<String> itemCodeArr = new ArrayList<String>();
ArrayList<String> itemCodeArr2 = new ArrayList<String>();
NumberFormat formatter = new DecimalFormat("#0.00");
private ArrayList<String> itemCodeArr = new ArrayList<String>();
private ArrayList<String> itemCodeArr2 = new ArrayList<String>();
private NumberFormat formatter = new DecimalFormat("#0.00");
private int globalNo = 0;
private String oldRate = "";
private String currentCustCode = "",currentFromDate = "",currentToDate = "";
private String preViousCustCode = "",preViousFromDate = "",preViousToDate = "";
//private String preViousCustCode = "",preViousFromDate = "",preViousToDate = "";
HashMap<String,String> firstFormDetailMap = new HashMap<String,String>();
private Set<Integer> srNoSet = null;//added on 10-10-18 Add new Form no2 to get srNo.
private Set<Integer> copyOfsrNoSet = null;
private String globaldisPriceList = "";
private String globalpriceList = "";
private String globalcommTable = "";
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
......@@ -112,7 +122,7 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
System.out.println(" ########### SalesQuotProposal **********wfValData 3333 (Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams)***********" );
NodeList parentNodeList = null;NodeList childNodeList = null;
Node parentNode = null;Node childNode = null;
String childNodeName = null;
String childNodeName = null,cildNodeValue = null;
Connection conn = null;
PreparedStatement pstmt = null ;
ResultSet rs = null , rs1 = null;
......@@ -132,6 +142,9 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
Node node = null;
Element element = null;
//Added by AMOL END
String srNoStr = "", itemCodeStr = "", quantityStr = "", rateStr = "";
String newRateStr = "";
try
{
connDriver = null;
......@@ -264,76 +277,90 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
break;
}
}
//Commented on 05-10-18 START
//Added by AMOL START
/*try
}
}
}
else if("sale_quotdet".equalsIgnoreCase(formName))
{
if( E12GenericUtility.checkNull(custCode).length() > 0 && E12GenericUtility.checkNull(fromDtStr).length() > 0
&& E12GenericUtility.checkNull(toDtStr).length() > 0)
parentNodeList = dom.getElementsByTagName("Detail2");
int parentNodeListLen = parentNodeList.getLength();
System.out.println("##### Number of node in parentNodeListLen : "+parentNodeListLen);
for ( int rowCnt=0; rowCnt < parentNodeListLen; rowCnt++ )
{
System.out.println("#### WFValData From Date :"+fromDtStr);
System.out.println("#### WFValData To Date :"+toDtStr);
formatedInvIds = new SalesQuotRevision().getInvoiceIds(formatedInvIds,custCode,fromDtStr,toDtStr,conn);
System.out.println("#### Formatted IDs ["+formatedInvIds+"]");
System.out.println("#### formatedInvIds.length ["+formatedInvIds.length()+"]");
if(formatedInvIds.length() == 2 || formatedInvIds == null)
try {
System.out.println("#### IN FORM 2 ");
parentNode = parentNodeList.item(rowCnt);
Element childElement = (Element)parentNode;
childNode = childElement.getElementsByTagName("sr_no").item(0);
//String nodeValStr = childNode.getFirstChild().getNodeValue();
Node firstChildNode = childNode.getFirstChild();
if(firstChildNode == null)
{
errCode = "VTNORECFND";
System.out.println("### IN IF @@@@");
errCode = "VTBLNKDTL";
errList.add(errCode);
errFields.add("to_date");
break;
errFields.add("sr_no");
}else
{
System.out.println("#### In ELSE FOR SELECTED ");
if(childElement.getElementsByTagName("selectbox") != null)
{
childNode = childElement.getElementsByTagName("selectbox").item(0);
if(childNode != null && childNode.getFirstChild() != null)
{
String valStr = childNode.getFirstChild().getNodeValue();
System.out.println("#### valStr "+valStr);
if(valStr.equalsIgnoreCase("true"))
{
count2 ++;
}
}
}
catch(Exception e)
if(childElement.getElementsByTagName("selected") != null)
{
System.out.println("#### Exception in WFValDate Invoice_ID "+e);
e.printStackTrace();
}*/
//Added by AMOL END
//Commented on 05-10-18 END
}
}
childNode = childElement.getElementsByTagName("selected").item(0);
}
else if("sale_quotdet".equalsIgnoreCase(formName))
if(childNode != null && childNode.getFirstChild() != null)
{
parentNodeList = dom.getElementsByTagName("Detail2");
int parentNodeListLen = parentNodeList.getLength();
System.out.println("##### Number of node in parentNodeListLen : "+parentNodeListLen);
//Added by AMOL[If no record selected] START
/*for(int ctr2 = 0; ctr2 < parentNodeListLen; ctr2++ )
String valStr = childNode.getFirstChild().getNodeValue();
System.out.println("#### valStr "+valStr);
if(valStr.equalsIgnoreCase("true"))
{
node = parentNodeList.item(ctr);
childNodeName = node.getNodeName();
element = (Element) node;
count2 ++;
}
}
}
if(element.getElementsByTagName("selectbox").item(0) != null)
}
} catch (Exception e)
{
count2++;
e.printStackTrace();
}
}
if(count2 == 0)
{
System.out.println("###### COUNT "+count2);
errCode = "VTBLNKDTL";
errList.add(errCode);
errFields.add("selectbox");
errFields.add("selected");
}
count2 = 0;
//Added by AMOL[If no record selected] END
count2 = 0 ;
if(parentNodeListLen == 0)
{
errCode = "VTINVSEL";
errList.add(errCode);
errFields.add("invoice_id".toLowerCase());
}*/
}
else if("sale_quotitems".equalsIgnoreCase(formName))
{
System.out.println("##### APPLY VALIDATION @@@@@");
parentNodeList = dom.getElementsByTagName("Detail3");
int parentNodeListLen = parentNodeList.getLength();
//Element childElem = null;
for ( int rowCnt=0; rowCnt < parentNodeListLen; rowCnt++ )
{
parentNode = parentNodeList.item(rowCnt);
......@@ -344,20 +371,70 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("#### Detail 3 Name [ "+childNodeName+"]");
if (childNodeName.equalsIgnoreCase("discount"))
if(childNodeName.equalsIgnoreCase("sr_no"))
{
srNoStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("sr_no", dom));
System.out.println("###### srNoStr ["+srNoStr+"]");
if(srNoStr == null)
{
errCode = "INVSRNO";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
else if (childNodeName.equalsIgnoreCase("rate__new"))
}
else if(childNodeName.equalsIgnoreCase("qty_per_month"))
{
quantityStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("qty_per_month", dom));
System.out.println("###### quantityStr ["+quantityStr+"]");
if(quantityStr.isEmpty())
{
errCode = "INVQTYPM";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
else if (childNodeName.equalsIgnoreCase("comm_perc"))
else if(childNodeName.equalsIgnoreCase("item_code"))
{
itemCodeStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("item_code", dom));
System.out.println("###### item_code ["+itemCodeStr+"]");
if(itemCodeStr.isEmpty())
{
errCode = "INVITMCO";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
else if(childNodeName.equalsIgnoreCase("rate"))
{
rateStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("rate", dom));
System.out.println("###### rateStr ["+rateStr+"]");
if(rateStr.isEmpty())
{
errCode = "INVRATE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
else if (childNodeName.equalsIgnoreCase("rate__new"))
{
newRateStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("rate__new", dom));
System.out.println("###### newRateStr ["+newRateStr+"]");
if(newRateStr.isEmpty())
{
errCode = "INVNEWRT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
}
}
}
int errListSize = errList.size();
......@@ -620,16 +697,16 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
System.out.println("#### Does preDomExist : "+preDomExist );
System.out.println("#### currentCustCode "+currentCustCode );
System.out.println("#### preViousCustCode "+preViousCustCode );
System.out.println("#### preViousCustCode "+firstFormDetailMap.get("CustCode") );
System.out.println("#### currentFromDate "+currentFromDate );
System.out.println("#### preViousFromDate "+preViousFromDate );
System.out.println("#### preViousFromDate "+firstFormDetailMap.get("FromDate") );
System.out.println("#### currentToDate "+currentToDate );
System.out.println("#### preViousToDate "+preViousToDate );
System.out.println("#### preViousToDate "+firstFormDetailMap.get("ToDate") );
if(preDomExist && currentCustCode.equals(preViousCustCode) && currentFromDate.equals(preViousFromDate) && currentToDate.equals(preViousToDate))
if(preDomExist && currentCustCode.equals(firstFormDetailMap.get("CustCode")) && currentFromDate.equals(firstFormDetailMap.get("FromDate")) && currentToDate.equals(firstFormDetailMap.get("ToDate")))
{
System.out.println("<<<<<<<<<<< Re Draw Existing Data >>>>>>>>>");
System.out.println("<<<<<<<<<<< preDomExists Data >>>>>>>>>");
//selectedItem = getPrevFormValues( dom2, formNo, new ArrayList<String>(Arrays.asList(temp)), "strg_code" ) ;
}
else
......@@ -643,11 +720,16 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
toDateStr = checkNull(genericUtility.getColumnValue("to_date", dom1));
discountType = checkNull(genericUtility.getColumnValue("discount_type", dom1));
preViousCustCode = custCode;
/*preViousCustCode = custCode;
preViousFromDate = fromDateStr;
preViousToDate = toDateStr;
preViousToDate = toDateStr;*/
firstFormDetailMap.put("CustCode", custCode);
firstFormDetailMap.put("FromDate", fromDateStr);
firstFormDetailMap.put("ToDate", toDateStr);
System.out.println("#### preViousCustCode "+preViousCustCode );
System.out.println("#### preViousCustCode "+firstFormDetailMap.get("CustCode"));
System.out.println("#### preViousCustCode "+firstFormDetailMap.get("FromDate"));
System.out.println("#### preViousCustCode "+firstFormDetailMap.get("ToDate"));
toDate = Timestamp.valueOf(genericUtility.getValidDateString(toDateStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
......@@ -667,11 +749,40 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
//String newSrNo = getSrNo(dom2);
//System.out.println("#### New SrNo ");
valueXmlString.append("<Detail2 domID=\""+""+"\" selected=\"N\" > \r\n");
String newSrNo = "";
System.out.println("######### srNoSet size "+srNoSet.size());
if(copyOfsrNoSet != null)
{
srNoSet.addAll(copyOfsrNoSet);//Add new sr No Form 2
copyOfsrNoSet.clear();////Add new sr No Form 2
}
if(!srNoSet.isEmpty())
{
newSrNo = (srNoSet.size()+1)+"";
//srNoSet.add(srNoSet.size()+1);
//srNoSet.clear();
}
else
{
newSrNo = getLineNo(dom2);
System.out.println("######### New SrNo "+newSrNo);
if("0".equals(newSrNo))
{
System.out.println("######## ZerO SeT...");
newSrNo = "1";
}
}
System.out.println("######### AFter New SrNo "+newSrNo);
valueXmlString.append("<Detail2 domID=\""+newSrNo+"\" selected=\"N\" > \r\n");
valueXmlString.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valueXmlString.append("<quot_no/>");
valueXmlString.append( "<line_no protect='1'><![CDATA[" ).append("").append( "]]></line_no>\r\n" );
valueXmlString.append("<sr_no><![CDATA[" ).append("").append( "]]></sr_no>\r\n" );
valueXmlString.append( "<line_no protect='1'><![CDATA[" ).append(newSrNo).append( "]]></line_no>\r\n" );
valueXmlString.append("<sr_no><![CDATA[" ).append(newSrNo).append( "]]></sr_no>\r\n" );
valueXmlString.append("<item_code><![CDATA[" ).append("").append( "]]></item_code>\r\n" );
valueXmlString.append("<item_descr><![CDATA[" ).append("").append( "]]></item_descr>\r\n" );
valueXmlString.append("<unit><![CDATA[" ).append("").append( "]]></unit>\r\n" );
......@@ -701,26 +812,72 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
}
else if(currentColumn.trim().equalsIgnoreCase("item_code"))
{
Map<String, String> itemDetailMap = new HashMap<String, String>();
try
{
StringBuffer valXmlStr = new StringBuffer();
String currDomStr = genericUtility.serializeDom(dom);
String itemCode = checkNull(genericUtility.getColumnValue("item_code", dom));
double quantity = getDoubleValue(checkNull(genericUtility.getColumnValue("qty_per_month", dom)));
discountType = checkNull(genericUtility.getColumnValue("discount_type",dom));
itemDetailMap = getItemData(itemCode, conn);
double actualCost = getCostRate(conn, itemCode);
double discount2 = getRate(conn, globaldisPriceList, itemCode);
double rate2 = getRate(conn, globalpriceList, itemCode);
Double grossRate2 = ((rate2 - ((rate2 * discount2) / 100)));
if(grossRate2.isNaN() || grossRate2.isInfinite())
{
grossRate2 = 0.0;
}
double comm = 0;
try
{
comm = getCommision(globalcommTable,currDate,conn,itemCode);
}
catch(Exception e)
{
comm = 0;
}
double commPerUnit2 = (((grossRate2 * comm) / 100));
double newCostRate2 = ((grossRate2 - commPerUnit2));
double costRate2 = getCostRate(conn, itemCode);
double availblStock = getStockDetails(conn,itemCode);
double profit2 = (newCostRate - costRate);
String profitParse = String.format("%.2f", profit);
double profitOnGoods2 = (Double.parseDouble(profitParse) * quantity);
double finalPrice2 = (grossRate2 * quantity);
Double percProfit2 = ((profitOnGoods2 / finalPrice2) * 100);
if(percProfit2.isNaN() || percProfit2.isInfinite())
{
percProfit2 = 0.0;
}
valXmlStr.append("<quot_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("quot_no",dom)) +"]]>").append("</quot_no>");
valXmlStr.append("<sr_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("sr_no",dom)) +"]]>").append("</sr_no>");
valXmlStr.append("<line_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("sr_no",dom)) +"]]>").append("</line_no>");
valXmlStr.append("<line_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("line_no",dom)) +"]]>").append("</line_no>");
valXmlStr.append("<item_code protect='1'><![CDATA[" ).append(itemCode).append( "]]></item_code>\r\n" );
valXmlStr.append("<item_descr><![CDATA[" ).append(itemDetailMap.get("descr")).append( "]]></item_descr>\r\n" );
valXmlStr.append("<unit><![CDATA[" ).append(itemDetailMap.get("unit")).append( "]]></unit>\r\n" );
valXmlStr.append("<cost_rate><![CDATA[" ).append(getCommaSep (actualCost)).append( "]]></cost_rate>\r\n" );
valXmlStr.append("<available_stock><![CDATA[" ).append( getCommaSep(availblStock)).append( "]]></available_stock>\r\n" );
valXmlStr.append("<qty_per_month><![CDATA[" ).append(quantity).append( "]]></qty_per_month>\r\n" );
valXmlStr.append("<rate><![CDATA[" ).append(String.format ("%.2f", rate2)).append( "]]></rate>\r\n" );
valXmlStr.append("<discount_type><![CDATA[" ).append(discountType).append( "]]></discount_type>\r\n" );
valXmlStr.append("<discount><![CDATA[" ).append(String.format ("%.2f", discount2)).append( "]]></discount>\r\n" );
valXmlStr.append("<gross_rate><![CDATA[" ).append(String.format ("%.2f", grossRate2)).append( "]]></gross_rate>\r\n" );
valXmlStr.append("<comm_perc><![CDATA[" ).append(String.format ("%.2f", comm)).append( "]]></comm_perc>\r\n" );
valXmlStr.append("<comm_per_unit><![CDATA[" ).append(String.format ("%.2f",commPerUnit2)).append( "]]></comm_per_unit>\r\n" );
valXmlStr.append("<rate__new><![CDATA[" ).append(Math.round(grossRate2)).append( "]]></rate__new>\r\n" );
valXmlStr.append("<basic_dist_price><![CDATA[" ).append(getCommaSep(newCostRate2)).append( "]]></basic_dist_price>\r\n" );
valXmlStr.append("<cost_rate><![CDATA[" ).append( String.format("%.2f", costRate2)).append( "]]></cost_rate>\r\n" );
valXmlStr.append("<profit><![CDATA[" ).append( getCommaSep(profit2) ).append( "]]></profit>\r\n" );
valXmlStr.append("<profit_on_goods><![CDATA[" ).append( getCommaSep( profitOnGoods2 ) ).append( "]]></profit_on_goods>\r\n" );
valXmlStr.append("<final_price><![CDATA[" ).append( getCommaSep( finalPrice2 ) ).append( "]]></final_price >\r\n" );
valXmlStr.append("<perc_profit><![CDATA[" ).append( getCommaSep( percProfit2 ) ).append( "]]></perc_profit>\r\n" );
valXmlStr.append("<available_stock><![CDATA[" ).append( getCommaSep( availblStock ) ).append( "]]></available_stock>\r\n" );
valXmlStr.append("</Detail2>");
currDomStr = currDomStr.replace("</Detail2>",valXmlStr.toString());
......@@ -733,7 +890,7 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
}
}
/*else if(currentColumn.trim().equalsIgnoreCase("qty_per_month"))
else if(currentColumn.trim().equalsIgnoreCase("qty_per_month"))
{
String currDomStr = genericUtility.serializeDom(dom);
......@@ -779,10 +936,204 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> qty_per_month :"+e);
}
}*/
//END 08-10-18
//valueXmlString.append("</Root>");
}
else if(currentColumn.trim().equalsIgnoreCase("discount"))
{
try
{
String currDomStr = genericUtility.serializeDom(dom);
StringBuffer valueXmlStr = new StringBuffer();
qtyMonth = checkNull(genericUtility.getColumnValue("qty_per_month",dom));
rate = checkNull(genericUtility.getColumnValue("rate",dom));
discount = checkNull(genericUtility.getColumnValue("discount",dom));
grossRate = checkNull(genericUtility.getColumnValue("gross_rate",dom));
commission = checkNull(genericUtility.getColumnValue("comm_perc",dom));
commissionPerUnit = checkNull(genericUtility.getColumnValue("comm_per_unit",dom));
costRate = getDoubleValue(checkNull(genericUtility.getColumnValue("cost_rate",dom)));
discountType = checkNull(genericUtility.getColumnValue("discount_type",dom));
System.out.println("#### discountType "+discountType);
if(discountType != null && discountType.equalsIgnoreCase("FIX"))
{
newGrossRate = (getDoubleValue(rate) -getDoubleValue(discount));
}
else
{
newGrossRate = (((getDoubleValue(rate) - ((getDoubleValue(rate) * getDoubleValue(discount)) / 100))));
}
if( newGrossRate.isNaN() || newGrossRate.isInfinite())
{
newGrossRate = 0.0;
}
commPerUnit = (((newGrossRate * getDoubleValue(commission)) / 100));
if( commPerUnit.isNaN() || commPerUnit.isInfinite())
{
commPerUnit = 0.0;
}
newCostRate = ((newGrossRate - commPerUnit));
profit = (newCostRate - costRate);
String profitParse = String.format("%.2f", profit);
profitOnGoods = (getDoubleValue(profitParse) * getDoubleValue(qtyMonth));
finalPrice = (newGrossRate * getDoubleValue(qtyMonth));
percProfit = ((profitOnGoods / finalPrice) * 100);
if( percProfit.isNaN() || percProfit.isInfinite())
{
percProfit = 0.0;
}
valueXmlStr.append("<quot_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("quot_no",dom)) +"]]>").append("</quot_no>");
valueXmlStr.append("<line_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("line_no",dom)) +"]]>").append("</line_no>");
valueXmlStr.append("<discount><![CDATA[" ).append(String.format ("%.2f", Double.parseDouble(discount))).append( "]]></discount>\r\n" );
valueXmlStr.append("<gross_rate><![CDATA[" ).append(String.format ("%.2f", newGrossRate)).append( "]]></gross_rate>\r\n" );
valueXmlStr.append("<comm_per_unit><![CDATA[" ).append(String.format ("%.2f", commPerUnit)).append( "]]></comm_per_unit>\r\n" );
valueXmlStr.append("<rate__new><![CDATA[" ).append(Math.round(newGrossRate)).append( "]]></rate__new>\r\n" );
valueXmlStr.append("<basic_dist_price><![CDATA[" ).append( getCommaSep(newCostRate) ).append( "]]></basic_dist_price>\r\n" );
valueXmlStr.append("<cost_rate><![CDATA[" ).append(String.format("%.2f",costRate)).append( "]]></cost_rate>\r\n" );
valueXmlStr.append("<profit><![CDATA[" ).append( getCommaSep(profit)).append( "]]></profit>\r\n" );
valueXmlStr.append("<profit_on_goods><![CDATA[" ).append( getCommaSep(profitOnGoods) ).append( "]]></profit_on_goods>\r\n" );
valueXmlStr.append("<final_price><![CDATA[" ).append( getCommaSep(finalPrice) ).append( "]]></final_price>\r\n" );
valueXmlStr.append("<perc_profit><![CDATA[" ).append( getCommaSep(percProfit) ).append( "]]></perc_profit>\r\n" );
valueXmlStr.append("</Detail2>");
currDomStr = currDomStr.replace("</Detail2>", valueXmlStr.toString());
valueXmlString.append(currDomStr);
}
catch (Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> discount :"+e);
}
}
else if(currentColumn.trim().equalsIgnoreCase("rate__new"))
{
try
{
StringBuffer valueXmlStr = new StringBuffer();
String currDomStr = genericUtility.serializeDom(dom);
newGrossRate = getDoubleValue(checkNull(genericUtility.getColumnValue("rate__new",dom)));
commission = checkNull(genericUtility.getColumnValue("comm_perc",dom));
qtyMonth = checkNull(genericUtility.getColumnValue("qty_per_month",dom));
commPerUnit = (((newGrossRate * getDoubleValue(commission)) / 100));
if(commPerUnit.isNaN() || commPerUnit.isInfinite())
{
commPerUnit = 0.0;
}
newCostRate = ((newGrossRate - commPerUnit));
profit = (newCostRate - costRate);
String profitParse = String.format("%.2f", profit);
profitOnGoods = (getDoubleValue(profitParse) * getDoubleValue(qtyMonth));
finalPrice = (newGrossRate * getDoubleValue(qtyMonth));
percProfit = ((profitOnGoods / finalPrice) * 100);
if(percProfit.isNaN() || percProfit.isInfinite())
{
percProfit = 0.0;
}
valueXmlStr.append("<comm_per_unit><![CDATA[" ).append(String.format ("%.2f", commPerUnit)).append( "]]></comm_per_unit>\r\n" );
valueXmlStr.append("<rate__new><![CDATA[" ).append(Math.round(newGrossRate)).append( "]]></rate__new>\r\n" );
valueXmlStr.append("<basic_dist_price><![CDATA[" ).append( getCommaSep(newCostRate)).append( "]]></basic_dist_price>\r\n" );
valueXmlStr.append("<profit><![CDATA[" ).append( getCommaSep(profit)).append( "]]></profit>\r\n" );
valueXmlStr.append("<profit_on_goods><![CDATA[" ).append( getCommaSep(profitOnGoods) ).append( "]]></profit_on_goods>\r\n" );
valueXmlStr.append("<final_price><![CDATA[" ).append( getCommaSep(finalPrice) ).append( "]]></final_price>\r\n" );
valueXmlStr.append("<perc_profit><![CDATA[" ).append( getCommaSep(percProfit) ).append( "]]></perc_profit>\r\n" );
valueXmlStr.append("</Detail2>");
currDomStr = currDomStr.replace("</Detail2>", valueXmlStr.toString());
valueXmlString.append(currDomStr);
}
catch(Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> New Rate :"+e);
}
}
else if(currentColumn.trim().equalsIgnoreCase("comm_perc"))
{
try
{
String currDomStr = genericUtility.serializeDom(dom);
StringBuffer valueXmlStr = new StringBuffer();
qtyMonth = checkNull(genericUtility.getColumnValue("qty_per_month",dom));
rate = checkNull(genericUtility.getColumnValue("rate",dom));
discount = checkNull(genericUtility.getColumnValue("discount",dom));
grossRate = checkNull(genericUtility.getColumnValue("gross_rate",dom));
commission = checkNull(genericUtility.getColumnValue("comm_perc",dom));
commissionPerUnit = checkNull(genericUtility.getColumnValue("comm_per_unit",dom));
costRate = getDoubleValue(checkNull(genericUtility.getColumnValue("cost_rate",dom)));
discountType = checkNull(genericUtility.getColumnValue("discount_type",dom));
if(discountType != null && discountType.equalsIgnoreCase("FIX"))
{
newGrossRate = (getDoubleValue(rate) -getDoubleValue(discount));
}
else
{
newGrossRate = (((getDoubleValue(rate) - ((getDoubleValue(rate) * getDoubleValue(discount)) / 100))));
}
if(newGrossRate.isNaN() || newGrossRate.isInfinite())
{
newGrossRate = 0.0;
}
commPerUnit = (((newGrossRate * getDoubleValue(commission)) / 100));
if(commPerUnit.isNaN() || commPerUnit.isInfinite())
{
commPerUnit = 0.0;
}
newCostRate = ((newGrossRate - commPerUnit));
profit = (newCostRate - costRate);
String profitParse = String.format("%.2f", profit);
profitOnGoods = (getDoubleValue(profitParse) * getDoubleValue(qtyMonth));
finalPrice = (newGrossRate * getDoubleValue(qtyMonth));
percProfit = ((profitOnGoods / finalPrice) * 100);
if(percProfit.isNaN() || percProfit.isInfinite())
{
percProfit = 0.0;
}
valueXmlStr.append("<quot_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("quot_no",dom)) +"]]>").append("</quot_no>");
valueXmlStr.append("<line_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("line_no",dom)) +"]]>").append("</line_no>");
valueXmlStr.append("<discount><![CDATA[" ).append(String.format ("%.2f", Double.parseDouble(discount))).append( "]]></discount>\r\n" );
valueXmlStr.append("<gross_rate><![CDATA[" ).append(String.format ("%.2f", newGrossRate)).append( "]]></gross_rate>\r\n" );
valueXmlStr.append("<comm_per_unit><![CDATA[" ).append(String.format ("%.2f", commPerUnit)).append( "]]></comm_per_unit>\r\n" );
valueXmlStr.append("<rate__new><![CDATA[" ).append(Math.round(newGrossRate)).append( "]]></rate__new>\r\n" );
valueXmlStr.append("<basic_dist_price><![CDATA[" ).append( getCommaSep(newCostRate)).append( "]]></basic_dist_price>\r\n" );
valueXmlStr.append("<cost_rate><![CDATA[" ).append(String.format("%.2f", costRate)).append( "]]></cost_rate>\r\n" );
valueXmlStr.append("<profit><![CDATA[" ).append( getCommaSep(profit)).append( "]]></profit>\r\n" );
valueXmlStr.append("<profit_on_goods><![CDATA[" ).append( getCommaSep(profitOnGoods) ).append( "]]></profit_on_goods>\r\n" );
valueXmlStr.append("<final_price><![CDATA[" ).append( getCommaSep(finalPrice) ).append( "]]></final_price>\r\n" );
valueXmlStr.append("<perc_profit><![CDATA[" ).append( getCommaSep(percProfit) ).append( "]]></perc_profit>\r\n" );
valueXmlStr.append("</Detail2>");
currDomStr = currDomStr.replace("</Detail2>", valueXmlStr.toString());
valueXmlString.append(currDomStr);
}
catch (Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> comm_perc :"+e);
}
}
//valueXmlString.append("</Root>");//It is for Final return.
}
else if("sale_quotitems".equals(formName) || "3".equalsIgnoreCase(objContext))
{
if(currentColumn.trim().equalsIgnoreCase("itm_default"))
......@@ -887,9 +1238,9 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
valueXmlStr.append("<comm_per_unit><![CDATA[" ).append(String.format ("%.2f", commPerUnit)).append( "]]></comm_per_unit>\r\n" );
valueXmlStr.append("<rate__new><![CDATA[" ).append(Math.round(newGrossRate)).append( "]]></rate__new>\r\n" );
//valueXmlStr.append("<basic_dist_price><![CDATA[" ).append(String.format ("%.2f", newCostRate)).append( "]]></basic_dist_price>\r\n" );
//valueXmlStr.append("<cost_rate><![CDATA[" ).append(String.format ("%.2f", costRate)).append( "]]></cost_rate>\r\n" );
valueXmlStr.append("<basic_dist_price><![CDATA[" ).append( getCommaSep(newCostRate) ).append( "]]></basic_dist_price>\r\n" );
valueXmlStr.append("<cost_rate><![CDATA[" ).append( getCommaSep(costRate)).append( "]]></cost_rate>\r\n" );
valueXmlStr.append("<cost_rate><![CDATA[" ).append(String.format ("%.2f", costRate)).append( "]]></cost_rate>\r\n" );
/*valueXmlStr.append("<profit><![CDATA[" ).append(String.format ("%.2f", profit)).append( "]]></profit>\r\n" );
valueXmlStr.append("<profit_on_goods><![CDATA[" ).append(String.format ("%.2f", profitOnGoods)).append( "]]></profit_on_goods>\r\n" );
valueXmlStr.append("<final_price><![CDATA[" ).append(String.format ("%.2f", finalPrice)).append( "]]></final_price>\r\n" );
......@@ -1017,9 +1368,9 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
valueXmlStr.append("<comm_per_unit><![CDATA[" ).append(String.format ("%.2f", commPerUnit)).append( "]]></comm_per_unit>\r\n" );
valueXmlStr.append("<rate__new><![CDATA[" ).append(Math.round(newGrossRate)).append( "]]></rate__new>\r\n" );
//valueXmlStr.append("<basic_dist_price><![CDATA[" ).append(String.format ("%.2f", newCostRate)).append( "]]></basic_dist_price>\r\n" );
//valueXmlStr.append("<cost_rate><![CDATA[" ).append(String.format ("%.2f", costRate)).append( "]]></cost_rate>\r\n" );
valueXmlStr.append("<basic_dist_price><![CDATA[" ).append( getCommaSep(newCostRate)).append( "]]></basic_dist_price>\r\n" );
valueXmlStr.append("<cost_rate><![CDATA[" ).append(getCommaSep(costRate)).append( "]]></cost_rate>\r\n" );
valueXmlStr.append("<cost_rate><![CDATA[" ).append(String.format ("%.2f", costRate)).append( "]]></cost_rate>\r\n" );
/*valueXmlStr.append("<profit><![CDATA[" ).append(String.format ("%.2f", profit)).append( "]]></profit>\r\n" );
valueXmlStr.append("<profit_on_goods><![CDATA[" ).append(String.format ("%.2f", profitOnGoods)).append( "]]></profit_on_goods>\r\n" );
valueXmlStr.append("<final_price><![CDATA[" ).append(String.format ("%.2f", finalPrice)).append( "]]></final_price>\r\n" );
......@@ -1143,22 +1494,68 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
StringBuffer valXmlStr = new StringBuffer();
String currDomStr = genericUtility.serializeDom(dom);
String itemCode = checkNull(genericUtility.getColumnValue("item_code", dom));
double quantity = getDoubleValue(checkNull(genericUtility.getColumnValue("qty_per_month", dom)));
discountType = checkNull(genericUtility.getColumnValue("discount_type",dom));
itemDetailMap = getItemData(itemCode, conn);
double actualCost = getCostRate(conn, itemCode);
double discount2 = getRate(conn, globaldisPriceList, itemCode);
double rate2 = getRate(conn, globalpriceList, itemCode);
Double grossRate2 = ((rate2 - ((rate2 * discount2) / 100)));
if(grossRate2.isNaN() || grossRate2.isInfinite())
{
grossRate2 = 0.0;
}
double comm = 0;
try
{
comm = getCommision(globalcommTable,currDate,conn,itemCode);
}
catch(Exception e)
{
comm = 0;
}
double commPerUnit2 = (((grossRate2 * comm) / 100));
double newCostRate2 = ((grossRate2 - commPerUnit2));
double costRate2 = getCostRate(conn, itemCode);
double availblStock = getStockDetails(conn,itemCode);
double profit2 = (newCostRate - costRate);
String profitParse = String.format("%.2f", profit);
double profitOnGoods2 = (Double.parseDouble(profitParse) * quantity);
double finalPrice2 = (grossRate2 * quantity);
Double percProfit2 = ((profitOnGoods2 / finalPrice2) * 100);
if(percProfit2.isNaN() || percProfit2.isInfinite())
{
percProfit2 = 0.0;
}
valXmlStr.append("<quot_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("quot_no",dom)) +"]]>").append("</quot_no>");
valXmlStr.append("<line_no>").append("<![CDATA["+ checkNull(genericUtility.getColumnValue("line_no",dom)) +"]]>").append("</line_no>");
valXmlStr.append("<item_code protect='1'><![CDATA[" ).append(itemCode).append( "]]></item_code>\r\n" );
valXmlStr.append("<item_descr><![CDATA[" ).append(itemDetailMap.get("descr")).append( "]]></item_descr>\r\n" );
valXmlStr.append("<unit><![CDATA[" ).append(itemDetailMap.get("unit")).append( "]]></unit>\r\n" );
valXmlStr.append("<cost_rate><![CDATA[" ).append(getCommaSep (actualCost)).append( "]]></cost_rate>\r\n" );
valXmlStr.append("<available_stock><![CDATA[" ).append( getCommaSep(availblStock)).append( "]]></available_stock>\r\n" );
valXmlStr.append("<qty_per_month><![CDATA[" ).append(quantity).append( "]]></qty_per_month>\r\n" );
valXmlStr.append("<rate><![CDATA[" ).append(String.format ("%.2f", rate2)).append( "]]></rate>\r\n" );
valXmlStr.append("<discount_type><![CDATA[" ).append(discountType).append( "]]></discount_type>\r\n" );
valXmlStr.append("<discount><![CDATA[" ).append(String.format ("%.2f", discount2)).append( "]]></discount>\r\n" );
valXmlStr.append("<gross_rate><![CDATA[" ).append(String.format ("%.2f", grossRate2)).append( "]]></gross_rate>\r\n" );
valXmlStr.append("<comm_perc><![CDATA[" ).append(String.format ("%.2f", comm)).append( "]]></comm_perc>\r\n" );
valXmlStr.append("<comm_per_unit><![CDATA[" ).append(String.format ("%.2f",commPerUnit2)).append( "]]></comm_per_unit>\r\n" );
valXmlStr.append("<rate__new><![CDATA[" ).append(Math.round(grossRate2)).append( "]]></rate__new>\r\n" );
valXmlStr.append("<basic_dist_price><![CDATA[" ).append(getCommaSep(newCostRate2)).append( "]]></basic_dist_price>\r\n" );
valXmlStr.append("<cost_rate><![CDATA[" ).append( String.format("%.2f", costRate2)).append( "]]></cost_rate>\r\n" );
valXmlStr.append("<profit><![CDATA[" ).append( getCommaSep(profit2) ).append( "]]></profit>\r\n" );
valXmlStr.append("<profit_on_goods><![CDATA[" ).append( getCommaSep( profitOnGoods2 ) ).append( "]]></profit_on_goods>\r\n" );
valXmlStr.append("<final_price><![CDATA[" ).append( getCommaSep( finalPrice2 ) ).append( "]]></final_price >\r\n" );
valXmlStr.append("<perc_profit><![CDATA[" ).append( getCommaSep( percProfit2 ) ).append( "]]></perc_profit>\r\n" );
valXmlStr.append("<available_stock><![CDATA[" ).append( getCommaSep( availblStock ) ).append( "]]></available_stock>\r\n" );
valXmlStr.append("</Detail3>");
currDomStr = currDomStr.replace("</Detail3>",valXmlStr.toString());
//currDomStr = currDomStr.replace("</Detail3>",valXmlStr.toString()+"</Detail3>");
valueXmlString.append(currDomStr);
}
......@@ -1636,6 +2033,7 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
Timestamp toDate, StringBuffer valueXmlString, String siteCode,String discountType) throws Exception
{
System.out.println("#### getInvoiceDetail ....");
srNoSet = new HashSet();//
PreparedStatement pstmt = null;
PreparedStatement pstmt1 = null;
ResultSet rs = null;
......@@ -1647,6 +2045,11 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
String priceList = E12GenericUtility.checkNull(getDBColumnValue("CUSTOMER", "PRICE_LIST", "CUST_CODE = '"+custCode+"'", conn));
//String commTable = E12GenericUtility.checkNull(getDBColumnValue("CUSTOMER", "COMM_TABLE", "CUST_CODE = '"+custCode+"'", conn));
String commTable = getCommission(custCode, conn);
globaldisPriceList = disPriceList;
globalpriceList = priceList;
globalcommTable = commTable;
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String eventDateStr = "";
//String discountType = "";
......@@ -1723,7 +2126,7 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
Iterator<Map.Entry<String, Double>> itr = map.entrySet().iterator();
//DistCommon distCommon = new DistCommon();
DistCommon distCommon = new DistCommon();
int srNo = 0;
......@@ -1732,6 +2135,7 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
while(itr.hasNext())
{
srNo++;
srNoSet.add(srNo);//added on 10-10-18 Add new Form no2 to get srNo.
Map.Entry<String, Double> entry = itr.next();
String itemCode = E12GenericUtility.checkNull(entry.getKey());
......@@ -1739,10 +2143,10 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
double maxValue = entry.getValue();
itemDetailMap = getItemData(itemCode, conn);
/*double discount = (distCommon.pickRate(disPriceList, eventDateStr, entry.getKey(), conn));
double rate = (distCommon.pickRate(priceList, eventDateStr, entry.getKey(), conn));*/
double discount = (distCommon.pickRate(disPriceList, eventDateStr, entry.getKey(), conn));
//double rate = (distCommon.pickRate(priceList, eventDateStr, entry.getKey(), conn));*/
System.out.println("##### Setting Discount disPriceList "+disPriceList);
double discount = getRate(conn, disPriceList, itemCode);
// double discount = getRate(conn, disPriceList, itemCode);
System.out.println("##### Setting rate priceList "+priceList);
double rate = getRate(conn, priceList, itemCode);
......@@ -1807,9 +2211,9 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
//valueXmlString.append("<rate__new><![CDATA[" ).append(Math.round(rate)).append( "]]></rate__new>\r\n" );//Changed on 04-10-18 Having Confusion
valueXmlString.append("<rate__new><![CDATA[" ).append(Math.round(grossRate)).append( "]]></rate__new>\r\n" );
//valueXmlString.append("<basic_dist_price><![CDATA[" ).append(String.format ("%.2f", newCostRate)).append( "]]></basic_dist_price>\r\n" );
//valueXmlString.append("<cost_rate><![CDATA[" ).append(String.format ("%.2f", costRate)).append( "]]></cost_rate>\r\n" );
valueXmlString.append("<basic_dist_price><![CDATA[" ).append(getCommaSep(newCostRate)).append( "]]></basic_dist_price>\r\n" );
valueXmlString.append("<cost_rate><![CDATA[" ).append( getCommaSep(costRate)).append( "]]></cost_rate>\r\n" );
valueXmlString.append("<cost_rate><![CDATA[" ).append(String.format ("%.2f", costRate)).append( "]]></cost_rate>\r\n" );
/*valueXmlString.append("<profit><![CDATA[" ).append(String.format ("%.2f", profit)).append( "]]></profit>\r\n" );
valueXmlString.append("<profit_on_goods><![CDATA[" ).append(String.format ("%.2f", profitOnGoods)).append( "]]></profit_on_goods>\r\n" );
valueXmlString.append("<final_price><![CDATA[" ).append(String.format ("%.2f", finalPrice)).append( "]]></final_price >\r\n" );
......@@ -2542,7 +2946,7 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
}
catch (NumberFormatException e)
{
System.out.println("@@@@ Exception in getDoubleValue "+e);
return 0.0;
}
return retVal;
}
......@@ -3305,11 +3709,15 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
}
}
//Added on 09-10-18 To calculate Total Summary.Below code get data for form no2 START
private List<Double> finalPriceList = null;
public List<Double> getGoodsProfitList(String custCode,String fromDateStr,String toDateStr)
private JSONObject finalSummaryProfitMap = null;
public JSONObject getGoodsMap(String custCode, String fromDateStr, String toDateStr)
{
List<Double> profitOnGoodsList = new ArrayList<Double>();
finalPriceList = new ArrayList<Double>();
//
finalSummaryProfitMap = new JSONObject();
JSONObject summaryGoodsMap = new JSONObject();
Connection conn = null;
ConnDriver connDriver = null;
......@@ -3405,6 +3813,8 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
int srNo = 0;
DistCommon distCommon = new DistCommon();
Map<String, String> itemDetailMap = new HashMap<String, String>();
while(itr.hasNext())
......@@ -3417,8 +3827,8 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
double maxValue = entry.getValue();
itemDetailMap = getItemData(itemCode, conn);
double discount = getRate(conn, disPriceList, itemCode);
//double discount = getRate(conn, disPriceList, itemCode);
double discount = (distCommon.pickRate(disPriceList, eventDateStr, entry.getKey(), conn));
double rate = getRate(conn, priceList, itemCode);
Double grossRate = ((rate - ((rate * discount) / 100)));
......@@ -3447,11 +3857,14 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
String str = String.format("%.2f", profitOnGoods);
double doubleVal = Double.parseDouble(str);
profitOnGoodsList.add(doubleVal);
summaryGoodsMap.put(itemCode, doubleVal);
//profitOnGoodsList.add(doubleVal);
String str2 = String.format("%.2f", finalPrice);
double doubleVal2 = Double.parseDouble(str2);
finalPriceList.add(doubleVal2);
finalSummaryProfitMap.put(itemCode, doubleVal2);
//finalPriceList.add(doubleVal2);
System.out.println("@@@@@@@@ profitOnGoods ["+doubleVal+"] finalPrice["+doubleVal2+"]");
......@@ -3462,15 +3875,35 @@ public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposal
{
e.printStackTrace();
}
System.out.println("@@@@@@@ profitOnGoodsList ["+profitOnGoodsList+"]");
return profitOnGoodsList;
finally
{
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {}
}
}
System.out.println("@@@@@@@ summaryGoodsMap ["+summaryGoodsMap+"]");
//
return summaryGoodsMap;
}
public JSONObject getFinalMap()
{
return finalSummaryProfitMap;
}
public List<Double> getFinalPriceList()
private String getLineNo(Document docu)
{
System.out.println("@@@@@@ finalPriceList ["+finalPriceList+"]");
return finalPriceList;
//String srNo = "";
NodeList parentNList = docu.getElementsByTagName("Detail2");
int nListLen = parentNList.getLength();
System.out.println("####Detail2 Lenght "+nListLen);
return String.valueOf(nListLen);
}
//Added on 09-10-18 To calculate Total Summary.Below code get data for form no2 END
}
\ No newline at end of file
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