Commit 965bfebb authored by caluka's avatar caluka

Ejb code updated for E-Collection schedule and field validation and itemchange


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@97432 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 26b6cbef
/********************************************************
Title : EcollectionIC[F14ISUN014]
Date : 17/02/15
Developer: Chandrashekar
********************************************************/
package ibase.webitm.ejb.fin;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import ibase.utility.E12GenericUtility;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.ejb.Stateless;
@Stateless
public class EcollectionIC extends ValidatorEJB implements EcollectionICLocal, EcollectionICRemote
{
E12GenericUtility genericUtility= new E12GenericUtility();
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String errString = "";
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
if (xmlString != null && xmlString.trim().length() > 0 )
{
dom = parseString(xmlString);
System.out.println("xmlString["+xmlString+"]");
}
if (xmlString1 != null && xmlString1.trim().length() > 0 )
{
dom1 = parseString(xmlString1);
System.out.println("xmlString1["+xmlString1+"]");
}
if (xmlString2 != null && xmlString2.trim().length() > 0 )
{
dom2 = parseString(xmlString2);
System.out.println("xmlString2["+xmlString2+"]");
}
errString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [EcollectionIC][wfValData( String, String )] :==>\n" + e.getMessage());
throw new ITMException(e);
}
return(errString);
}
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String childNodeName = null;
String errString = "";
String errCode = "";
String userId = "";
String sql = "";
String errorType = "";
String custCode="",bankCode="",lineNo="";
int cnt = 0;
int ctr=0;
int childNodeListLength;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
Connection conn = null;
PreparedStatement pstmt = null ;
ResultSet rs = null;
ConnDriver connDriver = new ConnDriver();
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
int currentFormNo =0;
String siteCode="",rcpAmtStr="",refSer="",refNo="",prdCode="";
java.util.Date tranDate = null;
double rcpAmt=0,rcpAmtNew=0;
double isInvAmt=0;
SimpleDateFormat dateFormat2 = null;
try
{ dateFormat2 = new SimpleDateFormat(genericUtility.getApplDateFormat());
System.out.println("@@@@@@@@ wfvaldata called");
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
userId = getValueFromXTRA_PARAMS(xtraParams,"loginCode");
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
switch(currentFormNo)
{
case 1 :
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equalsIgnoreCase("site_code"))
{
siteCode = this.genericUtility.getColumnValue("site_code", dom);
if(siteCode != null && siteCode.trim().length() > 0 )
{
sql = "select count(*) from site where site_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode.trim());
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt(1);
}
if (cnt == 0)
{
errCode = "VMSITE1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(genericUtility.getColumnValue("eff_date", dom) == null)
{
tranDate = null;
}
else
{
tranDate = dateFormat2.parse(genericUtility.getColumnValue("eff_date",dom));
sql = "select code from period where ? between fr_date and to_date";
pstmt = conn.prepareStatement(sql);
pstmt.setDate(1,new java.sql.Date(tranDate.getTime()));
rs = pstmt.executeQuery();
if(rs.next())
{
prdCode = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = "select count(*) from period_stat where site_code = ? and prd_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,siteCode);
pstmt.setString(2,prdCode);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(cnt == 0)
{
errCode = "VTSITEPD";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
errCode = nfCheckPeriod("FIN",tranDate,siteCode);
if(errCode != null && errCode.trim().length() > 0)
{
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}
else
{
errCode = "VMSITENUL";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if (childNodeName.equalsIgnoreCase("cust_code"))
{
custCode = this.genericUtility.getColumnValue("cust_code", dom);
if(custCode != null && custCode.trim().length() > 0 )
{
sql = "SELECT COUNT(*) AS COUNT FROM CUSTOMER WHERE CUST_CODE = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,custCode);
rs = pstmt.executeQuery();
if( rs.next())
{
cnt = rs.getInt("COUNT");
}
if( cnt == 0 )
{
errCode = "VTCUSTCD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else
{
errCode = "VMCUSTCD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if (childNodeName.equalsIgnoreCase("bank_code"))
{
bankCode = this.genericUtility.getColumnValue("bank_code", dom);
if(bankCode != null && bankCode.trim().length() > 0)
{
sql = "SELECT COUNT(*) AS COUNT FROM BANK WHERE BANK_CODE = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,bankCode);
rs = pstmt.executeQuery();
if( rs.next())
{
cnt = rs.getInt("COUNT");
}
if( cnt == 0 )
{
errCode = "VMBANKMIS1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else
{
errCode = "VMBANKCD1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}// end for
break; // case 1 end
case 2:
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
System.out.println("@@@@@@@@@@@@childNodeListLength["+childNodeListLength+"]");
for(ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if (childNodeName.equalsIgnoreCase("ref_ser"))
{
refSer = this.genericUtility.getColumnValue("ref_ser", dom);
if(refSer != null && refSer.trim().length() > 0)
{
sql = "SELECT COUNT(*) AS COUNT FROM RECEIVABLES WHERE TRAN_SER = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,refSer);
rs = pstmt.executeQuery();
if( rs.next())
{
cnt = rs.getInt("COUNT");
}
if( cnt == 0 )
{
errCode = "VTINVRESER";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
System.out.println("duplicate ref ser");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else
{
errCode = "VTNULRESER";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}else if (childNodeName.equalsIgnoreCase("ref_no"))
{
refNo = this.genericUtility.getColumnValue("ref_no", dom);
lineNo = genericUtility.getColumnValue("line_no",dom);
refSer = genericUtility.getColumnValue("ref_ser",dom);
if(refNo != null && refNo.trim().length() > 0)
{
sql = "SELECT COUNT(*) AS COUNT FROM RECEIVABLES WHERE REF_NO = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,refNo);
rs = pstmt.executeQuery();
if( rs.next())
{
cnt = rs.getInt("COUNT");
}
if( cnt == 0 )
{
errCode = "VTINVREFNO";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
if (isDulplicateFrmDom(dom2,refNo,lineNo,refSer))
{
errCode = "VTDUPREFNO";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else
{
errCode = "VTNULREFNO";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}else if (childNodeName.equalsIgnoreCase("rcp_amt"))
{
rcpAmtStr = genericUtility.getColumnValue("rcp_amt",dom);
refSer = genericUtility.getColumnValue("ref_ser",dom);
refNo = genericUtility.getColumnValue("ref_no",dom);
lineNo = genericUtility.getColumnValue("line_no",dom);
if (rcpAmtStr != null && rcpAmtStr.trim().length() > 0)
{
try
{
rcpAmtNew = Double.parseDouble(rcpAmtStr);
} catch (NumberFormatException n)
{
rcpAmtNew = 0;
}
}
System.out.println("rcpAmtNew["+rcpAmtNew+"]");
if(rcpAmtNew <= 0)
{
errCode = "VTRCPAMT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
break;
}
isInvAmt = getValidDateFromDom(dom2,refSer,refNo,lineNo, conn);
sql = "SELECT (TOT_AMT - ADJ_AMT) AS AMT FROM RECEIVABLES WHERE TRAN_SER = ? AND REF_NO = ? " ;
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,checkNull(genericUtility.getColumnValue("ref_ser",dom)));
pstmt.setString(2,checkNull(genericUtility.getColumnValue("ref_no",dom)));
rs = pstmt.executeQuery();
if( rs.next())
{
rcpAmt=rs.getDouble(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("isInvAmt>>>["+isInvAmt+"]rcpAmt["+rcpAmt+"]");
if(rcpAmt < isInvAmt)
{
errCode = "VTINVTLAMT";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
} // end for
break; // case 2 end
}
int errListSize = errList.size();
cnt = 0;
String errFldName = null;
if(errList != null && errListSize > 0)
{
for(cnt = 0; cnt < errListSize; cnt ++)
{
errCode = errList.get(cnt);
errFldName = errFields.get(cnt);
System.out.println("errCode .........." + errCode);
errString = getErrorString(errFldName, errCode, userId);
errorType = errorType(conn , errCode);
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;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors> </Root> \r\n");
}
else
{
errStringXml = new StringBuffer("");
}
}
catch(Exception e)
{
e.printStackTrace();
errString = 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);
}
}
errString = errStringXml.toString();
return errString;
}
//end of validation
// method for item change
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
System.out.println("xmlString............."+xmlString);
System.out.println("xmlString1............"+xmlString);
System.out.println("xmlString2............"+xmlString);
try
{
if(xmlString != null && xmlString.trim().length() > 0)
{
dom = parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length() > 0)
{
dom1 = parseString(xmlString1);
}
if(xmlString2 != null && xmlString2.trim().length() > 0)
{
dom2 = parseString(xmlString2);
}
valueXmlString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [EcollectionIC][itemChanged( String, String )] :==>\n" + e.getMessage());
throw new ITMException(e);
}
return valueXmlString;
}
// method for item change
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
String sql = "";
StringBuffer valueXmlString = new StringBuffer();
int ctr = 0;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null ;
E12GenericUtility genericUtility= new E12GenericUtility();
ConnDriver connDriver = new ConnDriver();
int currentFormNo =0, childNodeListLength=0;
String columnValue="";
String loginSite="",loginSiteDesc="",siteCodeDesc="";
String bankCode="",siteCode="",custCode="",bankName="",custName="",refNo="",refSer="";
double rcpAmt1=0;
try
{
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String sysDate = sdf.format(currentDate.getTime());
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver = null;
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext.trim());
}
System.out.println("Now the date is :=> " + sysDate);
valueXmlString = new StringBuffer("<?xml version = \"1.0\"?> <Root> <header> <editFlag>");
valueXmlString.append(editFlag).append("</editFlag> </header>");
System.out.println("**********ITEMCHANGE FOR CASE"+currentFormNo+"**************");
switch(currentFormNo)
{
case 1 :
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
childNodeListLength = childNodeList.getLength();
System.out.println("currentColumn[" + currentColumn + "]columnValue ==> '" + columnValue + "'");
valueXmlString.append("<Detail1>");
if ( currentColumn.trim().equalsIgnoreCase( "itm_default" ))
{
loginSite = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSite");
sql = "SELECT DESCR FROM SITE WHERE SITE_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, loginSite);
rs = pstmt.executeQuery();
if( rs.next() )
{
loginSiteDesc = rs.getString( "DESCR" );
}
valueXmlString.append( "<tran_date><![CDATA[" ).append( checkNull( sysDate ) ).append( "]]></tran_date>\r\n" );
valueXmlString.append( "<eff_date><![CDATA[" ).append( checkNull( sysDate ) ).append( "]]></eff_date>\r\n" );
valueXmlString.append("<site_code><![CDATA[" ).append( loginSite ).append( "]]></site_code>\r\n");
valueXmlString.append("<descr><![CDATA[" ).append( loginSiteDesc ).append( "]]></descr>\r\n");
valueXmlString.append("<status><![CDATA[" ).append("E").append( "]]></status>\r\n");
valueXmlString.append("<tran_type><![CDATA[" ).append("E").append( "]]></tran_type>\r\n");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
else if( currentColumn.trim().equalsIgnoreCase( "bank_code" ) )
{
bankCode = checkNull(genericUtility.getColumnValue("bank_code",dom));
sql = "SELECT BANK_NAME FROM BANK WHERE BANK_CODE =?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, bankCode);
rs = pstmt.executeQuery();
if( rs.next() )
{
bankName = checkNull(rs.getString( "BANK_NAME" ));
}
valueXmlString.append("<bank_name>").append("<![CDATA["+bankName+"]]>").append("</bank_name>\r\n");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}else if( currentColumn.trim().equalsIgnoreCase( "cust_code" ) )
{
custCode = checkNull(genericUtility.getColumnValue("cust_code",dom));
sql = "SELECT CUST_NAME FROM CUSTOMER WHERE CUST_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custCode);
rs = pstmt.executeQuery();
if( rs.next() )
{
custName = checkNull(rs.getString( "CUST_NAME" ));
}
System.out.println("custName["+custName+"]");
valueXmlString.append("<cust_name><![CDATA[").append(custName).append("]]></cust_name>\r\n");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}else if( currentColumn.trim().equalsIgnoreCase( "site_code" ) )
{
siteCode = checkNull(genericUtility.getColumnValue("site_code",dom));
sql = "SELECT DESCR FROM SITE WHERE SITE_CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
rs = pstmt.executeQuery();
if( rs.next() )
{
siteCodeDesc = checkNull(rs.getString( "DESCR" ));
}
valueXmlString.append("<descr><![CDATA[").append(siteCodeDesc).append("]]></descr>\r\n");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
valueXmlString.append("</Detail1>");
break;
case 2 :
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
ctr = 0;
valueXmlString.append("<Detail2>");
childNodeListLength = childNodeList.getLength();
System.out.println("currentColumn[" + currentColumn + "] ==> '" + columnValue + "'");
if ( currentColumn.trim().equalsIgnoreCase("itm_default") )
{
valueXmlString.append("<line_no__ref><![CDATA[" ).append("1").append( "]]></line_no__ref>\r\n");
}else if( currentColumn.trim().equalsIgnoreCase( "ref_no" ) ||currentColumn.trim().equalsIgnoreCase( "ref_ser" ) )
{
refNo = checkNull(genericUtility.getColumnValue("ref_no",dom));
refSer = checkNull(genericUtility.getColumnValue("ref_ser",dom));
sql = "SELECT (TOT_AMT - ADJ_AMT) AS AMT FROM RECEIVABLES WHERE TRAN_SER = ? AND REF_NO = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refSer);
pstmt.setString(2, refNo);
rs = pstmt.executeQuery();
if( rs.next() )
{
rcpAmt1=rs.getDouble(1);
}
valueXmlString.append("<rcp_amt><![CDATA[" ).append( rcpAmt1 ).append( "]]></rcp_amt>\r\n");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
valueXmlString.append("</Detail2>");
break;
}
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();
}
}
return valueXmlString.toString();
}
private String checkNull(String input)
{
if(input == null)
{
input = "";
}
return input;
}
public static java.util.Date relativeDate(java.util.Date date, int days)
{
java.util.Date calculatedDate = null;
if (date != null)
{
final GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.add(Calendar.DATE,days);
calculatedDate = new java.util.Date(calendar.getTime().getTime());
}
return calculatedDate;
}
private String errorType(Connection conn , String errorCode) throws ITMException
{
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,errorCode);
rs = pstmt.executeQuery();
if(rs.next())
{
msgType = rs.getString("MSG_TYPE");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(Exception ex)
{
ex.printStackTrace();
throw new ITMException(ex);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
}
return msgType;
}
private double getValidDateFromDom(Document dom,String refSer, String refNo,String lineNo, Connection conn) throws ITMException
{
System.out.println("---inside getValidDateFromDom--");
NodeList parentList = null;
NodeList childList = null;
Node parentNode = null;
Node childNode = null;
String lineNoDom = "";
String refSerDom="",refNoDom="",rcpAmtDomStr="";
double rcpAmtDom=0;
double reduceAmt=0;
try
{
parentList = dom.getElementsByTagName("Detail2");
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 != null && childNode.getNodeName().equalsIgnoreCase("attribute"))
{
String updateFlag = "";
updateFlag = childNode.getAttributes().getNamedItem("updateFlag").getNodeValue();
if (updateFlag.equalsIgnoreCase("D"))
{
System.out.println("Break from here as the record is deleted");
break;
}
}
if ( childNode != null && childNode.getFirstChild() != null && childNode.getNodeName().equalsIgnoreCase("line_no") )
{
lineNoDom = childNode.getFirstChild().getNodeValue().trim();
}
if ( childNode != null && childNode.getFirstChild() != null && childNode.getNodeName().equalsIgnoreCase("ref_no") )
{
refNoDom = childNode.getFirstChild().getNodeValue().trim();
}
if ( childNode != null && childNode.getFirstChild() != null && childNode.getNodeName().equalsIgnoreCase("ref_ser") )
{
refSerDom = childNode.getFirstChild().getNodeValue().trim();
}
if ( childNode != null && childNode.getFirstChild() != null && childNode.getNodeName().equalsIgnoreCase("rcp_amt") )
{
rcpAmtDomStr = childNode.getFirstChild().getNodeValue().trim();
if (rcpAmtDomStr != null && rcpAmtDomStr.trim().length() > 0)
{
try
{
rcpAmtDom = Double.parseDouble(rcpAmtDomStr);
} catch (NumberFormatException n)
{
rcpAmtDom = 0;
}
}
}
}
if (refSer.trim().equalsIgnoreCase(refSerDom.trim()) && refNo.trim().equalsIgnoreCase(refNoDom.trim()) )
{
reduceAmt=reduceAmt+rcpAmtDom;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
}
catch(Exception e)
{
e.printStackTrace();
}
}
System.out.println("final reduceAmt ["+reduceAmt+"]");
return reduceAmt;
}
private boolean isDulplicateFrmDom(Document dom,String refNo, String lineNo,String refSer) throws ITMException
{
NodeList parentList = null;
NodeList childList = null;
Node parentNode = null;
Node childNode = null;
String lineNoDom = "";
boolean isDulplicate = false;
String refNoDom= "",refSerDom="";
System.out.println("---inside isDulplicateFrmDom--");
try
{
parentList = dom.getElementsByTagName("Detail2");
int parentNodeListLength = parentList.getLength();
for (int prntCtr = parentNodeListLength; prntCtr > 0; prntCtr-- )
{
parentNode = parentList.item(prntCtr-1);
childList = parentNode.getChildNodes();
for (int ctr = 0; ctr < childList.getLength(); ctr++)
{
childNode = childList.item(ctr);
if(childNode != null && childNode.getNodeName().equalsIgnoreCase("attribute"))
{
String updateFlag = "";
updateFlag = childNode.getAttributes().getNamedItem("updateFlag").getNodeValue();
if (updateFlag.equalsIgnoreCase("D"))
{
System.out.println("Break from here as the record is deleted");
break;
}
}
if ( childNode != null && childNode.getFirstChild() != null &&
childNode.getNodeName().equalsIgnoreCase("line_no") )
{
lineNoDom = childNode.getFirstChild().getNodeValue().trim();
System.out.println("lineNo["+lineNo+"]lineNoDom["+lineNoDom+"]");
if (lineNo.equalsIgnoreCase(lineNoDom))
{
System.out.println("Break from here as line No match");
break;
}
}
if ( childNode != null && childNode.getFirstChild() != null &&
childNode.getNodeName().equalsIgnoreCase("REF_NO") )
{
refNoDom = childNode.getFirstChild().getNodeValue().trim();
}
if ( childNode != null && childNode.getFirstChild() != null &&
childNode.getNodeName().equalsIgnoreCase("ref_ser") )
{
refSerDom = childNode.getFirstChild().getNodeValue().trim();
}
}
if (refSer.trim().equalsIgnoreCase(refSerDom.trim()) && refNo.trim().equalsIgnoreCase(refNoDom.trim()) )
{
isDulplicate = true;
break;
}
}//for loop
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
}
catch(Exception e)
{
e.printStackTrace();
}
}
System.out.println("isDulplicate>>>>>> ["+isDulplicate+"]");
return isDulplicate;
}
}
/********************************************************
Title : EcollectionICLocal[F14ISUN014]
Date : 17/02/15
Developer: Chandrashekar
********************************************************/
package ibase.webitm.ejb.fin;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.ValidatorLocal;
import javax.ejb.Local; // added for ejb3
@Local // added for ejb3
public interface EcollectionICLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String wfValData(Document dom, Document dom1,Document dom2, String objCotext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, 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) throws RemoteException,ITMException;
}
\ No newline at end of file
/********************************************************
Title : EcollectionICRemote[F14ISUN014]
Date : 17/02/15
Developer: Chandrashekar
********************************************************/
package ibase.webitm.ejb.fin;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote; // added for ejb3
import ibase.webitm.ejb.ValidatorRemote;// added for ejb3
@Remote // added for ejb3
public interface EcollectionICRemote extends ValidatorRemote
{
public String wfValData(String xmlString, String xmlString1,String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException;
public String wfValData(Document dom, Document dom1,Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1,String xmlString2, 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) throws RemoteException,ITMException;
}
\ No newline at end of file
/********************************************************
Title : EcollectionSchedule[F14ISUN014]
Date : 17/02/15
Developer: Chandrashekar
********************************************************/
package ibase.webitm.ejb.fin;
import ibase.scheduler.utility.interfaces.Schedule;
import java.util.*;
import java.util.Date;
import java.sql.*;
import org.w3c.dom.*;
import javax.naming.InitialContext;
import ibase.webitm.utility.ITMException;
import ibase.webitm.ejb.*;
import ibase.webitm.ejb.fin.adv.ReceiptAdvConf;
import ibase.webitm.utility.GenericUtility;
import ibase.system.config.*;
import java.text.SimpleDateFormat;
import ibase.utility.E12GenericUtility;
public class EcollectionSchedule implements Schedule
{
String chgUser = null;
String chgTerm = null;
static long count_records=0;
boolean isError = false;
String loginSiteCode = "";
String retString="";
public static void main(String args[])
{
EcollectionSchedule ecs=new EcollectionSchedule();
System.out.println("Main Method Calling******************************************************88");
}
public String schedulePriority( String wrkflwPriority )throws Exception
{
return "";
}
public String schedule(HashMap map)throws Exception
{
return "";
}
public String schedule(String scheduleParamXML)throws Exception
{
String siteCode = "",actualLoginSiteCode="",errString="";
String xtraParams = "";
ibase.utility.UserInfoBean userInfo = null;
try
{
System.out.println("************ ["+scheduleParamXML+"]");
userInfo = new ibase.utility.UserInfoBean( scheduleParamXML );
siteCode = userInfo.getSiteCode();
xtraParams = "loginEmpCode="+userInfo.getEmpCode()+"~~termId="+userInfo.getRemoteHost()+"~~loginSiteCode="+loginSiteCode;
GenericUtility genericUtility=GenericUtility.getInstance();
Document dom=genericUtility.parseString(scheduleParamXML);
NodeList paramList = dom.getElementsByTagName( "SCHEDULE" );
// Node currDetail = null ;
// int noOfParam = paramList.getLength();
NodeList parentNodeList = null,childNodeList = null;
Node parentNode = null,childNode = null;
//String DisparmSites = "";
int childNodeListLength = 0;
String childNodeName = null;
parentNodeList = dom.getElementsByTagName("ACTUALPARAMETERS");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName!=null && !"#text".equalsIgnoreCase(childNodeName))
{
if(ctr==0)
{
actualLoginSiteCode=childNode.getFirstChild().getNodeValue();
}
}
}
System.out.println("ActualLoginSiteCode----["+actualLoginSiteCode+"]");
if(("null".equals(actualLoginSiteCode) || actualLoginSiteCode.trim().length() == 0 ))
{
siteCode = userInfo.getSiteCode();
System.out.println("Site code >>>>>>>>>> "+siteCode);
errString= insertReceipt(siteCode,scheduleParamXML,xtraParams);
}
else
{
String[] arrStr =actualLoginSiteCode.split(",");
int len =arrStr.length;
for(int i =0;i<len;i++)
{
loginSiteCode =arrStr[i];
System.out.println("loginSiteCode>>>>>>>>"+loginSiteCode);
errString= insertReceipt(loginSiteCode,scheduleParamXML,xtraParams);
}
}
}
catch(Exception e)
{
throw new Exception(e);
}
System.out.println("errString>>>["+errString+"]");
return errString;
}
public String insertReceipt(String siteCode , String scheduleParamXML,String xtraParams) throws Exception
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
PreparedStatement pstmt1 = null;
ResultSet rs1 = null;
String sql="";
String tranId="";
String tranDate =null;
String bankCode = "",refNo="",custCode="",tranType="",rcpMode="",finEntity="",remarks="";
String sql1="",refSer="",lineNoRef="";
String errString ="",xmlString="";
double rcpAmt=0,bankAmount=0,rcpAmtDet=0;
int cnt=0,lineNo=0;
Date refDate=null,effDate=null;
E12GenericUtility e12GenericUtility = new E12GenericUtility();
SimpleDateFormat sdf = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
ReceiptAdvConf ReceiptAdv = new ReceiptAdvConf();
try
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
conn.setAutoCommit(false);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(e12GenericUtility.getApplDateFormat());
java.util.Calendar cal = java.util.Calendar.getInstance();
tranDate = simpleDateFormat.format(cal.getTime());
sql = "select bank_code,ref_no,chq_amt,cust_code,tran_type,rcp_mode,ref_date,eff_date,remarks,tran_id from " + " receipt_form where confirmed='Y' and status='C' and site_code= ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
rs = pstmt.executeQuery();
while (rs.next())
{
bankCode = rs.getString("bank_code");
refNo = rs.getString("ref_no");
custCode = rs.getString("cust_code");
rcpAmt = rs.getDouble("chq_amt");
tranType = rs.getString("tran_type");
rcpMode = rs.getString("rcp_mode");
refDate = rs.getDate("ref_date");
effDate = rs.getDate("eff_date");
remarks = rs.getString("remarks");
tranId = rs.getString("tran_id");
System.out.println("receipt form tranId:::::::::" + tranId);
sql1 = " select fin_entity from site where site_code=? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, siteCode);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
finEntity = rs1.getString("fin_entity");
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
finEntity = finEntity == null ? "" : finEntity.trim();
sql1 = " select amount from bank_statement where site_code=? and bank_code= ? and ref_no= ?";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, siteCode);
pstmt1.setString(2, bankCode);
pstmt1.setString(3, refNo);
rs1 = pstmt1.executeQuery();
if (rs1.next())
{
bankAmount = rs1.getDouble("amount");
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
System.out.println("bankAmount>>>>>>[" + bankAmount + "]rcpAmt[" + rcpAmt + ']');
if (rcpAmt == bankAmount)
{
StringBuffer xmlBuff = new StringBuffer();
StringBuffer advBuff = new StringBuffer();
errString = "";
xmlBuff.append("<?xml version='1.0' encoding='ISO-8859-1'?>\n");
xmlBuff.append("<DocumentRoot>");
xmlBuff.append("<description>").append("Datawindow Root").append("</description>");
xmlBuff.append("<group0>");
xmlBuff.append("<description>").append("Group0 description").append("</description>");
xmlBuff.append("<Header0>");
xmlBuff.append("<objName><![CDATA[").append("receipt_adv").append("]]></objName>");
xmlBuff.append("<pageContext><![CDATA[").append("1").append("]]></pageContext>");
xmlBuff.append("<objContext><![CDATA[").append("1").append("]]></objContext>");
xmlBuff.append("<editFlag><![CDATA[").append("A").append("]]></editFlag>");
xmlBuff.append("<focusedColumn><![CDATA[").append("").append("]]></focusedColumn>");
xmlBuff.append("<action><![CDATA[").append("SAVE").append("]]></action>");
xmlBuff.append("<elementName><![CDATA[").append("").append("]]></elementName>");
xmlBuff.append("<keyValue><![CDATA[").append("1").append("]]></keyValue>");
xmlBuff.append("<taxKeyValue><![CDATA[").append(" ").append("]]></taxKeyValue>");
xmlBuff.append("<saveLevel><![CDATA[").append("1").append("]]></saveLevel>");
xmlBuff.append("<forcedSave><![CDATA[").append(true).append("]]></forcedSave>");
xmlBuff.append("<taxInFocus><![CDATA[").append(false).append("]]></taxInFocus>");
xmlBuff.append("<description>").append("Header0 members").append("</description>");
xmlBuff.append("<Detail1 objContext =\"1\"").append(" objName=\"receipt_adv\" domID=\"1\" dbID=\"\">");
xmlBuff.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\"/>");
xmlBuff.append("<tran_id/>");
xmlBuff.append("<tran_date><![CDATA[" + tranDate + "]]></tran_date>");
xmlBuff.append("<cust_code><![CDATA[" + custCode + "]]></cust_code>");
xmlBuff.append("<tran_type><![CDATA[" + tranType + "]]></tran_type>");
xmlBuff.append("<rcp_mode><![CDATA[" + rcpMode + "]]></rcp_mode>");
xmlBuff.append("<bank_code><![CDATA[" + bankCode + "]]></bank_code>");
xmlBuff.append("<ref_no><![CDATA[" + refNo + "]]></ref_no>");
if (refDate != null)
{
xmlBuff.append("<ref_date><![CDATA[" + sdf.format(refDate) + "]]></ref_date>");
} else
{
xmlBuff.append("<ref_date><![CDATA[]]></ref_date>");
}
xmlBuff.append("<site_code><![CDATA[" + siteCode + "]]></site_code>");
xmlBuff.append("<confirmed><![CDATA[]]></confirmed>");
xmlBuff.append("<auto_recd><![CDATA[]]></auto_recd>");
xmlBuff.append("<adv_amt><![CDATA[").append("0").append("]]></adv_amt>");
xmlBuff.append("<bill_amt><![CDATA[").append("0").append("]]></bill_amt>");
if (effDate != null)
{
xmlBuff.append("<eff_date><![CDATA[" + sdf.format(effDate) + "]]></eff_date>");
} else
{
xmlBuff.append("<eff_date><![CDATA[]]></eff_date>");
}
xmlBuff.append("<diff_amt__exch><![CDATA[]]></diff_amt__exch>");
xmlBuff.append("<sale_order><![CDATA[]]></sale_order>");
xmlBuff.append("<cust_bank_ref><![CDATA[]]></cust_bank_ref>");
xmlBuff.append("<entry_batch_no><![CDATA[]]></entry_batch_no>");
xmlBuff.append("<emp_code__aprv><![CDATA[]]></emp_code__aprv>");
xmlBuff.append("<chq_amt><![CDATA[" + rcpAmt + "]]></chq_amt>");
xmlBuff.append("<advadj_amt><![CDATA[").append("0").append("]]></advadj_amt>");
xmlBuff.append("<fin_scheme><![CDATA[]]></fin_scheme>");
xmlBuff.append("<item_ser><![CDATA[]]></item_ser>");
xmlBuff.append("<rcp_type><![CDATA[]]></rcp_type>");
xmlBuff.append("<remarks><![CDATA[" + remarks + "]]></remarks>");
xmlBuff.append("<fin_entity><![CDATA[" + finEntity + "]]></fin_entity>");
xmlBuff.append("</Detail1>");
sql1 = " select ref_ser,ref_no,line_no__ref,rcp_amt from rcpdet_form where tran_id=? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
rs1 = pstmt1.executeQuery();
while (rs1.next())
{
lineNo++;
System.out.println("lineNo is " + lineNo);
refSer = rs1.getString("ref_ser");
refNo = rs1.getString("ref_no");
lineNoRef = rs1.getString("line_no__ref");
rcpAmtDet = rs1.getDouble("rcp_amt");
refSer = refSer == null ? "" : refSer.trim();
refNo = refNo == null ? "" : refNo.trim();
lineNoRef = lineNoRef == null ? "" : lineNoRef.trim();
xmlBuff.append("<Detail2 objContext=\"2\" objName=\"receipt_adv\" domID=\"1\" dbID=''>");
xmlBuff.append("<attribute selected=\"N\" updateFlag=\"A\" status=\"N\" pkNames=\"\"/>");
xmlBuff.append("<tran_id/>");
xmlBuff.append("<line_no><![CDATA[" + lineNo + "]]></line_no>");
xmlBuff.append("<line_no__ref><![CDATA[" + lineNoRef + "]]></line_no__ref>");
xmlBuff.append("<ref_ser><![CDATA[" + refSer + "]]></ref_ser>");
xmlBuff.append("<ref_no><![CDATA[" + refNo + "]]></ref_no>");
xmlBuff.append("<rcp_amt><![CDATA[" + rcpAmtDet + "]]></rcp_amt>");
xmlBuff.append("</Detail2>");
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
xmlBuff.append(advBuff.toString());
xmlBuff.append("</Header0>");
xmlBuff.append("</group0>");
xmlBuff.append("</DocumentRoot>");
xmlString = xmlBuff.toString();
System.out.println("xmlString " + xmlString);
errString = saveData(siteCode, xmlString, conn);
System.out.println("Passed xml in master State full errString " + errString);
if (errString.indexOf("Success") > -1)
{
String[] arrayForTranId = errString.split("<TranID>");
int endIndex = arrayForTranId[1].indexOf("</TranID>");
System.out.println("***********going for confirmation************");
String tranIdForIssue = arrayForTranId[1].substring(0, endIndex);
System.out.println("tranIdForIssue" + tranIdForIssue);
errString = ReceiptAdv.confirm(tranIdForIssue, xtraParams, "", conn);
System.out.println("=====Its Confirmed=====");
System.out.println("retString from conf ::" + errString);
if (errString.indexOf("VTCICONF3") > -1)
{
sql1 = " update receipt_form set status= 'P' where tran_id = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
cnt = pstmt1.executeUpdate();
if (cnt > 0)
{
System.out.println("UPDATE QUERY FOR STATUS");
conn.commit();
}
pstmt1.close();
pstmt1 = null;
} else
{
System.out.println("connection roll back for confirmation");
conn.rollback();
}
} else
{
System.out.println("connection roll back for save data");
conn.rollback();
}
System.out.println("Passed xml in master State full errString " + errString);
} else
{
sql1 = " update receipt_form set remarks = 'Mismatch amount in bank statement and total receipt amount',status= 'R' where tran_id = ? ";
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, tranId);
cnt = pstmt1.executeUpdate();
if (cnt > 0)
{
conn.commit();
}
pstmt1.close();
pstmt1 = null;
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(SQLException se)
{
isError = true;
System.out.println("Exception : insReceipt : EcollectionSchedule" +se.getMessage());
try
{
conn.rollback();
}
catch(Exception se1){}
throw new ITMException(se);
}finally
{
if(conn != null)
{
if(pstmt!=null)
{
pstmt.close();
pstmt=null;
}
if(rs!=null)
{
rs.close();
rs=null;
}
conn.close();
conn= null;
}
}
System.out.println("errString........:: " + errString);
return errString;
}
private String saveData(String siteCode,String xmlString, Connection conn) throws ITMException
{
System.out.println("saving data...........");
InitialContext ctx = null;
String retString = null;
MasterStatefulLocal masterStateful = null; // for ejb3
try
{
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext(appConnect.getProperty());
masterStateful = (MasterStatefulLocal)ctx.lookup("ibase/MasterStatefulEJB/local");
System.out.println("-----------masterStateful------- " + masterStateful);
String [] authencate = new String[2];
authencate[0] = "";
authencate[1] = "";
System.out.println("xmlString to masterstateful [" + xmlString + "]");
retString = masterStateful.processRequest(authencate, siteCode, true, xmlString,true,conn);
}
catch(ITMException itme)
{
System.out.println("ITMException :CreateDistOrder :saveData :==>");
throw itme;
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception :CreateDistOrder :saveData :==>");
throw new ITMException(e);
}
return retString;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment