Commit 0f1c70f1 authored by asant's avatar asant

Added component for CHT pricing menu

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@190917 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 03cbd833
/********************************************************
Title : SalesQuotProposal
Date : 24/06/18
Author: Pankaj R
********************************************************/
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.io.ByteArrayOutputStream;
import java.net.InetAddress;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import org.apache.poi.hssf.record.formula.functions.Int;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
// added for ejb3
@Stateless // added for ejb3
public class SalesQuotProposal extends ValidatorEJB implements SalesQuotProposalLocal, SalesQuotProposalRemote
{
E12GenericUtility genericUtility = new E12GenericUtility();
ArrayList<String> itemCodeArr = new ArrayList<String>();
NumberFormat formatter = new DecimalFormat("#0.00");
private int globalNo = 0;
private String oldRate = "";
private String currentCustCode = "",currentFromDate = "",currentToDate = "";
private String preViousCustCode = "",preViousFromDate = "",preViousToDate = "";
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
}
catch(Exception e)
{
throw new ITMException( e );
}
return (errString);
}
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException
{
System.out.println("SalesQuotProposal formName : "+formName);
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
System.out.println("###### SalesQuotProposal xmlString:-" + xmlString );
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0 )
{
dom2 = parseString("<Root>" + xmlString2+ "</Root>");
}
System.out.println("###### SalesQuotProposal objContext["+objContext+"]\nwfValData.xmlString1["+xmlString1+"]");
System.out.println("###### wfValData.xmlString2["+xmlString2+"]");
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams, formName);
System.out.println("###### errString[" + errString+"]" );
}
catch(Exception e)
{
throw new ITMException( e );
}
return (errString);
}
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException
{
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;
Connection conn = null;
PreparedStatement pstmt = null ;
ResultSet rs = null , rs1 = null;
int cnt = 0, currentFormNo=0,childNodeListLength ,ctr=0;
ConnDriver connDriver = new ConnDriver();
String errString = "", errCode = "",userId = "";
ArrayList <String> errList = new ArrayList<String>();
ArrayList <String>errFields = new ArrayList <String> ();
String errorType = "";
String custCode= "", validUptoStr = "",effFromStr = "", fromDtStr = "", toDtStr = "";
double discount = 0, commPerc = 0, newRate = 0;
Timestamp toDate = null, fromDate = null, validUptoDate = null, effFromDate = null;
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
//Added by AMOL START
StringBuffer formatedInvIds = new StringBuffer();
int count2 = 0;
Node node = null;
Element element = null;
//Added by AMOL END
try
{
connDriver = null;
conn = getConnection();
userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
System.out.println("SalesQuotProposal userId:- " + userId);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
System.out.println("currentFormNo...." + currentFormNo+"\nformName : "+formName);
//sale_quot sale_quotdet sale_quotitems
if("sale_quot".equalsIgnoreCase(formName))
{
parentNodeList = dom.getElementsByTagName("Detail1");
int parentNodeListLen = parentNodeList.getLength();
System.out.println("##### Number of node in parentNodeListLen : "+parentNodeListLen);
for ( int rowCnt=0; rowCnt < parentNodeListLen; rowCnt++ )
{
parentNode = parentNodeList.item(rowCnt);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("##### childNodeName R : "+childNodeName);
if (childNodeName.equalsIgnoreCase("cust_code"))
{
custCode = E12GenericUtility.checkNull(genericUtility.getColumnValue("cust_code", dom));
String str = "select count(1) from customer where cust_code = ?";
int count = 0;
pstmt = conn.prepareStatement(str);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if(rs.next())
{
count = rs.getInt(1);
}
System.out.println("#### count : "+count);
pstmt.close();
pstmt = null;
rs.close();
rs = null;
if(count == 0)
{
errCode = "VMREGCUST";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
else if (childNodeName.equalsIgnoreCase("from_date"))
{
fromDtStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("from_date", dom));
toDtStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("to_date", dom));
if(fromDtStr.length() <= 0 || toDtStr.length() <= 0)
{
errCode = "VTINVFTDT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
fromDate = Timestamp.valueOf(genericUtility.getValidDateString(fromDtStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
toDate = Timestamp.valueOf(genericUtility.getValidDateString(toDtStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
if(toDate == null || fromDate == null)
{
errCode = "VTINVFTDT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
if(toDate.before(fromDate))
{
errCode = "VTINVFRDT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
else if (childNodeName.equalsIgnoreCase("valid_upto"))
{
validUptoStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("valid_upto", dom));
effFromStr = E12GenericUtility.checkNull(genericUtility.getColumnValue("eff_date", dom));
if(validUptoStr.length() <= 0 || effFromStr.length() <= 0)
{
errCode = "VTINVEVDT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
validUptoDate = Timestamp.valueOf(genericUtility.getValidDateString(validUptoStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
effFromDate = Timestamp.valueOf(genericUtility.getValidDateString(effFromStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
if(validUptoDate == null || effFromDate == null)
{
errCode = "VTINVEVDT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
if(validUptoDate.before(effFromDate))
{
errCode = "VTINVEFDT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
//Added by AMOL START
try
{
if( E12GenericUtility.checkNull(custCode).length() > 0 && E12GenericUtility.checkNull(fromDtStr).length() > 0
&& E12GenericUtility.checkNull(toDtStr).length() > 0)
{
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)
{
errCode = "VTNORECFND";
errList.add(errCode);
errFields.add("to_date");
break;
}
}
}
catch(Exception e)
{
System.out.println("#### Exception in WFValDate Invoice_ID "+e);
e.printStackTrace();
}
//Added by AMOL END
}
}
}
else if("sale_quotdet".equalsIgnoreCase(formName))
{
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++ )
{
node = parentNodeList.item(ctr);
childNodeName = node.getNodeName();
element = (Element) node;
if(element.getElementsByTagName("selectbox").item(0) != null)
{
count2++;
}
}
if(count2 == 0)
{
errCode = "VTBLNKDTL";
errList.add(errCode);
errFields.add("selectbox");
}
count2 = 0;*/
//Added by AMOL[If no record selected] END
if(parentNodeListLen == 0)
{
errCode = "VTINVSEL";
errList.add(errCode);
errFields.add("invoice_id".toLowerCase());
}
}
else if("sale_quotitems".equalsIgnoreCase(formName))
{
parentNodeList = dom.getElementsByTagName("Detail3");
int parentNodeListLen = parentNodeList.getLength();
for ( int rowCnt=0; rowCnt < parentNodeListLen; rowCnt++ )
{
parentNode = parentNodeList.item(rowCnt);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equalsIgnoreCase("discount"))
{
}
else if (childNodeName.equalsIgnoreCase("rate__new"))
{
}
else if (childNodeName.equalsIgnoreCase("comm_perc"))
{
}
}
}
}
int errListSize = errList.size();
cnt =0;
String errFldName = null;
if ( errList != null && errListSize > 0 )
{
System.out.println("Inside errList >"+errList);
for (cnt = 0; cnt < errListSize; cnt++)
{
errCode = (String)errList.get(cnt);
System.out.println("errCode :"+errCode);
int pos = errCode.indexOf("~");
System.out.println("pos :"+pos);
if(pos>-1)
{
errCode=errCode.substring(0,pos);
}
System.out.println("##### error code is :"+errCode);
errFldName = (String)errFields.get(cnt);
System.out.println("##### cnt [" + cnt + "] errCode [" + errCode + "] errFldName [" + errFldName + "]");
errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(conn, errCode);
System.out.println("errorType :"+errorType);
if (errString.length() > 0)
{
String bifurErrString = errString.substring(errString.indexOf("<Errors>") +
8, errString.indexOf("<trace>"));
bifurErrString = bifurErrString +
errString.substring(errString.indexOf("</trace>") +
8, errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
errString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
errStringXml.append("</Errors> </Root> \r\n");
}
else
{
errStringXml = new StringBuffer( "" );
}
}//END TRY
catch(Exception e)
{
//System.out.println("Exception ::"+e);
e.printStackTrace();
errString=e.getMessage();
throw new ITMException( e );
}
finally
{
try
{
if(conn!=null)
{
if(rs != null )rs.close();
if(rs1 != null )rs.close();
rs = null;
rs1 = null;
if(pstmt != null )pstmt.close();
pstmt =null;
conn.close();
}
conn = null;
}catch(Exception d)
{
d.printStackTrace();
throw new ITMException( d );
}
}
System.out.println("ErrString ::[ "+errStringXml.toString()+" ]");
return errStringXml.toString();
}
//END OF VALIDATION
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("xmlString...["+xmlString+"]");
System.out.println("xmlString1.....["+xmlString1+"]");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException( e );
}
return valueXmlString;
}
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException
{
System.out.println("###### xmlString 0000 ["+xmlString+"]");
System.out.println("###### xmlString 1111 ["+xmlString1+"]");
System.out.println("###### xmlString 2222 ["+xmlString2+"]");
System.out.println("###### formName["+formName+"]");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0 )
{
dom2 = parseString(xmlString2);
}
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams,formName);
}
catch(Exception e)
{
throw new ITMException(e);
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException
{
System.out.println("#### SalesQuotProposal :: itemChanged 3");
System.out.println("#### SalesQuotProposal :: formName ["+formName+"]");
System.out.println("#### objContext ["+objContext+"]");
System.out.println("#### currentColumn ["+currentColumn+"]");
System.out.println("#### editFlag ["+editFlag+"]");
System.out.println("#### xtraParams ["+xtraParams+"]");
StringBuffer valueXmlString = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ConnDriver connDriver = new ConnDriver();
int currentFormNo = 0 ;
String userId = "",siteCode = "", custCode = "",toDateStr = "", fromDateStr = "", chgTerm = "", custName = "";
String qtyMonth = "", rate = "", discount = "", grossRate = "", commission = "",commissionPerUnit = "",basicPrice ="", newRate ="";
String additionalCost = "",discountType = "";
double newCostRate = 0.0, costRate = 0.0, profit =0.0, profitOnGoods = 0.0,
finalPrice = 0.0, newRte = 0.0, discountDouble = 0.0;
Double newGrossRate =0.0, commPerUnit = 0.0, percProfit = 0.0;
Timestamp toDate = null, fromDate = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
try
{
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
conn = getConnection();
connDriver = null;
java.sql.Timestamp currDate = null;
currDate = new java.sql.Timestamp(System.currentTimeMillis()) ;
/*sordformId = checkNull(genericUtility.getColumnValue("SORDFORM_ID", dom, "1")).trim();
System.out.println("sordformId : "+sordformId);*/
InetAddress ownIP=InetAddress.getLocalHost();
userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
siteCode = getValueFromXTRA_PARAMS(xtraParams,"loginSiteCode");
chgTerm = E12GenericUtility.checkNull(ownIP.getHostAddress());
String currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate).toString();
System.out.println("####### currAppdate : "+currAppdate);
oldRate = checkNull(genericUtility.getColumnValue("rate",dom2));
System.out.println("######## siteCode["+siteCode+"]");
if("sale_quot".equalsIgnoreCase(formName))
{
int domID = 1;
if(currentColumn.trim().equalsIgnoreCase("itm_default"))
{
custCode = genericUtility.getColumnValue("cust_code", dom1);
fromDateStr = genericUtility.getColumnValue("from_date", dom1);
toDateStr = genericUtility.getColumnValue("to_date", dom1);
String effDateStr = genericUtility.getColumnValue("eff_date", dom1);
String validUptoStr = genericUtility.getColumnValue("valid_upto", dom1);
System.out.println("#### currAppdate ["+currAppdate+"]");
System.out.println("#### fromDateStr ["+fromDateStr);
System.out.println("#### toDateStr ["+toDateStr);
System.out.println("#### effDateStr ["+effDateStr);
System.out.println("#### validUptoStr ["+validUptoStr);
valueXmlString.append("<Detail1 domID='"+ domID +"' selected=\"Y\">\r\n");
valueXmlString.append("<attribute selected=\"Y\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valueXmlString.append("<quot_no/>");
valueXmlString.append( "<quot_date protect='1'><![CDATA[" ).append(currAppdate).append( "]]></quot_date>\r\n" );
valueXmlString.append( "<quot_type protect='1'><![CDATA[P]]></quot_type>\r\n" );
valueXmlString.append("<cust_code><![CDATA["+custCode+"]]></cust_code>");
valueXmlString.append("<from_date><![CDATA["+fromDateStr+"]]></from_date>");
valueXmlString.append("<to_date><![CDATA["+toDateStr+"]]></to_date>");
valueXmlString.append("<eff_date><![CDATA["+effDateStr+"]]></eff_date>");
valueXmlString.append("<valid_upto><![CDATA["+validUptoStr+"]]></valid_upto>");
//<<<<<<<<<<<<<<<<<<<<<<<<<<< Make SURE additional_fees added in sales_quot TABLE >>>
valueXmlString.append("<addl_chrg ><![CDATA["+getAdditionalCost(conn)+"]]></addl_chrg >");
valueXmlString.append("<quot_date><![CDATA[" +currAppdate+ "]]></quot_date>");
valueXmlString.append("<chg_date><![CDATA[" +currAppdate+ "]]></chg_date>");
valueXmlString.append("<chg_user><![CDATA[" + userId+ "]]></chg_user>");
valueXmlString.append("<chg_term><![CDATA[" + chgTerm + "]]></chg_term>");
valueXmlString.append("</Detail1>\r\n");
}
else if(currentColumn.trim().equalsIgnoreCase("cust_code"))
{
custCode = checkNull(genericUtility.getColumnValue("cust_code",dom));
fromDateStr = checkNull(genericUtility.getColumnValue("from_date",dom));// Added by AMOL
toDateStr = checkNull(genericUtility.getColumnValue("to_date",dom)); //Added by AMOL
String currDomStr = genericUtility.serializeDom(dom);
StringBuffer valueXmlStr = new StringBuffer();
custName = getDBColumnValue("CUSTOMER", "CUST_NAME", "CUST_CODE= '"+custCode+"'", conn);
valueXmlStr.append( "<cust_name><![CDATA[" ).append(custName).append( "]]></cust_name>\r\n" );
currDomStr = currDomStr.replace("</Detail1>", valueXmlStr.toString() + "</Detail1>");
valueXmlString.append(currDomStr);
}
}
else if("sale_quotdet".equalsIgnoreCase(formName))
{
int domID = 1;
if(currentColumn.trim().equalsIgnoreCase("itm_default"))
{
//DOM1 Data of 1st form DOM
custCode = genericUtility.getColumnValue("cust_code", dom1);
fromDateStr = genericUtility.getColumnValue("from_date", dom1);
toDateStr = genericUtility.getColumnValue("to_date", dom1);
currentCustCode = custCode;//
currentFromDate = fromDateStr;//
currentToDate = toDateStr;//
boolean preDomExist = preDomExists(dom2, objContext);
System.out.println("#### Does preDomExist : "+preDomExist );
System.out.println("#### currentCustCode "+currentCustCode );
System.out.println("#### preViousCustCode "+preViousCustCode );
System.out.println("#### currentFromDate "+currentFromDate );
System.out.println("#### preViousFromDate "+preViousFromDate );
System.out.println("#### currentToDate "+currentToDate );
System.out.println("#### preViousToDate "+preViousToDate );
if(preDomExist && currentCustCode.equals(preViousCustCode) && currentFromDate.equals(preViousFromDate) && currentToDate.equals(preViousToDate))
{
System.out.println("<<<<<<<<<<< Re Draw Existing Data >>>>>>>>>");
//selectedItem = getPrevFormValues( dom2, formNo, new ArrayList<String>(Arrays.asList(temp)), "strg_code" ) ;
}
else
{
System.out.println(" !!!!!!!!!!! New Data !!!!!!!!!!!!");
List<String> invoiceIdArr = new ArrayList<String>();
currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate).toString();
custCode = checkNull(genericUtility.getColumnValue("cust_code",dom1));
fromDateStr = checkNull(genericUtility.getColumnValue("from_date", dom1));
toDateStr = checkNull(genericUtility.getColumnValue("to_date", dom1));
discountType = checkNull(genericUtility.getColumnValue("discount_type", dom1));
preViousCustCode = custCode;
preViousFromDate = fromDateStr;
preViousToDate = toDateStr;
System.out.println("#### preViousCustCode "+preViousCustCode );
toDate = Timestamp.valueOf(genericUtility.getValidDateString(toDateStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
fromDate = Timestamp.valueOf(genericUtility.getValidDateString(fromDateStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
invoiceIdArr = getInvoiceDetail(conn, custCode, fromDate, toDate, valueXmlString,siteCode,discountType);
}
}
}
else if("sale_quotitems".equals(formName) || "3".equalsIgnoreCase(objContext))
{
if(currentColumn.trim().equalsIgnoreCase("itm_default"))
{
try
{
parentNodeList = dom2.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
int childNodeListLength = childNodeList.getLength();
int parentNodeListLen = parentNodeList.getLength();
String childNodeName = null;
String xmlString = "";
int ctr=0;
Element parentElem = null;
int check = 0;
for ( int rowCnt=0; rowCnt < parentNodeListLen; rowCnt++ )
{
parentNode = parentNodeList.item(rowCnt);
parentElem = (Element)parentNode;
if(parentElem.getElementsByTagName("selectbox").item(0) != null)
{
if((parentElem.getElementsByTagName("selectbox").item(0).getFirstChild().getNodeValue()).equals("true"))
{
ctr++;
globalNo++;
System.out.println("#### ITM_DEFAULT_GLOBAL_NO "+globalNo);
xmlString = serializeDom(parentNode);
String str11 = xmlString.substring(xmlString.indexOf("/>")+2);
StringBuffer buffer = new StringBuffer(str11.substring(0, str11.indexOf("</Detail2>")));
buffer.append( "<line_no protect='1'><![CDATA[" ).append(ctr).append( "]]></line_no>\r\n" );
buffer.append("<sr_no><![CDATA[" ).append(ctr).append( "]]></sr_no>\r\n</Detail3>" );
str11 = buffer.toString();
valueXmlString.append("<Detail3 domID=\""+ctr+"\" selected=\"Y\" > \r\n");
valueXmlString.append("<attribute selected=\"Y\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
//Added by AMOL TO Resovle issues occured in SalesQuotProp.jsp [To Remove OLD DATA] START
valueXmlString.append("<Record>"+globalNo+"</Record>");
//Added by AMOL TO Resovle issues occured in SalesQuotProp.jsp [To Remove OLD DATA] END
valueXmlString.append(str11);
}
}
}
} catch (Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> itm_default :"+e);
}
}
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));
//Changed on 21-08-18
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(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("<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" );
valueXmlStr.append("<perc_profit><![CDATA[" ).append(String.format ("%.2f", percProfit)).append( "]]></perc_profit>\r\n" );
valueXmlStr.append("</Detail3>");
currDomStr = currDomStr.replace("</Detail3>", valueXmlStr.toString());
//valueXmlStr.append("</Root>");
//currDomStr = currDomStr.replace("</Detail3>", valueXmlStr.toString() + "</Detail3>");
valueXmlString.append(currDomStr);
}
catch (Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> discount :"+e);
}
}
else if(currentColumn.trim().equalsIgnoreCase("qty_per_month"))
{
String currDomStr = genericUtility.serializeDom(dom);
StringBuffer valueXmlStr = new StringBuffer();
try
{
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));
newCostRate = (getDoubleValue(checkNull(genericUtility.getColumnValue("rate__new",dom))));
profit = (getDoubleValue(checkNull(genericUtility.getColumnValue("profit",dom))));
newGrossRate = (getDoubleValue(grossRate));
String profitParse = String.format("%.2f", profit);
profitOnGoods = (getDoubleValue(profitParse) * getDoubleValue(qtyMonth));
finalPrice = (newCostRate * 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("<qty_per_month><![CDATA[" ).append(qtyMonth).append( "]]></qty_per_month>\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" );
valueXmlStr.append("<perc_profit><![CDATA[" ).append(String.format ("%.2f", percProfit)).append( "]]></perc_profit>\r\n" );
valueXmlStr.append("</Detail3>");
currDomStr = currDomStr.replace("</Detail3>", valueXmlStr.toString());
//valueXmlStr.append("</Root>");
//currDomStr = currDomStr.replace("</Detail3>", valueXmlStr.toString() + "</Detail3>");
valueXmlString.append(currDomStr);
}
catch (Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> qty_per_month :"+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(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("<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" );
valueXmlStr.append("<perc_profit><![CDATA[" ).append(String.format ("%.2f", percProfit)).append( "]]></perc_profit>\r\n" );
valueXmlStr.append("</Detail3>");
currDomStr = currDomStr.replace("</Detail3>", valueXmlStr.toString());
//valueXmlStr.append("</Root>");
//currDomStr = currDomStr.replace("</Detail3>", valueXmlStr.toString() + "</Detail3>");
valueXmlString.append(currDomStr);
}
catch (Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> comm_perc :"+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(String.format ("%.2f", newCostRate)).append( "]]></basic_dist_price>\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" );
valueXmlStr.append("<perc_profit><![CDATA[" ).append(String.format ("%.2f", percProfit)).append( "]]></perc_profit>\r\n" );
valueXmlStr.append("</Detail3>");
currDomStr = currDomStr.replace("</Detail3>", valueXmlStr.toString());
//valueXmlStr.append("</Root>");
//currDomStr = currDomStr.replace("</Detail3>", valueXmlStr.toString() + "</Detail3>");
valueXmlString.append(currDomStr);
}
catch(Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> New Rate :"+e);
}
}
//Added by AMOL START
else if(currentColumn.trim().equalsIgnoreCase("itm_default_add"))
{
try
{
globalNo = globalNo +1;
String newSrNo = getSrNo(dom2);
System.out.println("#### New SrNo "+newSrNo);
valueXmlString.append("<Detail3 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(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" );
valueXmlString.append("<qty_per_month><![CDATA[" ).append("").append( "]]></qty_per_month>\r\n" );
valueXmlString.append("<rate><![CDATA[" ).append("").append( "]]></rate>\r\n" );
valueXmlString.append("<discount><![CDATA[" ).append("").append( "]]></discount>\r\n" );
valueXmlString.append("<gross_rate><![CDATA[" ).append("").append( "]]></gross_rate>\r\n" );
valueXmlString.append("<comm_perc><![CDATA[" ).append("").append( "]]></comm_perc>\r\n" );
valueXmlString.append("<comm_per_unit><![CDATA[" ).append("").append( "]]></comm_per_unit>\r\n" );
valueXmlString.append("<rate__new><![CDATA[" ).append("").append( "]]></rate__new>\r\n" );
valueXmlString.append("<basic_dist_price><![CDATA[" ).append("").append( "]]></basic_dist_price>\r\n" );
valueXmlString.append("<cost_rate><![CDATA[" ).append("").append( "]]></cost_rate>\r\n" );
valueXmlString.append("<profit><![CDATA[" ).append("").append( "]]></profit>\r\n" );
valueXmlString.append("<profit_on_goods><![CDATA[" ).append("").append( "]]></profit_on_goods>\r\n" );
valueXmlString.append("<final_price><![CDATA[" ).append("").append( "]]></final_price >\r\n" );
valueXmlString.append("<perc_profit><![CDATA[" ).append("").append( "]]></perc_profit>\r\n" );
valueXmlString.append("<available_stock><![CDATA[" ).append("").append( "]]></available_stock>\r\n" );
valueXmlString.append("</Detail3>");
}
catch (Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> itm_default_add : "+e);
}
}
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));
itemDetailMap = getItemData(itemCode, conn);
double actualCost = getCostRate(conn, itemCode);
double availblStock = getStockDetails(conn,itemCode);
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(String.format ("%.2f", actualCost)).append( "]]></cost_rate>\r\n" );
valXmlStr.append("<available_stock><![CDATA[" ).append(String.format ("%.2f", 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);
}
catch(Exception e)
{
System.out.println("@@@@ Exception ON ITEMCHANGE ==> ITEM_CODE : "+e);
}
}
}
valueXmlString.append("</Root>");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if(conn!=null)
{
if(rs != null)rs.close();
rs = null;
if(pstmt != null)pstmt.close();
pstmt = null;
conn.close();
}
conn = null;
}catch(Exception d)
{
d.printStackTrace();
throw new ITMException( d );
}
}
System.out.println("#### FINAL RETURN :: valueXmlString : "+valueXmlString.toString());
return ( valueXmlString == null || valueXmlString.toString().trim().length() == 0 ? "" : valueXmlString.toString() );
}
//Added by AMOL SANT on 03-09-18 START
private String getSrNo(Document docu)
{
//String srNo = "";
NodeList parentNList = docu.getElementsByTagName("Detail3");
int nListLen = parentNList.getLength();
System.out.println("Detail3 Lenght "+nListLen);
/*Node node = null;
Element element = null;
for( int i = 0; i < nListLen; i++)
{
node = parentNList.item(i);
}*/
return String.valueOf(nListLen);
}
//Added by AMOL SANT on 03-09-18 END
private String checkNull(String input)
{
if (input == null)
{
input="";
}
return input;
}
private String errorType( Connection conn , String errorCode )
{
String msgType = "";
PreparedStatement pstmt = null ;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement( sql );
pstmt.setString(1, checkNull(errorCode));
rs = pstmt.executeQuery();
while( rs.next() )
{
msgType = rs.getString("MSG_TYPE");
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
if ( rs != null )
{
rs.close();
rs = null;
}
if ( pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch ( Exception e )
{
e.printStackTrace();
}
}
return msgType;
}
//Not Using ....
public boolean preDomExists(Document dom, String currentFormNo) throws ITMException
{
NodeList parentList = null;
NodeList childList = null;
Node childNode = null;
boolean selected = false;
try
{
parentList = dom.getElementsByTagName("Detail" + currentFormNo);
if ( parentList.item(0) != null )
{
childList = parentList.item(0).getChildNodes();
for (int ctr = 0; ctr < childList.getLength(); ctr++)
{
childNode = childList.item(ctr);
if((childNode.getFirstChild() != null && childNode.getFirstChild().getNodeValue() != null))
{
System.out.println("Column found!!!" + childNode.getNodeName());
// Added by AMOL Due to discount_type has initial value so condition matches
// making selection true to other column value.
if(childNode.getNodeName().equalsIgnoreCase("discount_type"))
{
}else
{
selected = true;
}
break;
}
}
}
}
catch ( Exception e )
{
System.out.println("Exception InvoiceAckwIC.preDomExists() : "+e);
throw new ITMException(e);
}
System.out.println("preDomExists =["+selected+"] and currentFormNo =["+currentFormNo+"]");
return selected;
}
//Not Using....
public String getPrevFormValues( Document dom, String currentFormNo, ArrayList<String> temp, String colName) throws ITMException
{
int domID = 1;
E12GenericUtility genericUtility = new ibase.utility.E12GenericUtility();
NodeList parentList = null;
NodeList childList = null;
Node parentNode = null;
Node childNode = null;
Element elementAttr = null;
String childNodeName = "";
String columnValue = "";
String returnPrevStr = "";
Document chgPreDom = null;
try
{
chgPreDom = genericUtility.parseString("<Root/>");
System.out.println("currentFormNo ["+currentFormNo+"]");
parentList = dom.getElementsByTagName("Detail" + currentFormNo);
int parentNodeListLength = parentList.getLength();
for (int prntCtr = 0; prntCtr < parentNodeListLength; prntCtr++ )
{
parentNode = parentList.item(prntCtr);
childList = parentNode.getChildNodes();
for (int ctr = 0; ctr < childList.getLength(); ctr++)
{
childNode = childList.item(ctr);
if((childNode.getFirstChild() != null && childNode.getFirstChild().getNodeValue() != null))
{
columnValue = childNode.getFirstChild().getNodeValue().trim();
System.out.println("columnValue :::: P "+columnValue);
System.out.println("Child Nodename :::: P "+(childNode.getNodeName()));
System.out.println("Child colName :::: P "+(colName));
System.out.println("Child contains :::: P "+(temp.contains(columnValue)));
System.out.println("temp :::: P "+(temp));
if ( childNode.getNodeName().equalsIgnoreCase(colName) && temp.contains(columnValue))
{
elementAttr = (Element)parentNode;
if ( parentNode.getAttributes().getNamedItem( "domID" ) != null )
{
System.out.println("Inside Attribute : "+elementAttr);
Node node = elementAttr.getElementsByTagName("attribute").item(0);
String str = node.getAttributes().getNamedItem("updateFlag").getTextContent();
System.out.println("str :: "+str);
if(str.equals("D"))
elementAttr.setAttribute( "selected" , "N" );
else
elementAttr.setAttribute( "selected" , "Y" );
domID++;
}
Node importedNode = chgPreDom.importNode( parentNode, true );
chgPreDom.getDocumentElement().appendChild( importedNode );
break;
}
}
}
}
if(currentFormNo.equals("1"))
{
domID = 1;
}
System.out.println(">>>>>>>>> chgPreDom "+chgPreDom);
System.out.println(">>>>>>>>> returnPrevStr "+returnPrevStr);
returnPrevStr = genericUtility.serializeDom(chgPreDom);
System.out.println(">>>>>>>>> After returnPrevStr "+returnPrevStr);
System.out.println(">>>>>>>>> After returnPrevStr "+(returnPrevStr.indexOf("Detail"+currentFormNo)));
if(returnPrevStr.indexOf("Detail"+currentFormNo) != -1)
{
returnPrevStr = returnPrevStr.substring(returnPrevStr.indexOf(">") + 1, returnPrevStr.lastIndexOf("</"));
}
returnPrevStr = returnPrevStr.indexOf("Detail"+currentFormNo) != -1 ? returnPrevStr : "";
System.out.println(">>>>>>>>> After returnPrevStr>>>> "+returnPrevStr);
}
catch ( Exception e )
{
System.out.println("SalesQuotProposal.getPrevFormValues() : "+e);
throw new ITMException(e);
}
return returnPrevStr;
}
//Not using.........
private String getInvoiceData(Connection conn, StringBuffer valueXmlString, String custCode,String selectedCust, int domID, String loginSiteCode, String tranId) throws ITMException, Exception
{
String invoiceAmt="", invoiceId = "", discrpFalg = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
PreparedStatement pstmt1 = null;
ResultSet rs1 = null;
String formatedCustId = getFormattedCustId(E12GenericUtility.checkNull( selectedCust ));
String custmerBill = "";
String updatedInvoiceId = "";
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String eventDateStr = "";
Calendar calObj1 = Calendar.getInstance();
calObj1.setTime(new java.util.Date());
calObj1.add(Calendar.MONTH, -3);
calObj1.add(Calendar.YEAR, -2);
java.util.Date dateFrom = calObj1.getTime();
Timestamp timestamp = new Timestamp(calObj1.getTimeInMillis());
eventDateStr = sdf.format(dateFrom);
String sDteFro = genericUtility.getValidDateString(eventDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat());
Timestamp dateFro1 = java.sql.Timestamp.valueOf(sDteFro + " 00:00:00");
System.out.println("dateFro1 Now :: "+dateFro1);
ResultSet resultSet = null;
PreparedStatement pstmt2 = null;
try
{
System.out.println("str1 : "+tranId);
if(selectedCust != null && selectedCust.trim().length() > 0)
{
custmerBill = "SELECT * FROM INVOICE WHERE CUST_CODE = ? AND SITE_CODE = ? AND TRAN_DATE > ? AND INVOICE_ID NOT IN ("+ formatedCustId +") AND (DLV_STAT <> 1 OR DLV_STAT IS NULL)";
}
else if(tranId != null && tranId.trim().length() > 0)
{
//custmerBill = "SELECT * FROM INVOICE WHERE CUST_CODE = ? AND SITE_CODE = ? AND TRAN_DATE > ? AND (DLV_STAT <> 1 OR DLV_STAT IS NULL)";
custmerBill = "SELECT * FROM INVOICE WHERE CUST_CODE = ? AND SITE_CODE = ? AND TRAN_DATE > ? AND INVOICE.SALE_ORDER= (SELECT SORDER.SALE_ORDER FROM SORDER WHERE SORDER.UDF__STR1 = ? ) AND (DLV_STAT <> 1 OR DLV_STAT IS NULL)";
}
else
{
custmerBill = "SELECT * FROM INVOICE WHERE CUST_CODE = ? AND SITE_CODE = ? AND TRAN_DATE > ? AND (DLV_STAT <> 1 OR DLV_STAT IS NULL)";
}
pstmt = conn.prepareStatement(custmerBill);
if((selectedCust != null && selectedCust.trim().length() > 0) || (tranId == null || tranId.trim().length() <= 0))
{
pstmt.setString(1, custCode);
pstmt.setString(2, loginSiteCode);
pstmt.setTimestamp(3, dateFro1);
}
else
{
pstmt.setString(1, custCode);
pstmt.setString(2, loginSiteCode);
pstmt.setTimestamp(3, dateFro1);
pstmt.setString(4, tranId);
}
rs = pstmt.executeQuery();
int i = 0;
while(rs.next())
{
invoiceAmt = rs.getString("inv_amt");
invoiceId = rs.getString("invoice_id");
System.out.println("invoiceAmt :: "+invoiceAmt);
System.out.println("invoiceId :: "+invoiceId);
int totalQuantity = getQuantity(conn, invoiceId);
domID++;
if(tranId != null && tranId.trim().length() > 0)
{
updatedInvoiceId = invoiceId;
valueXmlString.append("<Detail2 domID=\""+domID+"\" selected=\"Y\" > \r\n");
valueXmlString.append("<attribute selected=\"Y\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valueXmlString.append("<tran_id/>");
valueXmlString.append( "<line_no protect='1'><![CDATA[" ).append(domID).append( "]]></line_no>\r\n" );
valueXmlString.append("<invoice_id><![CDATA[" ).append(invoiceId).append( "]]></invoice_id>\r\n" );
valueXmlString.append("<invoice_amt><![CDATA[" ).append(invoiceAmt).append( "]]></invoice_amt>\r\n" );
valueXmlString.append("<discr_flag><![CDATA[" ).append(discrpFalg).append( "]]></discr_flag>\r\n" );
valueXmlString.append("<quantity><![CDATA[" ).append(totalQuantity).append( "]]></quantity>\r\n" );
String custNameSql = "select sale_order from invoice where invoice_id = ?";
pstmt2 = conn.prepareStatement(custNameSql);
pstmt2.setString(1, invoiceId);
resultSet= pstmt2.executeQuery();
if(resultSet.next())
{
valueXmlString.append("<sale_order><![CDATA[" ).append(resultSet.getString("sale_order")).append( "]]></sale_order>\r\n" );
}
valueXmlString.append("</Detail2>");
if(resultSet != null)
{
resultSet.close(); resultSet = null;
}
if(pstmt2 != null)
{
pstmt2.close(); pstmt2 = null;
}
}
else
{
valueXmlString.append("<Detail2 domID=\""+domID+"\" selected=\"N\" > \r\n");
valueXmlString.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valueXmlString.append("<tran_id/>");
valueXmlString.append( "<line_no protect='1'><![CDATA[" ).append(domID).append( "]]></line_no>\r\n" );
valueXmlString.append("<invoice_id><![CDATA[" ).append(invoiceId).append( "]]></invoice_id>\r\n" );
valueXmlString.append("<invoice_amt><![CDATA[" ).append(invoiceAmt).append( "]]></invoice_amt>\r\n" );
valueXmlString.append("<discr_flag><![CDATA[" ).append(discrpFalg).append( "]]></discr_flag>\r\n" );
valueXmlString.append("<quantity><![CDATA[" ).append(totalQuantity).append( "]]></quantity>\r\n" );
String custNameSql = "select sale_order from invoice where invoice_id = ?";
pstmt2 = conn.prepareStatement(custNameSql);
pstmt2.setString(1, invoiceId);
resultSet= pstmt2.executeQuery();
if(resultSet.next())
{
valueXmlString.append("<sale_order><![CDATA[" ).append(resultSet.getString("sale_order")).append( "]]></sale_order>\r\n" );
}
valueXmlString.append("</Detail2>");
if(resultSet != null)
{
resultSet.close(); resultSet = null;
}
if(pstmt2 != null)
{
pstmt2.close(); pstmt2 = null;
}
}
}
if(tranId != null && tranId.trim().length() > 0)
{
System.out.println("updatedInvoiceId :: "+updatedInvoiceId);
updatedInvoiceId = getFormattedCustId(E12GenericUtility.checkNull( updatedInvoiceId ));
String unselectInvoice = "SELECT * FROM INVOICE WHERE CUST_CODE = ? AND SITE_CODE = ? AND TRAN_DATE > ? AND INVOICE_ID NOT IN ("+ updatedInvoiceId +") AND (DLV_STAT <> 1 OR DLV_STAT IS NULL)";
pstmt1 = conn.prepareStatement(unselectInvoice);
pstmt1.setString(1, custCode);
pstmt1.setString(2, loginSiteCode);
pstmt1.setTimestamp(3, dateFro1);
rs1 = pstmt1.executeQuery();
while(rs1.next())
{
invoiceAmt = rs1.getString("inv_amt");
invoiceId = rs1.getString("invoice_id");
int totalQuantity = getQuantity(conn, invoiceId);
domID++;
valueXmlString.append("<Detail2 domID=\""+domID+"\" selected=\"N\" > \r\n");
valueXmlString.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valueXmlString.append("<tran_id/>");
valueXmlString.append( "<line_no protect='1'><![CDATA[" ).append(domID).append( "]]></line_no>\r\n" );
valueXmlString.append("<invoice_id><![CDATA[" ).append(invoiceId).append( "]]></invoice_id>\r\n" );
valueXmlString.append("<invoice_amt><![CDATA[" ).append(invoiceAmt).append( "]]></invoice_amt>\r\n" );
valueXmlString.append("<discr_flag><![CDATA[" ).append(discrpFalg).append( "]]></discr_flag>\r\n" );
valueXmlString.append("<quantity><![CDATA[" ).append(totalQuantity).append( "]]></quantity>\r\n" );
String custNameSql = "select sale_order from invoice where invoice_id = ?";
pstmt2 = conn.prepareStatement(custNameSql);
pstmt2.setString(1, invoiceId);
resultSet= pstmt2.executeQuery();
if(resultSet.next())
{
valueXmlString.append("<sale_order><![CDATA[" ).append(resultSet.getString("sale_order")).append( "]]></sale_order>\r\n" );
}
valueXmlString.append("</Detail2>");
if(resultSet != null)
{
resultSet.close(); resultSet = null;
}
if(pstmt2 != null)
{
pstmt2.close(); pstmt2 = null;
}
}
if(rs1 != null)
{
rs1.close(); rs1 = null;
}
if(pstmt1 != null)
{
pstmt1.close(); pstmt1 = null;
}
}
if(rs != null)
{
rs.close(); rs = null;
}
if(pstmt != null)
{
pstmt.close(); pstmt = null;
}
}
catch (SQLException e)
{
e.printStackTrace();
System.out.println("InvoiceAckwIC.getInvoiceData() : "+e);
try {
custmerBill = "SELECT * FROM INVOICE WHERE CUST_CODE = ? AND SITE_CODE = ? AND TRAN_DATE > ? AND (DLV_STAT <> 1 OR DLV_STAT IS NULL)";
pstmt = conn.prepareStatement(custmerBill);
pstmt.setString(1, custCode);
pstmt.setString(2, loginSiteCode);
pstmt.setTimestamp(3, dateFro1);
rs = pstmt.executeQuery();
int i = 0;
while(rs.next())
{
invoiceAmt = rs.getString("inv_amt");
invoiceId = rs.getString("invoice_id");
System.out.println("invoiceAmt :: "+invoiceAmt);
System.out.println("invoiceId :: "+invoiceId);
int totalQuantity = getQuantity(conn, invoiceId);
domID++;
valueXmlString.append("<Detail2 domID=\""+domID+"\" selected=\"N\" > \r\n");
valueXmlString.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valueXmlString.append("<tran_id/>");
valueXmlString.append( "<line_no protect='1'><![CDATA[" ).append(domID).append( "]]></line_no>\r\n" );
valueXmlString.append("<invoice_id><![CDATA[" ).append(invoiceId).append( "]]></invoice_id>\r\n" );
valueXmlString.append("<invoice_amt><![CDATA[" ).append(invoiceAmt).append( "]]></invoice_amt>\r\n" );
valueXmlString.append("<discr_flag><![CDATA[" ).append(discrpFalg).append( "]]></discr_flag>\r\n" );
valueXmlString.append("<quantity><![CDATA[" ).append(totalQuantity).append( "]]></quantity>\r\n" );
valueXmlString.append("</Detail2>");
}
} catch (SQLException e1) {
e1.printStackTrace();
throw new ITMException(e);
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("InvoiceAckwIC.getInvoiceData() : "+e);
throw new ITMException(e);
}
System.out.println("InvoiceAckwIC.getInvoiceData() : "+valueXmlString.toString());
return valueXmlString.toString();
}
//This method return all details against invoice id.
public List<String> getInvoiceDetail(Connection conn, String custCode, Timestamp fromDate,
Timestamp toDate, StringBuffer valueXmlString, String siteCode,String discountType) throws Exception
{
System.out.println("#### getInvoiceDetail ....");
PreparedStatement pstmt = null;
PreparedStatement pstmt1 = null;
ResultSet rs = null;
ResultSet rs1 = null;
String custmerBill = "";
ArrayList<String> invoiceArr = new ArrayList<String>();
Map<String, Double> map = new HashMap<String, Double>();
String disPriceList = E12GenericUtility.checkNull(getDBColumnValue("CUSTOMER", "PRICE_LIST__DISC", "CUST_CODE = '"+custCode+"'", conn));
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);
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String eventDateStr = "";
//String discountType = "";
Calendar calObj1 = Calendar.getInstance();
calObj1.setTime(new java.util.Date());
java.util.Date dateFrom = calObj1.getTime();
eventDateStr = sdf.format(dateFrom);
String currDateStr = genericUtility.getValidDateString(eventDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat());
String qq = genericUtility.getValidDateTimeString(eventDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat());
Timestamp currDate = java.sql.Timestamp.valueOf(currDateStr + " 00:00:00");
custmerBill = "SELECT * FROM INVOICE WHERE CUST_CODE = ? AND TRAN_DATE >= ? AND TRAN_DATE <= ? AND INV_TYPE NOT IN ('DF','EF')";
try
{
pstmt = conn.prepareStatement(custmerBill);
pstmt.setString(1, custCode);
pstmt.setTimestamp(2, fromDate);
pstmt.setTimestamp(3, toDate);
rs = pstmt.executeQuery();
while(rs.next())
{
String invoiceId = checkNull(rs.getString("invoice_id")).trim();
//System.out.println("#### INVOICE ID :: "+invoiceId);
String invocieData = "SELECT * FROM INVOICE_TRACE WHERE INVOICE_ID = ? ";
try {
pstmt1 = conn.prepareStatement(invocieData);
pstmt1.setString(1, invoiceId);
rs1 = pstmt1.executeQuery();
while(rs1.next())
{
if(map.containsKey(rs1.getString("item_code")))
{
double i = map.put(rs1.getString("item_code"), Double.parseDouble(rs1.getString("quantity")));
System.out.println(i);
map.put(rs1.getString("item_code"), i + Double.parseDouble(rs1.getString("quantity")) );
}
else
{
map.put(rs1.getString("item_code"), Double.parseDouble(rs1.getString("quantity")));
}
}
if(rs1 != null)
{
rs1.close(); rs1 = null;
}
if(pstmt1 != null)
{
pstmt1.close(); pstmt1 = null;
}
} catch (Exception e)
{
System.out.println("@@@@@ Exception in SalesQuotProposal :: getInvoiceId() : "+e);
}
invoiceArr.add(invoiceId);
}
if(rs != null)
{
rs.close(); rs = null;
}
if(pstmt != null)
{
pstmt.close(); pstmt = null;
}
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("SalesQuotProposal.getInvoiceId() "+e);
throw new ITMException(e);
}
String domID = "1";
Iterator<Map.Entry<String, Double>> itr = map.entrySet().iterator();
DistCommon distCommon = new DistCommon();
int srNo = 0;
Map<String, String> itemDetailMap = new HashMap<String, String>();
while(itr.hasNext())
{
srNo++;
Map.Entry<String, Double> entry = itr.next();
String itemCode = entry.getKey();
itemCodeArr.add(itemCode);
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 grossRate = ((rate - ((rate * discount) / 100)));
if(grossRate.isNaN() || grossRate.isInfinite())
{
grossRate = 0.0;
}
double comm = 0;
try
{
comm = getCommision(commTable,currDate,conn,itemCode);
}
catch(Exception e)
{
comm = 0;
}
double commPerUnit = (((grossRate * comm) / 100));
double newCostRate = ((grossRate - commPerUnit));
double costRate = getCostRate(conn, itemCode);
double availblStock = getStockDetails(conn,itemCode);
double profit = (newCostRate - costRate);
String profitParse = String.format("%.2f", profit);
double profitOnGoods = (Double.parseDouble(profitParse) * maxValue);
double finalPrice = (grossRate * maxValue);
Double percProfit = ((profitOnGoods / finalPrice) * 100);
if(percProfit.isNaN() || percProfit.isInfinite())
{
percProfit = 0.0;
}
System.out.println("#### Item Code :: "+itemCode);
System.out.println("#### OLD Rate :: "+rate);
System.out.println("#### Discount :: "+discount);
System.out.println("#### comm :: "+comm);
System.out.println("#### commPerUnit :: "+commPerUnit);
System.out.println("#### basic_dist_price : "+newCostRate);
System.out.println("#### Final cost Rate : "+costRate);
System.out.println("#### availblStock : "+availblStock);
System.out.println("#### Formated Profit "+profitParse);
System.out.println("#### qtyMonth : "+maxValue);
System.out.println("#### finalPrice : "+finalPrice);
System.out.println("#### percProfit : "+percProfit);
valueXmlString.append("<Detail2 domID=\""+srNo+"\" 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(srNo).append( "]]></line_no>\r\n" );
valueXmlString.append("<sr_no><![CDATA[" ).append(srNo).append( "]]></sr_no>\r\n" );
valueXmlString.append("<item_code protect='1'><![CDATA[" ).append(itemCode).append( "]]></item_code>\r\n" );
valueXmlString.append("<item_descr><![CDATA[" ).append(itemDetailMap.get("descr")).append( "]]></item_descr>\r\n" );
valueXmlString.append("<unit><![CDATA[" ).append(itemDetailMap.get("unit")).append( "]]></unit>\r\n" );
valueXmlString.append("<qty_per_month><![CDATA[" ).append(maxValue).append( "]]></qty_per_month>\r\n" );
valueXmlString.append("<rate><![CDATA[" ).append(String.format ("%.2f", rate)).append( "]]></rate>\r\n" );
valueXmlString.append("<discount><![CDATA[" ).append(String.format ("%.2f", discount)).append( "]]></discount>\r\n" );
valueXmlString.append("<gross_rate><![CDATA[" ).append(String.format ("%.2f", grossRate)).append( "]]></gross_rate>\r\n" );
valueXmlString.append("<comm_perc><![CDATA[" ).append(String.format ("%.2f", comm)).append( "]]></comm_perc>\r\n" );
valueXmlString.append("<comm_per_unit><![CDATA[" ).append(String.format ("%.2f", commPerUnit)).append( "]]></comm_per_unit>\r\n" );
valueXmlString.append("<rate__new><![CDATA[" ).append(Math.round(rate)).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("<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" );
valueXmlString.append("<perc_profit><![CDATA[" ).append(String.format ("%.2f", percProfit)).append( "]]></perc_profit>\r\n" );
valueXmlString.append("<available_stock><![CDATA[" ).append(String.format ("%.2f", availblStock)).append( "]]></available_stock>\r\n" );
valueXmlString.append("<discount_type><![CDATA[" ).append(discountType).append( "]]></discount_type>\r\n" );
valueXmlString.append("</Detail2>");
}
return invoiceArr;
}
private double getCommision(String commTable, Timestamp currDate, Connection conn, String itemCode)
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
double commision = 0;
if(commTable != null)
{
try {
sql= "SELECT COMM_PERC FROM COMM_DET WHERE COMM_TABLE = ? AND VALID_UPTO >= ? AND ITEM_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,commTable);
pstmt.setTimestamp(2,currDate);
pstmt.setString(3,itemCode);
rs = pstmt.executeQuery();
while(rs.next())
{
commision = rs.getDouble("COMM_PERC");
}
pstmt.close();
rs = null;
pstmt = null;
} catch (SQLException e)
{
System.out.println("#### Exception in SalesQuotProposal :: getCommision :"+e);
e.printStackTrace();
}
}
return commision;
}
public String getFormattedCustId(String custId)
{
StringBuffer custIdStrBuff = new StringBuffer();
if( !"".equalsIgnoreCase( custId ) )
{
String[] custIdArr = custId.split(",");
int len = custIdArr.length;
for(int counter = 0; counter < len; counter++)
{
custIdStrBuff.append("'").append( E12GenericUtility.checkNull( custIdArr[counter] ) ).append("'");
if( counter < len - 1 )
{
custIdStrBuff.append(",");
}
}
}
if( "".equalsIgnoreCase( custIdStrBuff.toString() ) )
{
custIdStrBuff.append("");
}
return custIdStrBuff.toString();
}
private int getQuantity(Connection connection, String invoiceId)
{
PreparedStatement pStmt = null;
ResultSet resultSet = null;
int totalQuantity = 0;
String sql = "select quantity from invoice_trace where invoice_id = ? ";
try {
pStmt = connection.prepareStatement(sql);
pStmt.setString(1, invoiceId);
resultSet = pStmt.executeQuery();
while(resultSet.next())
{
int quantity = resultSet.getInt("quantity");
totalQuantity += quantity;
}
resultSet.close();
pStmt.close();
} catch (SQLException e)
{
System.out.println("@@@@@ Exception in getQuantity from invoice_trace : "+e);
}
return totalQuantity;
}
public String getDBColumnValue(String tableName, String columnName, String condition,Connection mConnection)
{
String columnValue = "";
Statement mStmt = null;
ResultSet rs = null;
String selectColumns="";
try
{
String columnNameAs = "";
selectColumns=columnName;
if( columnName.indexOf("~AS~") != -1 )
{
String[] columnNameArr = columnName.split("~AS~");
if( columnNameArr.length > 1 )
{
columnName = columnNameArr[0];
columnNameAs = columnNameArr[1];
selectColumns=columnName+" AS "+columnNameAs;
}
}
String mQuery = " SELECT " + selectColumns + " FROM " + tableName + " WHERE " + condition ;
System.out.println("#### mQuery ["+mQuery+"]");
mStmt = mConnection.createStatement();
rs = mStmt.executeQuery(mQuery);
if( columnNameAs.length() > 0 )
{
columnName = columnNameAs;
}
if (rs.next())
{
columnValue = checkNull( rs.getString( columnName.trim() ) );
}
}
catch (Exception e)
{
columnValue = "";
System.out.println("@@@@ Exception in SalesQuotProposal.getDBColumnValue()");
}
finally
{
try
{
//To close ResultSet, Statement and Connection in Finally
if(rs != null)
{
rs.close();
rs = null;
}
if(mStmt != null)
{
mStmt.close();
mStmt = null;
}
}
catch(Exception e)
{
System.out.println("@@@@ SalesQuotProposal.getDBColumnValue() : "+e);
}
}
return columnValue.trim();
}
private String serializeDom(Node dom)throws ITMException
{
String retString = null;
try
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Transformer serializer = TransformerFactory.newInstance().newTransformer();
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
serializer.transform(new DOMSource(dom), new javax.xml.transform.stream.StreamResult(out));
retString = out.toString();
out.flush();
out.close();
out = null;
}
catch (Exception e)
{
System.out.println("@@@@ Exception : MasterStatefulEJB : serializeDom :"+e);
throw new ITMException(e);
}
return retString;
}
private Map<String, String> getItemData(String itemCode, Connection conn)
{
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
Map<String, String> itemDetailMap = new HashMap<String, String>();
try
{
String sql = "SELECT SITE_CODE, DESCR, UNIT, LOC_CODE FROM ITEM WHERE ITEM_CODE = ?";
preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, itemCode);
resultSet = preparedStatement.executeQuery();
if(resultSet.next())
{
itemDetailMap.put("site_code", resultSet.getString("SITE_CODE"));
itemDetailMap.put("descr", resultSet.getString("DESCR"));
itemDetailMap.put("unit", resultSet.getString("UNIT"));
itemDetailMap.put("loc_code", resultSet.getString("LOC_CODE"));
}
if(resultSet != null)
{
resultSet.close();
resultSet = null;
}
if(preparedStatement != null)
{
preparedStatement.close();
preparedStatement = null;
}
}
catch(SQLException ex)
{
System.out.println("@@@@@ SQLException SalesQuotProposal.getItemData() : "+ex);
}
catch(Exception e)
{
System.out.println("@@@@@ Exception SalesQuotProposal.getItemData() : "+e);
}
return itemDetailMap;
}
private double getCostRate(Connection conn, String itemCode)
{
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String rateStr= "", quantityStr = "";
Double costRate = 0.0,additionalCost = 0.0;
double rate = 0, totalValue = 0,quantity = 0, totalQuantity = 0 ;
int count = 0 ;
double overHeadValue = 0.0, overHeadVal = 0.0;
try
{
String sql = "SELECT QUANTITY, RATE FROM STOCK WHERE ITEM_CODE = ? AND LOC_CODE IN ('FGM','QUAR')";
preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, itemCode);
resultSet = preparedStatement.executeQuery();
while(resultSet.next())
{
try
{
rateStr = E12GenericUtility.checkNull(resultSet.getString("RATE"));
rate = getDoubleValue(rateStr);
} catch (Exception e)
{
System.out.println("@@@@ Excedption in rate ["+e);
}
try
{
quantityStr = E12GenericUtility.checkNull(resultSet.getString("QUANTITY"));
quantity = getDoubleValue(quantityStr);
}
catch (Exception e)
{
System.out.println("@@@@ Exception in Quantity "+e);
}
totalQuantity = totalQuantity + quantity;
totalValue = totalValue +(rate * quantity);
count++;
}
if(resultSet != null)
{
resultSet.close();
resultSet = null;
}
if(preparedStatement != null)
{
preparedStatement.close();
preparedStatement = null;
}
if(count > 0)
{
costRate = (totalValue/totalQuantity);
if(costRate.isNaN() || costRate.isInfinite())
{
costRate = 0.0;
}
System.out.println("#### cost rate By totalValue/totalQuantity "+costRate);
additionalCost =((getDoubleValue(getAdditionalCost(conn))/costRate) * 100 );
if(additionalCost.isNaN() || additionalCost.isInfinite())
{
additionalCost = 0.0;
}
costRate = (costRate + additionalCost);
System.out.println("#### cost rate with AdditionalFees "+costRate);
}
System.out.println("#### Actual cost "+costRate);
String processOverhead = "SELECT OHD_TABLE__POST FROM ITEM WHERE ITEM_CODE = ? ";
preparedStatement = conn.prepareStatement(processOverhead);
preparedStatement.setString(1, itemCode);
resultSet = preparedStatement.executeQuery();
String ohdTablePost = "";
while(resultSet.next())
{
ohdTablePost = E12GenericUtility.checkNull(resultSet.getString("OHD_TABLE__POST"));
}
preparedStatement.close();
resultSet.close();
try
{
if( ohdTablePost.trim().length() > 0)
{
String sqlOverHead = "SELECT OVERHEAD_AMT FROM PROCESS_OVERHEAD_DET WHERE TABLE_NO = ?";
preparedStatement = conn.prepareStatement(sqlOverHead);
preparedStatement.setString(1, ohdTablePost);
resultSet = preparedStatement.executeQuery();
String overHeadDetails = "";
while( resultSet.next())
{
overHeadDetails = E12GenericUtility.checkNull(resultSet.getString("OVERHEAD_AMT"));
overHeadVal = Double.parseDouble(overHeadDetails);
overHeadValue = overHeadValue + overHeadVal;
}
System.out.println("#### overHeadValue " +overHeadValue);
preparedStatement.close();
resultSet.close();
}
} catch (Exception e)
{
System.out.println("@@@@ Exception in overHeadValue "+e);
}
costRate = (costRate + overHeadValue);
if(costRate.isNaN() || costRate.isInfinite())
{
costRate = 0.0;
}
System.out.println("#### costRate with overHeadValue "+costRate);
}
catch(SQLException ex)
{
System.out.println("@@@@ SQLException SalesQuotProposal :: getCostRate() : "+ex);
}
catch(Exception e)
{
System.out.println("@@@@ Exception SalesQuotProposal :: getCostRate() : "+e);
}
return costRate;
}
private double getStockDetails(Connection conn, String itemCode)
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
Double availblStock = 0.0;
try
{
sql = "SELECT SUM(QUANTITY) AS QUANTITY FROM STOCK WHERE QUANTITY <> 0 AND ITEM_CODE = ? AND LOC_CODE IN ('FGM','QUAR')";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, itemCode);
rs = pstmt.executeQuery();
while(rs.next())
{
availblStock = rs.getDouble("QUANTITY");
}
}
catch(Exception e)
{
System.out.println("@@@@ Exception in SalesQuotProposal :: getStockDetails :"+e);
}
if(availblStock.isNaN() || availblStock.isInfinite())
{
availblStock = 0.0;
}
return availblStock;
}
//Not Using
@Override
public String approvePriceRate(String quotNo, String userInfo, String xmlData)
{
Document dom = null;
try
{
dom = parseString(xmlData);
}
catch(Exception e)
{
e.printStackTrace();
}
ConnDriver connDriver = new ConnDriver();
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
String itemCode = "", proposedRate = "", custCode = "", priceList = "", validUpto = "", unit = "", revisedRate = "";
String termID = "",chgUser = "", chgTerm = "";;
NodeList parentNodeList = null;NodeList childNodeList = null;
Node parentNode = null;Node childNode = null;
String childNodeName = null;
int cnt = 0, currentFormNo=0,childNodeListLength ,ctr=0;
try
{
UserInfoBean userInfoBean = new UserInfoBean(userInfo);
String transDB = userInfoBean.getTransDB();
connection = connDriver.getConnectDB(transDB);
connection.setAutoCommit(false);
chgTerm = checkNull(genericUtility.getColumnValue("chg_term", dom, "1")).trim();
chgUser = checkNull(genericUtility.getColumnValue("chg_user", dom, "1")).trim();
custCode = checkNull(genericUtility.getColumnValue("cust_code", dom, "1")).trim();
custCode = checkNull(genericUtility.getColumnValue("cust_code", dom, "1")).trim();
priceList = getDBColumnValue("CUSTOMER", "PRICE_LIST", "CUST_CODE = '"+custCode+"'", connection);
parentNodeList = dom.getElementsByTagName("Detail3");
int parentNodeListLen = parentNodeList.getLength();
for ( int rowCnt=0; rowCnt < parentNodeListLen; rowCnt++ )
{
parentNode = parentNodeList.item(rowCnt);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equalsIgnoreCase("item_code"))
{
itemCode = childNode.getFirstChild().getNodeValue();
//unit = getDBColumnValue("ITEM", "UNIT", "ITEM_CODE= '"+itemCode+"'", connection);
//updatePriceList(priceList, itemCode, unit, chgTerm, chgUser, connection);
//validUpto = getDBColumnValue("PRICELIST", "VALID_UPTO", "PRICE_LIST = '"+priceList+"' and ITEM_CODE = '"+itemCode+"'", connection);
}
else if (childNodeName.equalsIgnoreCase("rate__new"))
{
revisedRate = childNode.getFirstChild().getNodeValue();
}
else if (childNodeName.equalsIgnoreCase("unit"))
{
unit = childNode.getFirstChild().getNodeValue();
System.out.println(":unit : in uniit "+unit);
}
}
updatePriceList(priceList, itemCode, unit, revisedRate, chgTerm, chgUser, connection);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if(connection != null)
{
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return "1";
}
//This method called through workflow
private void updatePriceList(String priceList, String itemCode, String unit, String revisedRate, String chgTerm, String chgUser, Connection connection)
{
System.out.println("#### updatePriceList .....");
PreparedStatement pStmt = null;
ResultSet resultSet = null;
PreparedStatement sPstmt = null;
ResultSet sRst = null;
int slabNo = 0;
String listType = "", effFrom = "", validUpto = "", lotNoFrom = "", lotNoTo = "", rateType ="", priceListParent = "", calcBasis = "";
String refNo = "", refOldNo = "", orderType = "", chgRefNo = "";
String minQty = "", maxQty = "", rate = "", maxRate = "", minRate ="";
Timestamp validDate = null;
String priceSql = "SELECT MAX(SLAB_NO) as SLAB_NO FROM PRICELIST WHERE PRICE_LIST = ? AND ITEM_CODE = ? AND UNIT = ?";
try
{
pStmt = connection.prepareStatement(priceSql);
pStmt.setString(1, priceList);
pStmt.setString(2, itemCode);
pStmt.setString(3, unit);
resultSet = pStmt.executeQuery();
if(resultSet.next())
{
slabNo = resultSet.getInt("SLAB_NO");
}
close(resultSet);
close(pStmt);
String validUptoSql = "SELECT * FROM PRICELIST WHERE PRICE_LIST = ? AND ITEM_CODE = ? AND UNIT = ? and slab_no = ?";
sPstmt = connection.prepareStatement(validUptoSql);
sPstmt.setString(1, priceList);
sPstmt.setString(2, itemCode);
sPstmt.setString(3, unit);
sPstmt.setInt(4, slabNo);
sRst = sPstmt.executeQuery();
if(sRst.next())
{
validDate = sRst.getTimestamp("VALID_UPTO");
listType = sRst.getString("LIST_TYPE");
lotNoFrom = sRst.getString("LOT_NO__FROM");
lotNoTo = sRst.getString("LOT_NO__TO");
minQty = sRst.getString("MIN_QTY");
maxQty = sRst.getString("MAX_QTY");
rate = sRst.getString("RATE");
minRate = sRst.getString("MIN_RATE");
maxRate = sRst.getString("MAX_RATE");
rateType = sRst.getString("RATE_TYPE");
orderType = sRst.getString("ORDER_TYPE");
priceListParent = sRst.getString("PRICE_LIST__PARENT");
calcBasis = sRst.getString("CALC_BASIS");
refNo = sRst.getString("REF_NO");
refOldNo = sRst.getString("REF_NO_OLD");
}
close(sRst);
close(sPstmt);
Calendar cal = Calendar.getInstance();
Calendar currDate = Calendar.getInstance();
currDate.setTimeInMillis(new Date().getTime());
currDate.set(Calendar.HOUR_OF_DAY, 0);
currDate.set(Calendar.HOUR, 0);
System.out.println("currDate : "+currDate.getTime());
cal.setTimeInMillis(validDate.getTime());
cal.add(Calendar.DAY_OF_MONTH, -1);
validDate = new Timestamp(cal.getTime().getTime());
System.out.println("validDate After: "+validDate);
String updateSql = "UPDATE PRICELIST SET VALID_UPTO = ? WHERE PRICE_LIST = ? AND ITEM_CODE = ? AND UNIT = ? and slab_no = ?";
PreparedStatement updatePreStmt = connection.prepareStatement(updateSql);
updatePreStmt.setTimestamp(1, validDate);
updatePreStmt.setString(2, priceList);
updatePreStmt.setString(3, itemCode);
updatePreStmt.setString(4, unit);
updatePreStmt.setInt(5, slabNo);
int updatedCnt = updatePreStmt.executeUpdate();
System.out.println("SalesQuotProposal.updatePriceList() updatedCnt : "+updatedCnt);
close(updatePreStmt);
String insertPriceListSql = "INSERT INTO PRICELIST(PRICE_LIST,ITEM_CODE,UNIT,LIST_TYPE,SLAB_NO,EFF_FROM,VALID_UPTO,LOT_NO__FROM,LOT_NO__TO,MIN_QTY,MAX_QTY,RATE,RATE_TYPE,MIN_RATE,CHG_DATE, CHG_USER, CHG_TERM, MAX_RATE, ORDER_TYPE,CHG_REF_NO,PRICE_LIST__PARENT,CALC_BASIS,REF_NO,REF_NO_OLD)"
+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement insertPstmt = connection.prepareStatement(insertPriceListSql);
insertPstmt.setString(1, priceList);
insertPstmt.setString(2, itemCode);
insertPstmt.setString(3, unit);
insertPstmt.setString(4, listType);
insertPstmt.setInt(5, slabNo + 1);
insertPstmt.setString(6, effFrom);
insertPstmt.setString(7, validUpto);
insertPstmt.setString(8, lotNoFrom);
insertPstmt.setString(9, lotNoTo);
insertPstmt.setString(10, minQty);
insertPstmt.setString(11, maxQty);
insertPstmt.setString(12, revisedRate);
insertPstmt.setString(13, rateType);
insertPstmt.setString(14, minRate);
insertPstmt.setString(15, validUpto);
insertPstmt.setString(16, chgTerm);
insertPstmt.setString(17, chgUser);
insertPstmt.setString(18, maxRate);
insertPstmt.setString(19, orderType);
insertPstmt.setString(20, chgRefNo);
insertPstmt.setString(21, priceListParent);
insertPstmt.setString(22, calcBasis);
insertPstmt.setString(23, refNo);
insertPstmt.setString(24, refOldNo);
int insertUpdate = insertPstmt.executeUpdate();
System.out.println("SalesQuotProposal.updatePriceList() L insertUpdate" +insertUpdate);
close(insertPstmt);
if(updatedCnt >= 0 || insertUpdate >= 0 )
{
//connection.commit();
}
} catch (SQLException e)
{
e.printStackTrace();
}
finally
{
}
}
private void close(AutoCloseable autoCloseable)
{
if(autoCloseable != null )
{
try
{
autoCloseable.close();
} catch (Exception e)
{
System.out.println("SalesQuotProposal.close() : "+e);
}
}
}
private String getCommission(String custCode, Connection connection)
{
PreparedStatement pStmt = null;
ResultSet resultSet = null;
String commTable = null;
String commSql = "SELECT COMM_TABLE__1, COMM_TABLE__3 FROM CUSTOMER WHERE CUST_CODE = ?";
try
{
pStmt = connection.prepareStatement(commSql);
pStmt.setString(1, custCode);
resultSet = pStmt.executeQuery();
if(resultSet.next())
{
commTable = resultSet.getString("COMM_TABLE__1");
if(E12GenericUtility.checkNull(commTable).length() <= 0 )
{
commTable = resultSet.getString("COMM_TABLE__3");
}
}
close(resultSet);
close(pStmt);
}
catch (SQLException e)
{
e.printStackTrace();
}
return commTable;
}
private Double getDoubleValue(String valStr)
{
double retVal = 0.0;
try
{
if(valStr.length() <= 0 )
{
retVal = 0;
}
else
{
retVal = Double.parseDouble(valStr);
}
}
catch (NumberFormatException e)
{
System.out.println("@@@@ Exception in getDoubleValue "+e);
}
return retVal;
}
private String getAdditionalCost(Connection conObj)
{
String additionalCost = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sqlStr = "SELECT VAR_VALUE FROM DISPARM WHERE VAR_NAME = ?";
try
{
pstmt = conObj.prepareStatement(sqlStr);
pstmt.setString(1, "ADDITIONAL_FEES");
rs = pstmt.executeQuery();
while(rs.next())
{
additionalCost = rs.getString("VAR_VALUE");
}
close(rs);
close(pstmt);
}
catch(Exception e)
{
System.out.println("@@@@@ Exception in getAdditionalCost : "+e);
}
return additionalCost;
}
}
\ No newline at end of file
/********************************************************
Title : PlaceOrdWizICLocal [D16BSUP001]
Date : 25/05/16
Author: Poonam Gole
********************************************************/
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
@Local // added for ejb3
public interface SalesQuotProposalLocal extends ValidatorLocal
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String approvePriceRate(String quotNo, String userInfo, String xmlData);
}
/********************************************************
Title : PlaceOrdWizICRemote [D16BSUP001]
Date : 25/05/16
Author: Poonam Gole
********************************************************/
package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote; // added for ejb3
@Remote // added for ejb3
public interface SalesQuotProposalRemote extends ValidatorRemote
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String approvePriceRate(String quotNo, String userInfo, String xmlData);
}
/********************************************************
Title : SalesQuotRevision
Date : 24/06/18
Author: AMOL SANT
********************************************************/
package ibase.webitm.ejb.dis;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.io.ByteArrayOutputStream;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class SalesQuotRevision extends ValidatorEJB implements SalesQuotRevisionLocal,SalesQuotRevisionRemote
{
E12GenericUtility genericUtility = new E12GenericUtility();
private String currentCustCode = "",currentFromDate = "",currentToDate = "";
private String preViousCustCode = "",preViousFromDate = "",preViousToDate = "";
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("#### SalesQuotRevision :: wfValData 1...");
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
System.out.println("xmlString:-" + xmlString );
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
System.out.println("errString[" + errString+"]" );
}
catch(Exception e)
{
throw new ITMException( e );
}
return (errString);
}
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException
{
System.out.println("#### SalesQuotRevision :: wfValData 2.. ");
System.out.println("#### formName : "+formName);
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
System.out.println("xmlString:-" + xmlString );
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
if (xmlString2.trim().length() > 0 )
{
dom2 = parseString("<Root>" + xmlString2+ "</Root>");
}
System.out.println("objContext["+objContext+"]\nwfValData.xmlString1["+xmlString1+"]");
System.out.println("wfValData.xmlString2["+xmlString2+"]");
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams, formName);
System.out.println("errString[" + errString+"]" );
}
catch(Exception e)
{
throw new ITMException( e );
}
return (errString);
}
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException
{
System.out.println("#### SalesQuotRevision :: wfValData 3");
Connection conn = null;
//ConnDriver connDriver = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String custCode = "", fromDateStr = "", toDateStr = "", effDateStr = "", validDateStr = "";
int currentFormNo = 0 ;
int count = 0;
String query ="";
String errorString="",errorCode ="",errorField ="",errorType;
String userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
List<String> errorCodeList = new ArrayList<String>();
List<String> errorFieldList = new ArrayList<String>();
NodeList nodeList = null;
Node node = null;
Node childNode = null;
Element element = null;
String childNodeName = "";
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
StringBuffer formatedInvIds = new StringBuffer();
/*if(objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}*/
System.out.println("#### Form No ["+currentFormNo+"]");
try
{
conn = getConnection();
errorCodeList.clear();
errorFieldList.clear();
if("price_rev".equalsIgnoreCase(formName))
{
custCode = genericUtility.getColumnValue("cust_code", dom);
fromDateStr = genericUtility.getColumnValue("from_date", dom1);
toDateStr = genericUtility.getColumnValue("to_date", dom1);
effDateStr = genericUtility.getColumnValue("eff_date", dom1);
validDateStr = genericUtility.getColumnValue("valid_upto", dom1);
query = "SELECT CUST_CODE FROM CUSTOMER WHERE CUST_CODE = ?";
pstmt = conn.prepareStatement(query);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
while(rs.next())
{
count ++;
custCode = rs.getString("CUST_CODE");
}
if(count == 0 )
{
errorCode = "VTCUSTNEX";
errorCodeList.add(errorCode);
errorFieldList.add("cust_code");
//errorMsg = getErrorType(conn,errorCode);
//errStringXml.append("<ErrorMessage><![CDATA["+errorMsg+"]]></ErrorMessage>");
}
count = 0;
try
{
String currAppdate ="";
java.sql.Timestamp currDate = null;
currDate = new java.sql.Timestamp(System.currentTimeMillis()) ;
if(currDate != null)
{
currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate).toString();
}
Timestamp currentDate = null, toDate = null, fromDate = null,effDate = null,validDate = null;
if(currAppdate != null)
{
currentDate = getDate(currAppdate);
}
if(toDateStr != null)
{
toDate = getDate(toDateStr);
}
if(fromDateStr != null)
{
fromDate = getDate(fromDateStr);
}
if(effDateStr != null)
{
effDate = getDate(effDateStr);
}
if(validDateStr != null)
{
validDate = getDate(validDateStr);
}
System.out.println("#### Current Date" +currentDate);
System.out.println("#### TO Date "+toDate);
System.out.println("#### EFF Date "+effDate);
System.out.println("#### VALID DATE Date "+validDate);
if(fromDate == null)
{
errorCode = "INVFRMDATE";
errorCodeList.add(errorCode);
errorFieldList.add("from_date");
}
else if(toDate == null)
{
errorCode = "VPSHFTCH04";
errorCodeList.add(errorCode);
errorFieldList.add("to_date");
}
else if(effDate == null)
{
errorCode = "VMEFFDATE";
errorCodeList.add(errorCode);
errorFieldList.add("eff_date");
}
else if(validDate == null)
{
errorCode = "VTDATEUPTO";
errorCodeList.add(errorCode);
errorFieldList.add("valid_upto");
}
else if(fromDate !=null && toDate != null && fromDate.after(toDate))
{
errorCode = "VTTODATE";//VMDATETO
errorCodeList.add(errorCode);
errorFieldList.add("to_date");
}
else if(currentDate != null && validDate != null && currentDate.after(validDate))
{
errorCode = "VTVLUPDATE";// BY ME...
errorCodeList.add(errorCode);
errorFieldList.add("valid_upto");
}
if(effDate != null && validDate != null && effDate.after(validDate))
{
errorCode = "VTDATE02";//VTDATE6
errorCodeList.add(errorCode);
errorFieldList.add("valid_upto");
}
//For Ffrom DATE NULL INVFRMDATE;
//For Valid null VPVDATE1 ,VTDATEUPTO
//for effDate null VTDATEFF,VMEFFDATE
} catch (Exception e1)
{
e1.printStackTrace();
}
try
{
formatedInvIds = getInvoiceIds(formatedInvIds,custCode,fromDateStr,toDateStr,conn);
System.out.println("#### Formatted IDs ["+formatedInvIds+"]");
System.out.println("#### formatedInvIds.length ["+formatedInvIds.length()+"]");
if(formatedInvIds.length() == 2 || formatedInvIds == null)
{
errorCode = "VTNORECFND";
errorCodeList.add(errorCode);
errorFieldList.add("to_date");//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
System.out.println("#### Executed ErrorCode");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
else if("price_revdet".equalsIgnoreCase(formName))
{
nodeList = dom2.getElementsByTagName("Detail2");
int nodeListLenght = nodeList.getLength();
for(int ctr = 0; ctr < nodeListLenght; ctr++ )
{
node = nodeList.item(ctr);
childNodeName = node.getNodeName();
element = (Element) node;
// <<<<<<<<<<< Need to disscussed......
/*childNode = element.getElementsByTagName("selectbox").item(0);
String selectBox = "";
if(childNode != null)
{
selectBox = childNode.getChildNodes().item(0).getNodeValue();
}*/
if(element.getElementsByTagName("selectbox").item(0) != null)
{
count++;
}
}
if(count == 0)
{
errorCode = "VTBLNKDTL";
errorCodeList.add(errorCode);
errorFieldList.add("selectbox");
}
count = 0;
}
else if("new_prc".equalsIgnoreCase(formName))
{
nodeList = dom2.getElementsByTagName("Detail3");
int nodeListLength = nodeList.getLength();
String newRate = "";
boolean numeric = true;
for(int ctr = 0; ctr < nodeListLength; ctr++)
{
node = nodeList.item(ctr);
element = (Element) node;
childNode = element.getElementsByTagName("rate__new").item(0);
if(childNode != null)
{
try
{
newRate = childNode.getChildNodes().item(0).getNodeValue();
Double rateNew = Double.parseDouble(newRate);
}
catch(NullPointerException nl)
{
numeric = false;
}
catch(NumberFormatException ne)
{
numeric = false;
}
catch(Exception e)
{
numeric = false;
}
}
}
if(!numeric)
{
System.out.println("Not a Number");
errorCode = "VTINVRATE";
errorCodeList.add(errorCode);
errorFieldList.add(childNodeName.toLowerCase());
}
}
int listSize = errorCodeList.size();
if(errorCodeList != null && listSize > 0)
{
for(int ctr = 0; ctr < listSize; ctr++)
{
errorCode = (String) errorCodeList.get(ctr);
errorField = (String) errorFieldList.get(ctr);
errorString = getErrorString(errorField, errorCode, userId);
errorType = getErrorType(conn, errorCode);
System.out.println("ERRORCODE : "+errorCode+"ERRORFIELD : "+errorField+"ERRORTYPE :"+errorType);
System.out.println("#### ERROR STRING : "+errorString);
if (errorString.length() > 0)
{
String bifurErrString = errorString.substring(errorString.indexOf("<Errors>") +
8, errorString.indexOf("<trace>"));
bifurErrString = bifurErrString +
errorString.substring(errorString.indexOf("</trace>") +
8, errorString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
errorString = "";
}
if (errorType.equalsIgnoreCase("E"))
{
break;
}
}
}
errStringXml.append("</Errors></Root> \r\n");
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
if(pstmt != null)
{
pstmt.close();
}
if(conn != null)
{
conn.close();
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return errStringXml.toString();
}
//END OF VALIDATION
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("#### SalesQuotRevision :: itemChanged 1");
Document dom = null;
Document dom1 = null;
Document dom2 =null;
String valXMLStr = "";
try
{
dom = parseString(xmlString);
dom = parseString(xmlString1);
valXMLStr = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException( e );
}
return valXMLStr;
}
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException
{
System.out.println("#### SalesQuotRevision :: itemChanged 2");
System.out.println("#### xmlString ["+xmlString+"]");
System.out.println("#### xmlString1 ["+xmlString1+"]");
System.out.println("#### xmlString2 ["+xmlString2+"]");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valXMLStr = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
if(xmlString2.trim().length() > 0)
{
dom2 = parseString(xmlString2);
}
valXMLStr = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams,formName);
}
catch(Exception e)
{
}
return valXMLStr;
}
//public String itemChanged(Document dom, Document dom1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException
{
System.out.println("#### SalesQuotRevision :: itemChanged 3");
System.out.println("#### SalesQuotRevision :: formName ["+formName+"]");
System.out.println("#### objContext ["+objContext+"]");
System.out.println("#### currentColumn ["+currentColumn+"]");
System.out.println("#### editFlag ["+editFlag+"]");
System.out.println("#### xtraParams ["+xtraParams+"]");
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String custCode = "",custName = "";
String fromDateStr= "",toDateStr = "",effDateStr = "",validUptoStr = "";;
Timestamp fromDate= null,toDate = null,effDate = null,validUpto = null;;
String sql = "";
String itemCode = "";
String priceList = "",price_list_dis = "";
String unit = "",descr = "",dis_count ="",slabNo ="";
int quantity = 0;
double rate = 0,discount = 0;
Double grossRate = 0.0;
double costRate = 0,commPerUnit = 0,commision = 0,newRate = 0;
String commTable = "",net_amt = "";
String siteCode = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
String chgUser = getValueFromXTRA_PARAMS(xtraParams, "loginCode");
String chgTerm = getValueFromXTRA_PARAMS(xtraParams, "chgTerm");
String currAppdate ="";
java.sql.Timestamp currDate = null;
currDate = new java.sql.Timestamp(System.currentTimeMillis()) ;
System.out.println("#### siteCode["+siteCode+"] chgUser ["+chgUser+"][ chgTerm "+chgTerm+"]");
StringBuffer valXMLBuff = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valXMLBuff.append(editFlag).append("</editFlag></header>");
try
{
conn = getConnection();
currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate).toString();
Timestamp currentDate = getDate(currAppdate);//
if("price_rev".equalsIgnoreCase(formName))
{
System.out.println("#### In price_rev : currentColumn :"+currentColumn);
int domID = 1;
if(currentColumn.trim().equalsIgnoreCase("itm_default"))
{
System.out.println("#### price_rev :: itm_default :");
custCode = genericUtility.getColumnValue("cust_code", dom1);
fromDateStr = genericUtility.getColumnValue("from_date", dom1);
toDateStr = genericUtility.getColumnValue("to_date", dom1);
effDateStr = genericUtility.getColumnValue("eff_date", dom1);
validUptoStr = genericUtility.getColumnValue("valid_upto", dom1);
System.out.println("#### currAppdate ["+currAppdate+"]");
System.out.println("#### fromDateStr ["+fromDateStr);
System.out.println("#### toDateStr ["+toDateStr);
System.out.println("#### effDateStr ["+effDateStr);
System.out.println("#### validUptoStr ["+validUptoStr);
valXMLBuff.append("<Detail1 domID='"+ domID +"' selected=\"Y\">\r\n");
valXMLBuff.append("<attribute selected=\"Y\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valXMLBuff.append("<quot_no/>");
valXMLBuff.append("<quot_type><![CDATA[R]]></quot_type>");
valXMLBuff.append("<cust_code><![CDATA["+custCode+"]]></cust_code>");
valXMLBuff.append("<from_date><![CDATA["+fromDateStr+"]]></from_date>");
valXMLBuff.append("<to_date><![CDATA["+toDateStr+"]]></to_date>");
valXMLBuff.append("<eff_date><![CDATA["+effDateStr+"]]></eff_date>");
valXMLBuff.append("<valid_upto><![CDATA["+validUptoStr+"]]></valid_upto>");
valXMLBuff.append("<quot_date><![CDATA[" +currAppdate+ "]]></quot_date>");
valXMLBuff.append("<chg_date><![CDATA[" +currAppdate+ "]]></chg_date>");
valXMLBuff.append("<chg_user><![CDATA[" + chgUser+ "]]></chg_user>");
valXMLBuff.append("<chg_term><![CDATA[" + chgTerm + "]]></chg_term>");
valXMLBuff.append("</Detail1>\r\n");
}
else if(currentColumn.trim().equalsIgnoreCase("cust_code"))
{
custCode = checkNull(genericUtility.getColumnValue("cust_code",dom));
System.out.println("Itemchanged in cust_code "+custCode);
String currDomStr = genericUtility.serializeDom(dom);
StringBuffer valueXmlStr = new StringBuffer();
custName = getDBColumnValue("CUSTOMER", "CUST_NAME", "CUST_CODE= '"+custCode+"'", conn);
valueXmlStr.append( "<cust_name><![CDATA[" ).append(custName).append( "]]></cust_name>\r\n" );
System.out.println("TEST currDomStr[" + valueXmlStr.toString() + "]");
currDomStr = currDomStr.replace("</Detail1>", valueXmlStr.toString() + "</Detail1>");
System.out.println("after currDomStr[" + currDomStr + "]");
valXMLBuff.append(currDomStr);
}
}
else if("price_revdet".equalsIgnoreCase(formName))
{
System.out.println("#### In price_revdet ...");
int cnt = 0;
if(currentColumn.trim().equalsIgnoreCase("itm_default"))
{
custCode = checkNull(genericUtility.getColumnValue("cust_code",dom1));
fromDateStr = checkNull(genericUtility.getColumnValue("from_date",dom1));
toDateStr = checkNull(genericUtility.getColumnValue("to_date",dom1));
currentCustCode = custCode;//
currentFromDate = fromDateStr;//
currentToDate = toDateStr;//
boolean preDomExist = preDomExists(dom2, objContext);
if(preDomExist && currentCustCode.equals(preViousCustCode) && currentFromDate.equals(preViousFromDate) && currentToDate.equals(preViousToDate))
{
System.out.println("<<<<<<<<<<< Re Draw Existing Data >>>>>>>>>");
//selectedItem = getPrevFormValues( dom2, formNo, new ArrayList<String>(Arrays.asList(temp)), "strg_code" ) ;
}
else
{
System.out.println(" !!!!!!!!!!! New Data !!!!!!!!!!!!");
preViousCustCode = custCode;
preViousFromDate = fromDateStr;
preViousToDate = toDateStr;
System.out.println("#### preViousCustCode "+preViousCustCode );
if(custCode != null && custCode.trim().length() > 0)
{
//sql = "SELECT PRICE_LIST,PRICE_LIST__DISC,COMM_TABLE FROM CUSTOMER WHERE CUST_CODE = ?";
sql = "SELECT PRICE_LIST,PRICE_LIST__DISC,COMM_TABLE__1,COMM_TABLE__3 FROM CUSTOMER WHERE CUST_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
while(rs.next())
{
priceList = rs.getString("PRICE_LIST");
price_list_dis = rs.getString("PRICE_LIST__DISC");
//commTable = rs.getString("COMM_TABLE");
commTable = rs.getString("COMM_TABLE__1");
if(E12GenericUtility.checkNull(commTable).length() <= 0 )
{
commTable = rs.getString("COMM_TABLE__3");
}
}
pstmt.close();
rs = null;
pstmt = null;
}
//03-07-18 END
StringBuffer frmtdInvId = new StringBuffer();
frmtdInvId = getInvoiceIds(frmtdInvId,custCode,fromDateStr,toDateStr,conn);
if(frmtdInvId != null && frmtdInvId.length() > 2)
{
sql ="SELECT ITEM_CODE,QUANTITY FROM INVOICE_TRACE WHERE INVOICE_ID IN"+frmtdInvId;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
Map<String,Integer> itmQntHM = new HashMap<String,Integer>();
StringBuffer frmtdItemCode = new StringBuffer();
frmtdItemCode.append("(");
while(rs.next())
{
itemCode = checkNull(rs.getString("ITEM_CODE"));
quantity = rs.getInt("QUANTITY");
if(itmQntHM.containsKey(itemCode))
{
itmQntHM.put(itemCode,itmQntHM.get(itemCode)+quantity);
}
else
{
itmQntHM.put(itemCode,quantity);
}
if(cnt > 0)
{
frmtdItemCode.append(",");
}
frmtdItemCode.append("'"+itemCode+"'");
cnt++;
}
frmtdItemCode.append(")");
cnt = 0;
rs.close();
pstmt.close();
rs = null;
pstmt = null;
int domID = 0;
System.out.println("itmQntHM ::: "+itmQntHM);
DistCommon distCommon = new DistCommon();
Map<String, String> itemDetailMap = new HashMap<String, String>();
for(String itemCodeKey : itmQntHM.keySet())
{
domID++;
if(commTable != null)
{
sql= "SELECT COMM_PERC FROM COMM_DET WHERE COMM_TABLE = ? AND VALID_UPTO >= ? AND ITEM_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,commTable);
pstmt.setTimestamp(2,currentDate);
pstmt.setString(3, itemCodeKey);
rs = pstmt.executeQuery();
while(rs.next())
{
commision = rs.getDouble("COMM_PERC");
}
pstmt.close();
rs.close();
rs = null;
pstmt = null;
}
//for unit START
sql="SELECT UNIT,DESCR FROM ITEM WHERE ITEM_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,itemCodeKey);//>>>>>>>>>>>>>> Item Code
rs = pstmt.executeQuery();
while(rs.next())
{
unit = rs.getString("UNIT");
descr = rs.getString("DESCR");
}
pstmt.close();
rs.close();
rs = null;
pstmt = null;
System.out.println("#### Unit ["+unit+"#### Description ["+descr+"]");
System.out.println("#### PriceList ["+priceList);
rate = (distCommon.pickRate(priceList, currAppdate, itemCodeKey, conn));
System.out.println("#### PriceList_Dis ["+price_list_dis);
discount = (distCommon.pickRate(price_list_dis, currAppdate, itemCodeKey, conn));
itemDetailMap = getItemData(itemCodeKey, conn);
//costRate = getCostRate(conn, itemCode, itemDetailMap);
costRate = getCostRate(conn, itemCode);
grossRate = ((rate - ((rate * discount) / 100)));
if(grossRate.isNaN() || grossRate.isInfinite())
{
grossRate = 0.0;
}
commPerUnit = (((grossRate * commision) / 100));
double rateNew = (grossRate - commPerUnit);
valXMLBuff.append("<Detail2 domID='"+ domID +"' selected=\"N\">\r\n");
valXMLBuff.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valXMLBuff.append("<quot_no/>");
valXMLBuff.append("<line_no><![CDATA[" + domID + "]]></line_no>");
valXMLBuff.append("<item_code><![CDATA["+itemCodeKey+"]]></item_code>");
valXMLBuff.append("<descr><![CDATA["+descr+"]]></descr>");
valXMLBuff.append("<unit><![CDATA["+unit+"]]></unit>");
valXMLBuff.append("<rate><![CDATA["+rate+"]]></rate>");
valXMLBuff.append("<qty_per_month><![CDATA["+itmQntHM.get(itemCodeKey)+"]]></qty_per_month>");
valXMLBuff.append("<discount><![CDATA["+discount+"]]></discount>");
//valXMLBuff.append("<gross_rate><![CDATA["+Math.round(grossRate)+"]]></gross_rate>");
valXMLBuff.append("<gross_rate><![CDATA[]]></gross_rate>");
valXMLBuff.append("<comm_perc><![CDATA["+commision+"]]></comm_perc>");
valXMLBuff.append("<comm_per_unit><![CDATA["+Math.round(commPerUnit)+"]]></comm_per_unit>");
valXMLBuff.append("<rate__new><![CDATA["+rateNew+"]]></rate__new>");
//valXMLBuff.append("<rate__new><![CDATA[]]></rate__new>");
valXMLBuff.append("<cost_rate><![CDATA["+costRate+"]]></cost_rate>");
valXMLBuff.append("</Detail2>\r\n");
}
System.out.println("domID :: "+domID);
}//
}
}
System.out.println("#### currentColumn "+currentColumn);
}
else if("new_prc".equalsIgnoreCase(formName) || "3".equalsIgnoreCase(objContext))
{
System.out.println("#### currentColumn "+currentColumn);
if(currentColumn.trim().equalsIgnoreCase("itm_default"))
{
System.out.println("<<<< INSIDE >>>>");
NodeList nodeList = null;
Node node = null;
Element elem = null;
Node childNode = null;
nodeList = dom2.getElementsByTagName("Detail2");
node = nodeList.item(0);
int nodeListLenght = nodeList.getLength();
System.out.println("<<<< Lenght ["+nodeListLenght+"]");
int ctr = 0;
String str = "";
for(int i = 0 ; i < nodeListLenght; i++)
{
node = nodeList.item(i);
elem = (Element) node;
childNode = elem.getElementsByTagName("selectbox").item(0);//<<<<<<<<<<<<<<<<<<<<<<<
System.out.println("#### childNode of selectbox "+childNode);
if( childNode != null)
{
if( childNode.getChildNodes().item(0).getNodeValue().equals("true"))
{
ctr++;
str = serializeDom(node);
System.out.println("#### SerialiseDOM ["+str+"]");
String str11 = str.substring(str.indexOf("/>")+2);
StringBuffer buffer = new StringBuffer(str11.substring(0, str11.indexOf("</Detail2>")));
buffer.append( "<line_no protect='1'><![CDATA[" ).append(ctr).append( "]]></line_no>\r\n" );
buffer.append("<sr_no><![CDATA[" ).append(ctr).append( "]]></sr_no>\r\n</Detail3>" );
str11 = buffer.toString();
System.out.println("str11 :"+str11);
valXMLBuff.append("<Detail3 domID=\""+ctr+"\" selected=\"Y\" > \r\n");
valXMLBuff.append("<attribute selected=\"Y\" updateFlag=\"A\" status=\"N\" pkNames=\"\" />\r\n");
valXMLBuff.append(str11);
}
}
}
}
else if(currentColumn.trim().equalsIgnoreCase("rate__new"))
{
System.out.println("<<<<<<<<< INSIDE NEW RATE >>>>>>>>>>");
try
{
String serl = serializeDom(dom);
System.out.println("##### Serialize DOM String["+serl);
String newRateR = genericUtility.getColumnValue("rate__new", dom);
System.out.println("@@@@@ NewRate ["+newRateR);
newRate = Double.parseDouble(newRateR);
System.out.println("#### Rate After parsing ["+newRate+"]");
String discountR = genericUtility.getColumnValue("discount", dom);
System.out.println("@@@@@ Discount ["+discountR+"]");
discount = Double.parseDouble(discountR);
System.out.println("#### Discount After parsing ["+discount+"]");
//double grossRateN = (newRate - discount);
//double grossRateN = ((newRate - ((newRate * discount) / 100)));
System.out.println("#### ITEM CHN rate__new "+newRate);
//System.out.println("#### ITEM CHN grossRate OLD"+grossRate);
//System.out.println("#### ITEM CHN grossRate New "+grossRateN);
String detailDomStr = "";
detailDomStr = serializeDom(dom);
System.out.println("#### Old detailDomStr : "+detailDomStr);
StringBuffer xmlBuff = new StringBuffer();
//xmlBuff.append("<gross_rate><![CDATA["+Math.round(grossRateN)+"]]></gross_rate>\r\n");
xmlBuff.append("<rate__new><![CDATA["+newRate+"]]></rate__new>\r\n");
detailDomStr = detailDomStr.replace("</Detail3>",xmlBuff.toString()+"</Detail3>");
valXMLBuff.append(detailDomStr);
System.out.println("#### xmlBuff ["+xmlBuff.toString()+"]");
System.out.println("#### detailDomStr "+detailDomStr);
System.out.println("#### VAL XML BUFF "+valXMLBuff.toString());
} catch (Exception e)
{
System.out.println("#### Exception in Item change New Rate "+e);
e.printStackTrace();
}
}
}
valXMLBuff.append("</Root>");
}
catch(Exception e)
{
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
if(pstmt != null)
{
pstmt.close();
}
if(conn != null)
{
conn.close();
}
}
catch(Exception ex)
{
System.out.println("Finally Exception : "+ex.getMessage());
ex.printStackTrace();
}
}
System.out.println("#### valXMlBuff "+valXMLBuff.toString());
return ( valXMLBuff == null || valXMLBuff.toString().trim().length() == 0 ? "" : valXMLBuff.toString() );
}
private String checkNull(String columnValue)
{
if(columnValue == null)
{
columnValue = "";
}
return columnValue;
}
@Override
public String priceRevision(String custCode,String xmlData,String userInfoStr) throws RemoteException,ITMException
{
System.out.println("#### Calling PriceRevionWF :: ");
System.out.println("#### custCode :: "+custCode);
System.out.println("#### xmlData :: "+xmlData);
String valPrevStr = "1";
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
PreparedStatement pstmt = null;
ResultSet rs = null;
String sqlStr = "";
String validUpto ="";
String effDate = "";
String currAppdate ="";
String priceList ="";
String listType = "", slabNo = "", lotNoFrom = "", lotNoTo = "", minQty = "", maxQty = "",
rate = "", rateType = "", minRate = "", maxRate = "", orderType = "",chgRefNo = "",
priceListParent = "", calcBasis = "", refNo = "", refNoOld = "",valDate ="";
Timestamp validDate = null;
Document dom = parseString(xmlData);
String _custCode = genericUtility.getColumnValue("cust_code", dom);
String chgTerm = checkNull(genericUtility.getColumnValue("chg_term", dom, "1")).trim();
String chgUser = checkNull(genericUtility.getColumnValue("chg_user", dom, "1")).trim();
System.out.println("#### custCode ["+_custCode);
try
{
UserInfoBean userInfo = new UserInfoBean(userInfoStr);
String transDB = userInfo.getTransDB();
// String termimnal = userInfo.getHostIP();
// String user = userInfo.getUserName();
System.out.println("#### TransDB connection in : "+transDB);
if (transDB != null && transDB.trim().length() > 0)
{
conn = connDriver.getConnectDB(transDB);
}
else
{
conn = connDriver.getConnectDB("DriverITM");
}
conn.setAutoCommit(false);
connDriver = null;
System.out.println("#### Connection establish ["+conn+"]");
/*
java.sql.Timestamp currDate = null;
currDate = new java.sql.Timestamp(System.currentTimeMillis()) ;
currAppdate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(currDate).toString();//String Format
Timestamp currentDate = getDate(currAppdate);//Timestamp format.
*/
sqlStr = "SELECT PRICE_LIST FROM CUSTOMER WHERE CUST_CODE = ?";
pstmt = conn.prepareStatement(sqlStr);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
while(rs.next())
{
priceList = rs.getString("PRICE_LIST");
//priceListG = priceList;
}
pstmt.close();
rs = null;
pstmt = null;
NodeList nList1 = dom.getElementsByTagName("Detail1");
for(int ctr = 0; ctr< nList1.getLength();ctr++)
{
Node node = nList1.item(0);
System.out.println("nList1.getLength() "+nList1.getLength());
Element elm = (Element) node;
validUpto = elm.getElementsByTagName("valid_upto").item(0).getTextContent();
effDate = elm.getElementsByTagName("eff_date").item(0).getTextContent();
System.out.println("valid_upto "+validUpto);
System.out.println("effDate "+effDate);
}
NodeList nList = dom.getElementsByTagName("Detail3");
for(int ctr= 0; ctr < nList.getLength();ctr++)
{
Node node = nList.item(ctr);
System.out.println("nList.getLength() "+nList.getLength());
Element elm = (Element) node;
String rateNew = elm.getElementsByTagName("rate__new").item(0).getTextContent();
String itemCode = elm.getElementsByTagName("item_code").item(0).getTextContent();
String unit = elm.getElementsByTagName("unit").item(0).getTextContent();
System.out.println("#### rate__new "+rateNew);
System.out.println("#### item_code "+itemCode);
System.out.println("#### unit "+unit);
System.out.println("######## itemCode "+itemCode+" priceList "+priceList+" unit "+unit);
String priceSql = "SELECT MAX(SLAB_NO) as SLAB_NO FROM PRICELIST WHERE PRICE_LIST = ? AND ITEM_CODE = ? AND UNIT = ?";
pstmt = conn.prepareStatement(priceSql);
pstmt.setString(1, priceList);
pstmt.setString(2, itemCode);
pstmt.setString(3, unit);
rs = pstmt.executeQuery();
if(rs.next())
{
slabNo = rs.getString("SLAB_NO");
}
pstmt.close();
pstmt = null;
rs = null;
sqlStr = "SELECT * FROM PRICELIST WHERE ITEM_CODE = ? AND PRICE_LIST = ? AND UNIT = ? and SLAB_NO = ?";
pstmt = conn.prepareStatement(sqlStr);
pstmt.setString(1,itemCode);
pstmt.setString(2,priceList);
pstmt.setString(3,unit);
pstmt.setString(4,slabNo);
System.out.println("Executing query "+sqlStr);
rs = pstmt.executeQuery();
while(rs.next())
{
listType = E12GenericUtility.checkNull(rs.getString("list_type"));
slabNo = E12GenericUtility.checkNull(rs.getString("slab_no"));
validDate = rs.getTimestamp("VALID_UPTO");//
lotNoFrom = E12GenericUtility.checkNull(rs.getString("lot_no__from"));
lotNoTo = E12GenericUtility.checkNull(rs.getString("lot_no__to"));
minQty = E12GenericUtility.checkNull(rs.getString("min_qty"));
maxQty = E12GenericUtility.checkNull(rs.getString("max_qty"));
rate = E12GenericUtility.checkNull(rs.getString("rate"));
rateType = E12GenericUtility.checkNull(rs.getString("rate_type"));
minRate = E12GenericUtility.checkNull(rs.getString("min_rate"));
maxRate = E12GenericUtility.checkNull(rs.getString("max_rate"));
orderType = E12GenericUtility.checkNull(rs.getString("order_type"));
chgRefNo = E12GenericUtility.checkNull(rs.getString("chg_ref_no"));
priceListParent = E12GenericUtility.checkNull(rs.getString("price_list__parent"));
calcBasis = E12GenericUtility.checkNull(rs.getString("calc_basis"));
refNo = E12GenericUtility.checkNull(rs.getString("ref_no"));
refNoOld = E12GenericUtility.checkNull(rs.getString("ref_no_old"));
}
System.out.println("#### slabNo :"+slabNo+" valDate :"+valDate);
pstmt.close();
pstmt = null;
rs = null;
/*SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
System.out.println("#### 111111111111111111");
//Date date = sdf.parse(valDate);
Date date = sdf.parse(effDate);
Calendar cal = Calendar.getInstance();
cal.add(cal.DAY_OF_YEAR,-1);
Date pdate = cal.getTime();
System.out.println("#### 22222222222222222");
String prepDate = new SimpleDateFormat(genericUtility.getApplDateFormat()).format(pdate).toString();
Timestamp previousDate = getDate(prepDate);//Timestamp.valueOf(genericUtility.getValidDateString(prepDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())+"00:00:00.0");
*/
Calendar cal = Calendar.getInstance();
Calendar currDate = Calendar.getInstance();
currDate.setTimeInMillis(new Date().getTime());
currDate.set(Calendar.HOUR_OF_DAY, 0);
currDate.set(Calendar.HOUR, 0);
System.out.println("currDate : "+currDate.getTime());
cal.setTimeInMillis(validDate.getTime());
cal.add(Calendar.DAY_OF_MONTH, -1);
validDate = new Timestamp(cal.getTime().getTime());
System.out.println("validDate After: "+validDate);
sqlStr = "UPDATE PRICELIST SET VALID_UPTO = ? WHERE ITEM_CODE = ? AND PRICE_LIST = ? AND UNIT = ? and SLAB_NO = ?";
pstmt = conn.prepareStatement(sqlStr);
pstmt.setTimestamp(1,validDate);
pstmt.setString(2,itemCode);
pstmt.setString(3,priceList);
pstmt.setString(4,unit);
pstmt.setString(5,slabNo);
System.out.println("########## Updating PriceList");
pstmt.executeUpdate();
pstmt.close();
pstmt = null;
conn.rollback();
sqlStr = "INSERT INTO PRICELIST " +
"(PRICE_LIST,ITEM_CODE,UNIT,LIST_TYPE,SLAB_NO,EFF_FROM,VALID_UPTO,LOT_NO__FROM,LOT_NO__TO,MIN_QTY,MAX_QTY,RATE,RATE_TYPE," +
"MIN_RATE,CHG_DATE,CHG_USER,CHG_TERM,MAX_RATE,ORDER_TYPE,CHG_REF_NO,PRICE_LIST__PARENT,CALC_BASIS,REF_NO,REF_NO_OLD)" +
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sqlStr);
pstmt.setString(1,priceList);
pstmt.setString(2,itemCode);
pstmt.setString(3,unit);
pstmt.setString(4,listType);
pstmt.setString(5,Integer.parseInt(slabNo)+1+"");//
pstmt.setString(6,effDate);
pstmt.setString(7,validUpto);
pstmt.setString(8,lotNoFrom);
pstmt.setString(9,lotNoTo);
pstmt.setString(10,minQty);
pstmt.setString(11,maxQty);
pstmt.setString(12,rateNew);//
pstmt.setString(13,rateType);
pstmt.setString(14,rateNew);//minRate
pstmt.setString(15,validUpto);
pstmt.setString(16,chgTerm);
pstmt.setString(17,chgUser);// Need to get from xtraParam
pstmt.setString(18,rateNew);//maxRate
pstmt.setString(19,orderType);
pstmt.setString(20,chgRefNo);
pstmt.setString(21,priceListParent);
pstmt.setString(22,calcBasis);
pstmt.setString(23,refNo);
pstmt.setString(24,refNoOld);
System.out.println("######## INsert into PriceList ..........");
pstmt.executeUpdate();
pstmt.close();
pstmt = null;
conn.rollback();
}
}
catch(Exception e)
{
System.out.println("#### Exception in priceList " +e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
if(pstmt != null)
{
pstmt.close();
}
if(conn != null)
{
conn.close();
}
}
catch(Exception ex)
{
System.out.println("Finally Exception : "+ex.getMessage());
ex.printStackTrace();
}
}
System.out.println("#### return ["+valPrevStr+"]");
return valPrevStr;
}
protected StringBuffer getInvoiceIds(StringBuffer frmtdInvId2, String custCode, String fromDateStr, String toDateStr, Connection conn2) throws Exception
{
PreparedStatement pstmt = null;
ResultSet rs = null;
Timestamp toDate = null, fromDate = null;
String sql = "";
String invoiceId = "";
int cnt = 0;
if(
(custCode !=null && custCode.trim().length() > 0) &&
(fromDateStr !=null && fromDateStr.trim().length() > 0) &&
(toDateStr != null && toDateStr.trim().length() > 0)
)
{
try
{
toDate = getDate(toDateStr);//Timestamp.valueOf(genericUtility.getValidDateString(toDateStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) 00:00:00.0");
fromDate = getDate(fromDateStr);//Timestamp.valueOf(genericUtility.getValidDateString(fromDateStr,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat()) 00:00:00.0");
sql = "SELECT INVOICE_ID FROM INVOICE WHERE CUST_CODE = ? AND TRAN_DATE BETWEEN ? AND ? AND INV_TYPE NOT IN ('DF','EF')";
pstmt = conn2.prepareStatement(sql);
pstmt.setString(1,custCode);
pstmt.setTimestamp(2,fromDate);
pstmt.setTimestamp(3,toDate);
rs = pstmt.executeQuery();
frmtdInvId2.append("(");
while(rs.next())
{
invoiceId = checkNull(rs.getString("INVOICE_ID"));
if(cnt > 0)
{
frmtdInvId2.append(",");
}
frmtdInvId2.append("'"+invoiceId+"'");
cnt++;
}
frmtdInvId2.append(")");
cnt = 0;
System.out.println("#### formatted INvoice ID ["+frmtdInvId2+"]");
rs.close();
pstmt.close();
rs = null;
pstmt = null;
System.out.println("#### Invoice ID Set ["+frmtdInvId2.toString()+"]");
} catch (Exception e)
{
System.out.println("#### Exception in SalesQuotRevision :: getInvoiceIds :"+e);
e.printStackTrace();
}
}
return frmtdInvId2;
}
private String serializeDom(Node dom)throws ITMException
{
String retString = null;
try
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
Transformer serializer = TransformerFactory.newInstance().newTransformer();
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
serializer.transform(new DOMSource(dom), new javax.xml.transform.stream.StreamResult(out));
retString = out.toString();
out.flush();
out.close();
out = null;
}
catch (Exception e)
{
System.out.println("Exception : MasterStatefulEJB : serializeDom :"+e);
throw new ITMException(e);
}
return retString;
}
private String getErrorType( Connection conn , String errorCode )
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String errorType = "";
try
{
String sql = "SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, errorCode);
rs = pstmt.executeQuery();
while(rs.next())
{
errorType = rs.getString("MSG_TYPE");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(rs != null)
{
rs.close();
}
if(pstmt != null)
{
pstmt.close();
}
if(conn != null)
{
conn.close();
}
}
catch(Exception ex)
{
System.out.println("Finally Exception : "+ex.getMessage());
ex.printStackTrace();
}
}
return errorType;
}
private Timestamp getDate(String date)
{
Timestamp timeDate = null;
try
{
timeDate = Timestamp.valueOf(genericUtility.getValidDateString(date,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())
+ " 00:00:00.0");
} catch (Exception e)
{
e.printStackTrace();
}
System.out.println("#### getDate ["+timeDate);
return timeDate;
}
public String getDBColumnValue(String tableName, String columnName, String condition,Connection mConnection)
{
System.out.println("#### getDBColumnValue ");
String columnValue = "";
Statement mStmt = null;
ResultSet rs = null;
String selectColumns="";
try
{
String columnNameAs = "";
selectColumns=columnName;
if( columnName.indexOf("~AS~") != -1 )
{
String[] columnNameArr = columnName.split("~AS~");
if( columnNameArr.length > 1 )
{
columnName = columnNameArr[0];
columnNameAs = columnNameArr[1];
selectColumns=columnName+" AS "+columnNameAs;
}
}
String mQuery = " SELECT " + selectColumns + " FROM " + tableName + " WHERE " + condition ;
System.out.println("mQuery ["+mQuery+"]");
mStmt = mConnection.createStatement();
rs = mStmt.executeQuery(mQuery);
System.out.println("columnNameAs::"+columnNameAs);
if( columnNameAs.length() > 0 )
{
columnName = columnNameAs;
}
if (rs.next())
{
columnValue = checkNull( rs.getString( columnName.trim() ) );
}
}
catch (Exception e)
{
columnValue = "";
System.out.println("Exception in SalesQuotProposal.getDBColumnValue()");
}
finally
{
try
{
//To close ResultSet, Statement and Connection in Finally
if(rs != null)
{
rs.close();
rs = null;
}
if(mStmt != null)
{
mStmt.close();
mStmt = null;
}
}
catch(Exception e)
{
System.out.println("SalesQuotProposal.getDBColumnValue() : "+e);
}
}
System.out.println(tableName +"." + columnName + " ["+columnValue+"]");
return columnValue.trim();
}
private Map<String, String> getItemData(String itemCode, Connection conn)
{
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
Map<String, String> itemDetailMap = new HashMap<String, String>();
try
{
String sql = "SELECT SITE_CODE, DESCR, UNIT, LOC_CODE FROM ITEM WHERE ITEM_CODE = ?";
preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, itemCode);
resultSet = preparedStatement.executeQuery();
if(resultSet.next())
{
itemDetailMap.put("site_code", resultSet.getString("SITE_CODE"));
itemDetailMap.put("descr", resultSet.getString("DESCR"));
itemDetailMap.put("unit", resultSet.getString("UNIT"));
itemDetailMap.put("loc_code", resultSet.getString("LOC_CODE"));
}
if(resultSet != null)
{
resultSet.close();
resultSet = null;
}
if(preparedStatement != null)
{
preparedStatement.close();
preparedStatement = null;
}
}
catch(SQLException ex)
{
System.out.println("SQLException SalesQuotProposal.getItemData() : "+ex);
}
catch(Exception e)
{
System.out.println("Exception SalesQuotProposal.getItemData() : "+e);
}
System.out.println("##### SalesQuotProposal:: getItemData() : itemDetailMap : "+itemDetailMap);
return itemDetailMap;
}
//private double getCostRate(Connection conn, String itemCode, Map<String, String> itemMap)
private double getCostRate(Connection conn, String itemCode)
{
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String rateStr= "", quantityStr = "";
Double costRate = 0.0,additionalCost = 0.0;
double rate = 0, totalValue = 0,quantity = 0, totalQuantity = 0 ;
int count = 0 ;
double overHeadValue = 0.0, overHeadVal = 0.0;
try
{
String sql = "SELECT QUANTITY, RATE FROM STOCK WHERE ITEM_CODE = ? AND LOC_CODE IN ('FGM','QUAR')";
preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, itemCode);
resultSet = preparedStatement.executeQuery();
while(resultSet.next())
{
try
{
rateStr = E12GenericUtility.checkNull(resultSet.getString("RATE"));
rate = getDoubleValue(rateStr);
} catch (Exception e)
{
System.out.println("@@@@ Excedption in rate ["+e);
}
try
{
quantityStr = E12GenericUtility.checkNull(resultSet.getString("QUANTITY"));
quantity = getDoubleValue(quantityStr);
}
catch (Exception e)
{
System.out.println("@@@@ Exception in Quantity "+e);
}
totalQuantity = totalQuantity + quantity;
totalValue = totalValue +(rate * quantity);
count++;
}
if(resultSet != null)
{
resultSet.close();
resultSet = null;
}
if(preparedStatement != null)
{
preparedStatement.close();
preparedStatement = null;
}
if(count > 0)
{
costRate = (totalValue/totalQuantity);
if(costRate.isNaN() || costRate.isInfinite())
{
costRate = 0.0;
}
System.out.println("#### cost rate By totalValue/totalQuantity "+costRate);
additionalCost =((getDoubleValue(getAdditionalCost(conn))/costRate) * 100 );
if(additionalCost.isNaN() || additionalCost.isInfinite())
{
additionalCost = 0.0;
}
costRate = (costRate + additionalCost);
System.out.println("#### cost rate with AdditionalFees "+costRate);
}
System.out.println("#### Actual cost "+costRate);
String processOverhead = "SELECT OHD_TABLE__POST FROM ITEM WHERE ITEM_CODE = ? ";
preparedStatement = conn.prepareStatement(processOverhead);
preparedStatement.setString(1, itemCode);
resultSet = preparedStatement.executeQuery();
String ohdTablePost = "";
while(resultSet.next())
{
ohdTablePost = E12GenericUtility.checkNull(resultSet.getString("OHD_TABLE__POST"));
}
preparedStatement.close();
resultSet.close();
try
{
if( ohdTablePost.trim().length() > 0)
{
String sqlOverHead = "SELECT OVERHEAD_AMT FROM PROCESS_OVERHEAD_DET WHERE TABLE_NO = ?";
preparedStatement = conn.prepareStatement(sqlOverHead);
preparedStatement.setString(1, ohdTablePost);
resultSet = preparedStatement.executeQuery();
String overHeadDetails = "";
while( resultSet.next())
{
overHeadDetails = E12GenericUtility.checkNull(resultSet.getString("OVERHEAD_AMT"));
overHeadVal = Double.parseDouble(overHeadDetails);
overHeadValue = overHeadValue + overHeadVal;
}
System.out.println("#### overHeadValue " +overHeadValue);
preparedStatement.close();
resultSet.close();
}
} catch (Exception e)
{
System.out.println("@@@@ Exception in overHeadValue "+e);
}
costRate = (costRate + overHeadValue);
if(costRate.isNaN() || costRate.isInfinite())
{
costRate = 0.0;
}
System.out.println("#### costRate with overHeadValue "+costRate);
}
catch(SQLException ex)
{
System.out.println("@@@@ SQLException SalesQuotProposal :: getCostRate() : "+ex);
}
catch(Exception e)
{
System.out.println("@@@@ Exception SalesQuotProposal :: getCostRate() : "+e);
}
return costRate;
}
private String getAdditionalCost(Connection conObj)
{
String additionalCost = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sqlStr = "SELECT VAR_VALUE FROM DISPARM WHERE VAR_NAME = ?";
try
{
pstmt = conObj.prepareStatement(sqlStr);
pstmt.setString(1, "ADDITIONAL_FEES");
rs = pstmt.executeQuery();
while(rs.next())
{
additionalCost = rs.getString("VAR_VALUE");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
System.out.println("@@@@@ Exception in getAdditionalCost : "+e);
}
return additionalCost;
}
private Double getDoubleValue(String valStr)
{
double retVal = 0.0;
try
{
if(valStr.length() <= 0 )
{
retVal = 0;
}
else
{
retVal = Double.parseDouble(valStr);
}
}
catch (NumberFormatException e)
{
System.out.println("@@@@ Exception in getDoubleValue "+e);
}
return retVal;
}
public boolean preDomExists(Document dom, String currentFormNo) throws ITMException
{
NodeList parentList = null;
NodeList childList = null;
Node childNode = null;
boolean selected = false;
try
{
parentList = dom.getElementsByTagName("Detail" + currentFormNo);
if ( parentList.item(0) != null )
{
childList = parentList.item(0).getChildNodes();
for (int ctr = 0; ctr < childList.getLength(); ctr++)
{
childNode = childList.item(ctr);
if((childNode.getFirstChild() != null && childNode.getFirstChild().getNodeValue() != null))
{
System.out.println("Column found!!!" + childNode.getNodeName());
// Added by AMOL Due to discount_type has initial value so condition matches
// making selection true to other column value.
if(childNode.getNodeName().equalsIgnoreCase("discount_type"))
{
}else
{
selected = true;
}
break;
}
}
}
}
catch ( Exception e )
{
System.out.println("Exception InvoiceAckwIC.preDomExists() : "+e);
throw new ITMException(e);
}
System.out.println("preDomExists =["+selected+"] and currentFormNo =["+currentFormNo+"]");
return selected;
}
/*private String getSalesOrderValues(HashMap sqlxmlMap1 ,String tranIdHdr , Connection conn) throws Exception
{}
public String getPriceListType(String priceList, Connection conn) throws Exception
{}
@SuppressWarnings({ "unchecked", "rawtypes" })
private HashMap getDefaultData(String option, Document dom1, Connection conn) throws ITMException
{}
private String checkNull(String input)
{}
private String getLineNewNo(String lineNo)
{}
public static boolean isNumeric(String str)
{}
{}
private String getItemSer(String itemCode,String siteCode,Timestamp tranDate,String custCode,Connection conn) throws ITMException
{}
private double getIntegralQty(Connection conn, String custCode, String itemCode, String siteCode) throws ITMException
{}
private String getSchemeDescr( Connection conn, String custCd, String itemCode, Timestamp tranDate, String siteCode) throws ITMException
{}
public boolean preDomExists(Document dom, String currentFormNo) throws ITMException
{}
public String getPrevFormValues( Document dom, String currentFormNo, ArrayList<String> temp, String colName) throws ITMException
{}
public String getBillToCustomer(Connection conn, StringBuffer valueXmlString, String custCode,String selectedCust, int domID) throws ITMException
{}
public List<String> getStockiest(Connection conn, String custCode) throws ITMException
{}
public String getFormattedCustId(String custId)
{}*/
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local
public interface SalesQuotRevisionLocal extends ValidatorLocal
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
//public String priceRevision(String custCode,String effDate,String validUpto) throws RemoteException,ITMException;
public String priceRevision(String custCode,String xmlData,String userInfoStr) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.dis;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface SalesQuotRevisionRemote extends ValidatorRemote
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams, String formName) throws RemoteException,ITMException;
//public String priceRevision(String custCode,String effDate,String validUpto) throws RemoteException,ITMException;
public String priceRevision(String custCode,String xmlData,String userInfoStr) throws RemoteException,ITMException;
}
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