Commit 47dffd30 authored by prane's avatar prane

changes done for [F17LNEL001]

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@183965 ce508802-f39f-4f6c-b175-0d175dae99d5
parent dce5d6a2
package ibase.webitm.ejb.fin;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import ibase.utility.E12GenericUtility;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Session Bean implementation class RecPayXfrIC
*/
@Stateless
public class RecPayXfrIC extends ValidatorEJB implements RecPayXfrICRemote, RecPayXfrICLocal {
/**
* Default constructor.
*/
public RecPayXfrIC() {
}
E12GenericUtility genericUtility = new E12GenericUtility();
/**
* The public method is used for converting the current form data into a document(DOM)
* The dom is then given as argument to the overloaded function wfValData to perform validation
* Returns validation string if exists else returns null in XML format
* @param xmlString contains the current form data in XML format
* @param xmlString1 contains all the header information in the XML format
* @param xmlString2 contains the data of all the forms in XML format
* @param objContext represents the form number
* @param editFlag represents the mode of transaction(A-Add or E-Edit)
* @param xtraParams contains additional information such as loginEmpCode,loginCode,chgTerm etc
*/
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String retString = "";
try
{
if(xmlString != null && xmlString.trim().length() > 0)
{
dom = genericUtility.parseString(xmlString);
}
if(xmlString1 != null && xmlString1.trim().length() > 0)
{
dom1 = genericUtility.parseString(xmlString1);
}
if(xmlString2 != null && xmlString2.trim().length() > 0)
{
dom2 = genericUtility.parseString(xmlString2);
}
retString = wfValData(dom, dom1, dom2, objContext, editFlag, xtraParams);
System.out.println("retString:::"+retString);
}
catch(Exception e)
{
System.out.println("Exception in RecPayXfrIC wfValData :: " + getClass().getSimpleName() + "::"+ e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
/**
* The public overloaded method takes a document as input and is used for the validation of required fields
* Returns validation string if exist otherwise returns null in XML format
* @param currFormDataDom contains the current form data as a document object model
* @param hdrDataDom contains all the header information
* @param allFormDataDom contains the field data of all the forms
* @param objContext represents form number
* @param editFlag represents the mode of transaction(A-Add or E-Edit)
* @param xtraParams contains additional information such as loginEmpCode,loginCode,chgTerm etc
*/
public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("******************* Pavan Rane *******************");
System.out.println("******* Inside RecPayXfrIC wfValData **********");
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
Connection conn = null;
E12GenericUtility genericUtility;
String errString = "", userId = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
try
{
int currentFormNo = 0, childNodeListLength = 0, ctr = 0, cnt = 0;
String childNodeName = "", errorType = "", errCode = "";
String saleOrder="";
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
conn = getConnection();
genericUtility = new E12GenericUtility();
//SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
System.out.println("xtraParam----->>["+xtraParams+"]");
System.out.println("editFlag ------------>>["+editFlag+"]");
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("sale_order"))
{
saleOrder = checkNull(genericUtility.getColumnValue("sale_order", dom));
if ( saleOrder != null && saleOrder.trim().length() > 0)
{
sql = "select count(*) as cnt from sorder where sale_order = ? and confirmed = 'Y' ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, saleOrder);
rs = pstmt.executeQuery();
if (rs.next())
{
cnt = rs.getInt("cnt");
}
pstmt.close();
rs.close();
pstmt = null;
rs = null;
if (cnt == 0)
{
errList.add("VTSORD1");
errFields.add(childNodeName.toLowerCase());
}
}
}
else if (childNodeName.equalsIgnoreCase("descr"))
{}
}//end of for loop
break;// end of switch
}// end of switch
int errListSize = errList.size();
int count = 0;
String errFldName = null;
if (errList != null && errListSize > 0)
{
for (count = 0; count < errListSize; count++) {
errCode = errList.get(count);
errFldName = errFields.get(count);
System.out.println(" testing :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 )
{
System.out.println ( "Exception: RecPayXfrIC: wfValData( Document currFormDataDom ): " + e.getMessage() + ":" );
e.printStackTrace();
throw new ITMException(e);
}
return errStringXml.toString();
}
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 retString = "";
E12GenericUtility genericUtility = new E12GenericUtility();
System.out.println("----------------Inside RecPayXfrIC itemChanged-------------------");
try {
System.out.println("xmlString::["+xmlString+"]\nxmlString1::["+xmlString1+"]\nxmlString2::["+xmlString2+"]");
if (xmlString != null && xmlString.trim().length() > 0) {
dom = genericUtility.parseString(xmlString);
}
if (xmlString1 != null && xmlString1.trim().length() > 0) {
dom1 = genericUtility.parseString(xmlString1);
}
if (xmlString2 != null && xmlString2.trim().length() > 0) {
dom2 = genericUtility.parseString(xmlString2);
}
retString = itemChanged(dom, dom1, dom2, objContext, currentColumn, editFlag, xtraParams);
} catch (Exception e) {
System.out.println("Exception: RecPayXfrIC: itemChanged:" + this.getClass().getSimpleName() + "::" + e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return retString;
}
public String itemChanged(Document dom, Document dom1, Document dom2,String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String loginSite="";
String dateNow="";
StringBuffer valueXmlString = new StringBuffer();
int currentFormNo = 0, ctr = 0;
Timestamp currentDate= null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
try {
System.out.println("******************* Pavan Rane *******************");
System.out.println("----------------Inside itemChanged-------------------");
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
currentDate = new Timestamp(System.currentTimeMillis());
dateNow = (sdf.format(currentDate).toString()).trim();
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>");
switch (currentFormNo)
{
case 1 : parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail1>");
ctr = 0;
int childNodeListLength = childNodeList.getLength();
do
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
if(childNodeName.equals(currentColumn))
{
if(childNode.getFirstChild() != null)
{
}
}
ctr ++;
}while(ctr < childNodeListLength && ! childNodeName.equals(currentColumn));
if(currentColumn.trim().equalsIgnoreCase("itm_default"))
{
loginSite = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
System.out.println("loginSite::["+loginSite+"]");
System.out.println("----------- inside itm_default ---------------");
valueXmlString.append("<site_code>").append("<![CDATA[" + loginSite + "]]>").append("</site_code>");
valueXmlString.append("<tran_date>").append("<![CDATA[" + dateNow + "]]>").append("</tran_date>");
}
valueXmlString.append("</Detail1>");
break;
}//switch
valueXmlString.append("</Root>");
System.out.println("------ItemChanged::valueXmlString["+valueXmlString+"]");
}catch(Exception e)
{
System.out.println("Exception: RecPayXfrIC: itemChanged:" + this.getClass().getSimpleName() + "::" + e.getMessage());
e.printStackTrace();
throw new ITMException(e);
}
return valueXmlString.toString();
}
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 String checkNull(String str) {
if (str == null) {
return "";
} else {
return str;
}
}
private String checkNullAndTrim(String inputVal)
{
if ( inputVal == null )
{
inputVal = "";
}
else
{
inputVal = inputVal.trim();
}
return inputVal;
}
}
package ibase.webitm.ejb.fin;
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 RecPayXfrICLocal 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 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;
}
package ibase.webitm.ejb.fin;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote
public interface RecPayXfrICRemote 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;
}
package ibase.webitm.ejb.fin;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ProcessEJB;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.TransIDGenerator;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class RecPayXfrPrc extends ProcessEJB implements RecPayXfrPrcLocal,RecPayXfrPrcRemote
{
E12GenericUtility genericUtility = null;
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException, ITMException
{
System.out.println("******* Inside RecPayXfrPrc getData**********");
//System.out.println(".....xtraParams["+xtraParams+"]");
Document dom = null, dom1 = null;
String retString = null;
try
{
//System.out.println(">>>>>xmlString:getData"+xmlString+">>>>xmlString2:"+xmlString2);
if (xmlString != null && xmlString.trim().length() != 0)
{
genericUtility= new E12GenericUtility();
dom = genericUtility.parseString(xmlString);
}
if (xmlString2 != null && xmlString2.trim().length() != 0)
{
genericUtility= new E12GenericUtility();
dom1 = genericUtility.parseString(xmlString2);
}
retString = getData(dom, dom1, windowName, xtraParams);
} catch (Exception e)
{
System.out.println("Exception : RecPayXfrPrc : getData:" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("Returning from getDate :: " + retString);
return retString;
}
public String getData(Document dom, Document dom1, String windowName, String xtraParams) throws RemoteException, ITMException
{
System.out.println("******************* PAVAN RANE *******************");
System.out.println("----------- Inside RecPayXfrPrc getData -----------");
String siteCode = "";
String custFr = "";
String custTo = "";
String saleOrder = "";
String sDueDateFr = "";
String sDueDateTo = "";
String sql = "";
String recPayXfr = "";
String itemSer = "";
String custCode = "";
String custName = "";
String tranSer = "";
String siteCodeRcv = "";
String finEntity = "";
String bankCode = "";
String saleOrderRcv = "";
String xmlRetString = "";
String refNo = "";
String acctCode = "";
String cctrCode = "";
String tranId = "";
String currCode = "";
String crTerm = "";
String errString = "";
String refType = "";
Timestamp dueDate = null;
Timestamp dueDateFr = null;
Timestamp dueDateTo = null;
Timestamp tranDate = null;
Timestamp refDate = null;
double totAmt = 0.0d;
double adjAmt = 0.0d;
double exchRate = 0.0d;
double netAmt = 0.0d;
int rows = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
conn = getConnection() ;
StringBuffer xmlBuff = new StringBuffer("<?xml version = \"1.0\"?>");
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>");
siteCode = checkNull(genericUtility.getColumnValue("site_code", dom));
sDueDateFr = checkNull(genericUtility.getColumnValue("due_date__fr", dom));
sDueDateTo = checkNull(genericUtility.getColumnValue("due_date__to", dom));
custFr = checkNull(genericUtility.getColumnValue("cust_code__fr", dom));
custTo = checkNull(genericUtility.getColumnValue("cust_code__to", dom));
saleOrder= checkNull(genericUtility.getColumnValue("sale_order", dom));
if ( saleOrder != null && saleOrder.trim().length() > 0)
{
refType = "AV";
}else
{
saleOrder = "%";
refType = "@";
}
//to get rec_pay_xfr
recPayXfr= checkNull(genericUtility.getColumnValue("rec_pay_xfr", dom));
System.out.println("----recPayXfr["+recPayXfr+"]");
if(sDueDateFr != null) {
dueDateFr = Timestamp.valueOf(genericUtility.getValidDateString(sDueDateFr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
if(sDueDateTo != null) {
dueDateTo = Timestamp.valueOf(genericUtility.getValidDateString(sDueDateTo, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
sql = " select receivables.item_ser, receivables.cust_code, customer.cust_name, receivables.tran_ser, receivables.tran_date, receivables.ref_no, receivables.ref_date, receivables.tot_amt, receivables.adj_amt, receivables.acct_code, receivables.cctr_code, receivables.tran_id, receivables.curr_code, receivables.exch_rate, receivables.cr_term, receivables.due_date, receivables.site_code, receivables.fin_entity, receivables.bank_code, receivables.sale_order, receivables.tot_amt - receivables.adj_amt as net_amt " +
" FROM receivables, customer " +
" WHERE ( receivables.cust_code = customer.cust_code ) " ;
if (recPayXfr != null && "P".equalsIgnoreCase(recPayXfr))
{
sql = sql +" AND ( receivables.tot_amt - receivables.adj_amt > 0 ) " ;
}else if (recPayXfr != null && "N".equalsIgnoreCase(recPayXfr))
{
sql = sql +" AND ( receivables.tot_amt - receivables.adj_amt < 0 ) " ;
}else if (recPayXfr != null && "B".equalsIgnoreCase(recPayXfr))
{
sql = sql +" ";
}
sql = sql + " AND ( receivables.tot_amt - receivables.adj_amt != 0 ) " +
" AND ( receivables.cust_code between ? and ? ) " +
" AND ( receivables.site_code = ? ) " +
" AND ( receivables.due_date between ? and ? ) " +
" AND ( case when receivables.sale_order is null then ' ' else receivables.sale_order end like ? ) " +
" AND ( case when receivables.ref_type is null then ' ' else receivables.ref_type end not like ? ) ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, custFr);
pstmt.setString(2, custTo);
pstmt.setString(3, siteCode);
pstmt.setTimestamp(4, dueDateFr);
pstmt.setTimestamp(5, dueDateTo);
pstmt.setString(6, saleOrder);
pstmt.setString(7, refType);
rs = pstmt.executeQuery();
System.out.println(">>>-GetData SQL :: ["+sql+"]");
while(rs.next())
{
itemSer = checkNull(rs.getString("item_ser"));
custCode = checkNull(rs.getString("cust_code"));
custName = checkNull(rs.getString("cust_name"));
tranSer = checkNull(rs.getString("tran_ser"));
tranDate = rs.getTimestamp("tran_date");
refNo = checkNull(rs.getString("ref_no"));
refDate = rs.getTimestamp("ref_date");
totAmt = rs.getDouble("tot_amt");
adjAmt = rs.getDouble("adj_amt");
acctCode = checkNull(rs.getString("acct_code"));
cctrCode = checkNull(rs.getString("cctr_code"));
tranId = checkNull(rs.getString("tran_id"));
currCode = checkNull(rs.getString("curr_code"));
exchRate = rs.getDouble("exch_rate");
crTerm = checkNull(rs.getString("cr_term"));
dueDate = rs.getTimestamp("due_date");
siteCodeRcv = checkNull(rs.getString("site_code"));
finEntity = checkNull(rs.getString("fin_entity"));
bankCode = checkNull(rs.getString("bank_code"));
saleOrderRcv = checkNull(rs.getString("sale_order"));
netAmt = rs.getDouble("net_amt");
xmlBuff.append("<Detail2>");
xmlBuff.append("<item_ser>").append("<![CDATA[" + itemSer + "]]>").append("</item_ser>");
xmlBuff.append("<cust_code>").append("<![CDATA[" + custCode + "]]>").append("</cust_code>");
xmlBuff.append("<cust_name>").append("<![CDATA[" + custName + "]]>").append("</cust_name>");
xmlBuff.append("<tran_ser>").append("<![CDATA[" + tranSer + "]]>").append("</tran_ser>");
if(tranDate != null) {
xmlBuff.append("<tran_date>").append("<![CDATA[" + (sdf.format(tranDate)) + "]]>").append("</tran_date>"); }
xmlBuff.append("<ref_no>").append("<![CDATA[" + refNo + "]]>").append("</ref_no>");
if(refDate != null) {
xmlBuff.append("<ref_date>").append("<![CDATA[" + (sdf.format(refDate)) + "]]>").append("</ref_date>"); }
xmlBuff.append("<tot_amt>").append("<![CDATA[" + totAmt + "]]>").append("</tot_amt>");
xmlBuff.append("<adj_amt>").append("<![CDATA[" + adjAmt + "]]>").append("</adj_amt>");
xmlBuff.append("<net_amt>").append("<![CDATA[" + netAmt + "]]>").append("</net_amt>");
xmlBuff.append("<acct_code>").append("<![CDATA[" + acctCode + "]]>").append("</acct_code>");
xmlBuff.append("<cctr_code>").append("<![CDATA[" + cctrCode + "]]>").append("</cctr_code>");
xmlBuff.append("<tran_id>").append("<![CDATA[" + tranId + "]]>").append("</tran_id>");
xmlBuff.append("<curr_code>").append("<![CDATA[" + currCode + "]]>").append("</curr_code>");
xmlBuff.append("<exch_rate>").append("<![CDATA[" + exchRate + "]]>").append("</exch_rate>");
xmlBuff.append("<cr_term>").append("<![CDATA[" + crTerm + "]]>").append("</cr_term>");
if(refDate != null) {
xmlBuff.append("<due_date>").append("<![CDATA[" + (sdf.format(dueDate)) + "]]>").append("</due_date>"); }
xmlBuff.append("<site_code>").append("<![CDATA[" + siteCodeRcv + "]]>").append("</site_code>");
xmlBuff.append("<fin_entity>").append("<![CDATA[" + finEntity + "]]>").append("</fin_entity>");
xmlBuff.append("<bank_code>").append("<![CDATA[" + bankCode + "]]>").append("</bank_code>");
xmlBuff.append("<sale_order>").append("<![CDATA[" + saleOrderRcv + "]]>").append("</sale_order>");
xmlBuff.append("</Detail2>");
xmlBuff.append("\n");
rows ++;
}
pstmt.close();
rs.close();
pstmt = null;
rs = null;
xmlBuff.append("</Header0>\r\n");
xmlBuff.append("</group0>\r\n");
xmlBuff.append("</DocumentRoot>\r\n");
xmlRetString=xmlBuff.toString();
System.out.println("Pavan ----ROWS----["+rows+"]");
if(rows == 0)
{
errString = itmDBAccessEJB.getErrorString("", "VTNOREC1", "","", conn);
return errString;
}
System.out.println("xmlRetString:["+xmlRetString+"]rows["+rows+"]");
}catch (SQLException se)
{
System.out.println("SQLException :RecPayXfrPrc :getData(Document dom, Document dom2, String winName, String xtraParams):" + se.getMessage() + ":");
se.printStackTrace();
throw new ITMException(se);
} catch (Exception e)
{
System.out.println("Exception :RecPayXfrPrc :getData(Document dom, Document dom2, String winName, String xtraParams):" + e.getMessage() + ":");
e.printStackTrace();
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 e)
{
}
}
return xmlRetString;
}
/********************************************************************************************
1. Function for transferring the negative receivables to payables.
2. The receivable is adjusted and a new record is inserted in to payables.
3. Record in inserted into receivables_adj
********************************************************************************************/
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException
{
System.out.println("******* Inside RecPayXfrPrc process **********");
System.out.println(".....xtraParams["+xtraParams+"]");
Document detailDom = null;
Document headerDom = null;
String retStr = "";
try
{
if(xmlString != null && xmlString.trim().length()!=0)
{
headerDom = genericUtility.parseString(xmlString);
}
if(xmlString2 != null && xmlString2.trim().length()!=0)
{
detailDom = genericUtility.parseString(xmlString2);
}
retStr = process(headerDom, detailDom, windowName, xtraParams);
}catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception : RecPayXfrPrc: process(String xmlString, String xmlString2, String windowName, String xtraParams): "+e.getMessage());
throw new ITMException(e);
}
return retStr;
}
public String process(Document headerDom, Document detailDom, String windowName, String xtraParams) throws RemoteException,ITMException
{
System.out.println("******************* PAVAN RANE *******************");
System.out.println("----------- Inside RecPayXfrPrc getData -----------");
String errString = "";
String refSer = "";
String refNo = "";
String currCode = "";
String custCode = "";
String acctCode = "";
String cctrCode = "";
String finEnt = "";
String refSerPay = "";
String siteCode = "";
String bankCode = "";
String tranIdRec = "";
String sTranDate = "";
String sTotAmt = "";
String sAdjAmt = "";
String sRefDate = "";
String sDueDate = "";
String sExchRate = "";
String tranId = "";
String tranIdRecadj = "";
String sundryType = "";
String status = "";
String sql = "";
Timestamp refDate = null;
Timestamp dueDate = null;
Timestamp tranDate = null;
double exchRate = 0.0d;
double totAmt = 0.0d;
double adjAmt = 0.0d;
NodeList parentNodeList = null;
Node parentNode = null;
Connection conn = null;
PreparedStatement pstmt1 = null;
PreparedStatement pstmt2 = null;
PreparedStatement pstmt3 = null;
ResultSet rs = null;
try
{
conn = getConnection();
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
sTranDate = checkNull(genericUtility.getColumnValue("tran_date", headerDom));
System.out.println(">>>> TranDate:["+sTranDate+"]");
if(sTranDate != null && sTranDate.trim().length() > 0){
tranDate = Timestamp.valueOf(genericUtility.getValidDateString(sTranDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
sql = "INSERT INTO MISC_PAYABLES ( TRAN_ID, TRAN_SER, TRAN_DATE, REF_NO, REF_DATE, CURR_CODE, EXCH_RATE, SUNDRY_CODE, SUNDRY_TYPE, ACCT_CODE, CCTR_CODE, DUE_DATE, FIN_ENTITY, SITE_CODE, TOT_AMT, ADJ_AMT, STATUS, STATUS_DATE, BANK_CODE ) " +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";
pstmt2 = conn.prepareStatement(sql);
sql="INSERT INTO RECEIVABLES_ADJ ( TRAN_ID, REF_SER, REF_NO, TOT_AMT, ADJ_AMT, REF_SER_ADJ, REF_NO_ADJ, NET_AMT, TRAN_ID__RCV ) " +
" VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)";
pstmt3 = conn.prepareStatement(sql);
String browDom=genericUtility.serializeDom(detailDom);
System.out.println("Detail dom"+browDom);
parentNodeList = detailDom.getElementsByTagName("Detail2");
int parentNodeListLength = parentNodeList.getLength();
for(int ptr = 0; ptr < parentNodeListLength; ptr++)
{
parentNode = parentNodeList.item(ptr);
sTotAmt = checkNull(genericUtility.getColumnValueFromNode("tot_amt", parentNode));
sAdjAmt = checkNull(genericUtility.getColumnValueFromNode("adj_amt", parentNode));
System.out.println(">>>---1---[TotAmt="+totAmt+"]AdjAmt=["+adjAmt+"]");
if(sTotAmt != null && sTotAmt.trim().length() > 0)
{
totAmt = Double.parseDouble(sTotAmt);
}else
{
totAmt = 0;
}
if(sAdjAmt != null && sAdjAmt.trim().length() > 0)
{
adjAmt = Double.parseDouble(sAdjAmt);
}else{
adjAmt = 0;
}
System.out.println(">>>---2---[TotAmt="+totAmt+"]AdjAmt=["+adjAmt+"]");
refSer = checkNull(genericUtility.getColumnValueFromNode("tran_ser", parentNode));
refNo = checkNullAndTrim(genericUtility.getColumnValueFromNode("ref_no", parentNode));
siteCode = checkNull(genericUtility.getColumnValueFromNode("site_code", parentNode));
System.out.println("[1]"+refSer+"[2]"+refNo+"[3]"+siteCode);
if ("R-ADV".equalsIgnoreCase(refSer))
{
refSerPay = "RCPADV";
}else{
refSerPay = "RCVCNV";
}
// select all necessary details from receivables
tranIdRec = checkNull(genericUtility.getColumnValueFromNode("tran_id", parentNode));
sRefDate = checkNull(genericUtility.getColumnValueFromNode("ref_date", parentNode));
currCode = checkNull(genericUtility.getColumnValueFromNode("curr_code", parentNode));
sExchRate = checkNull(genericUtility.getColumnValueFromNode("exch_rate", parentNode));
custCode = checkNull(genericUtility.getColumnValueFromNode("cust_code", parentNode));
acctCode = checkNull(genericUtility.getColumnValueFromNode("acct_code", parentNode));
cctrCode = checkNull(genericUtility.getColumnValueFromNode("cctr_code", parentNode));
sDueDate = checkNull(genericUtility.getColumnValueFromNode("due_date", parentNode));
finEnt = checkNull(genericUtility.getColumnValueFromNode("fin_entity", parentNode));
bankCode = checkNull(genericUtility.getColumnValueFromNode("bank_code", parentNode));
sundryType = "C";
status = "U";
System.out.println("[1]"+tranIdRec+"[2]"+sRefDate+"[3]"+currCode+"[4]"+sExchRate+"[5]"+custCode+"[6]"+acctCode+"[7]"+cctrCode+"[8]"+sDueDate+"[9]"+finEnt);
if(sDueDate != null && sDueDate.trim().length() > 0){
dueDate = Timestamp.valueOf(genericUtility.getValidDateString(sDueDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
if(sRefDate != null && sRefDate.trim().length() > 0){
refDate = Timestamp.valueOf(genericUtility.getValidDateString(sRefDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
if(sExchRate!= null && sExchRate.trim().length() > 0)
{
exchRate = Double.parseDouble(sExchRate);
}
//
sql = "update receivables set adj_amt = tot_amt, stat_date = ?, status = 'A' " +
" where tran_ser = ? " +
" and ref_no = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setTimestamp(1, tranDate);
pstmt1.setString(2, refSer);
pstmt1.setString(3, refNo);
pstmt1.executeUpdate();
pstmt1.close();
pstmt1 = null;
tranId = generateTranId("t_payables", "PAYL", siteCode, conn);
System.out.println("Misc_Payables Transaction Id:"+tranId);
/*System.out.println("MISC_PAYABLES Tran_Id:"+tranId);
sql = "INSERT INTO MISC_PAYABLES ( TRAN_ID, TRAN_SER, TRAN_DATE, REF_NO, REF_DATE, CURR_CODE, EXCH_RATE, SUNDRY_CODE, SUNDRY_TYPE, ACCT_CODE, CCTR_CODE, DUE_DATE, FIN_ENTITY, SITE_CODE, TOT_AMT, ADJ_AMT, STATUS, STATUS_DATE, BANK_CODE ) " +
" values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";
pstmt2 = conn.prepareStatement(sql);*/
pstmt2.setString(1, tranId);
pstmt2.setString(2, refSerPay);
pstmt2.setTimestamp(3, tranDate);
pstmt2.setString(4, refNo);
pstmt2.setTimestamp(5, refDate);
pstmt2.setString(6, currCode);
pstmt2.setDouble(7, exchRate);
pstmt2.setString(8, custCode);
pstmt2.setString(9, sundryType);
pstmt2.setString(10, acctCode);
pstmt2.setString(11, cctrCode);
pstmt2.setTimestamp(12, dueDate);
pstmt2.setString(13, finEnt);
pstmt2.setString(14, siteCode);
pstmt2.setDouble(15, totAmt * (-1));
pstmt2.setDouble(16, adjAmt * (-1));
pstmt2.setString(17, status);
pstmt2.setTimestamp(18, tranDate);
pstmt2.setString(19, bankCode);
pstmt2.addBatch();
pstmt2.clearParameters();
tranIdRecadj = generateTranId("t_misc_rec_adj", "RECADJ", siteCode, conn);
System.out.println("Misc_Rec_Adj Transaction Id:"+tranIdRecadj);
/*sql="INSERT INTO RECEIVABLES_ADJ ( TRAN_ID, REF_SER, REF_NO, TOT_AMT, ADJ_AMT, REF_SER_ADJ, REF_NO_ADJ, NET_AMT, TRAN_ID__RCV ) " +
" VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)";
pstmt3 = conn.prepareStatement(sql); */
pstmt3.setString(1, tranIdRecadj);
pstmt3.setString(2, refSer);
pstmt3.setString(3, refNo);
pstmt3.setDouble(4, totAmt);
pstmt3.setDouble(5, adjAmt);
pstmt3.setString(6, refSerPay);
pstmt3.setString(7, tranId); //misc_payables tran_id
pstmt3.setDouble(8, totAmt-adjAmt);
pstmt3.setString(9, tranIdRec);
pstmt3.addBatch();
pstmt3.clearParameters();
}
//parentNode loop end
int rowsInserted1[] = pstmt2.executeBatch();
int rowsInserted2[] = pstmt3.executeBatch();
pstmt2.clearBatch();
pstmt3.clearBatch();
System.out.println("---rowsInserted----["+rowsInserted1.length+"]["+rowsInserted2.length+"]");
if(rowsInserted1.length > 0 && rowsInserted1.length > 0)
{
errString = itmDBAccessEJB.getErrorString("","VTCOMPL","","",conn);
if(conn != null)
{
conn.commit();
System.out.println("commited....!!!");
}
}
else
{
errString = itmDBAccessEJB.getErrorString("","VINSERT5 ","","",conn);
return errString;
}
}
catch (SQLException d)
{
System.out.println("Exception : RecPayXfrPrc =>: Process"+ d.toString());
d.printStackTrace();
System.out.println("Exception : RecPayXfrPrc(String xmlString2, String xmlString2, String windowName, String xtraParams):"+ d.getMessage() + ":");
d.printStackTrace();
errString = d.getMessage();
throw new ITMException(d);
}
catch (Exception e)
{
//isError = true;
e.printStackTrace();
System.out.println("Exception in process ::"+ e.getMessage());
try
{
conn.rollback();
} catch (Exception d)
{
System.out.println("Exception : RecPayXfrPrc =>: Process"+ d.toString());
d.printStackTrace();
System.out.println("Exception : RecPayXfrPrc(String xmlString2, String xmlString2, String windowName, String xtraParams):"+ d.getMessage() + ":");
d.printStackTrace();
errString = d.getMessage();
throw new ITMException(d);
}
}
finally
{
try
{
if(conn != null)
{
if(pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
if(pstmt2 != null)
{
pstmt2.close();
pstmt2 = null;
}
if(pstmt3 != null)
{
pstmt3.close();
pstmt3 = null;
}
conn.close();
}
conn = null;
}
catch(Exception d)
{
d.printStackTrace();
throw new ITMException(d);
}
}
return errString;
}
public String generateTranId( String windowName,String tranSer,String siteCode, Connection conn )throws ITMException
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String selSql = "";
String tranId = "";
String keyString = "";
String xmlValues = "";
java.sql.Timestamp currDate = null;
ibase.utility.E12GenericUtility genericUtility= new ibase.utility.E12GenericUtility();
try
{
SimpleDateFormat sdfAppl = new SimpleDateFormat(genericUtility.getApplDateFormat());
currDate = new java.sql.Timestamp(System.currentTimeMillis());
String currDateStr = sdfAppl.format(currDate);
selSql = "SELECT KEY_STRING FROM TRANSETUP WHERE TRAN_WINDOW = ? ";
pstmt = conn.prepareStatement(selSql);
pstmt.setString( 1, windowName );
rs = pstmt.executeQuery();
if (rs.next())
{
keyString = rs.getString("KEY_STRING");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}else
{
selSql = "SELECT KEY_STRING FROM TRANSETUP WHERE TRAN_WINDOW = 'GENERAL' ";
pstmt = conn.prepareStatement(selSql);
pstmt.setString( 1, windowName );
rs = pstmt.executeQuery();
if (rs.next())
{
keyString = rs.getString("KEY_STRING");
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
}
System.out.println("keyString :"+keyString);
System.out.println("tranSer :"+tranSer);
xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
xmlValues = xmlValues + "<Header></Header>";
xmlValues = xmlValues + "<Detail1>";
xmlValues = xmlValues + "<tran_id></tran_id>";
xmlValues = xmlValues + "<site_code>" + siteCode + "</site_code>";
xmlValues = xmlValues + "<tran_date>" + currDateStr + "</tran_date>";
xmlValues = xmlValues + "</Detail1></Root>";
System.out.println("xmlValues :["+xmlValues+"]");
TransIDGenerator tg = new TransIDGenerator(xmlValues, "BASE", CommonConstants.DB_NAME);
tranId = tg.generateTranSeqID(tranSer, "tran_id", keyString, conn);
System.out.println("tranId NEWLY WT SITECODE & DATE :"+tranId);
}
catch (SQLException ex)
{
System.out.println("Exception :generateTranId:" +selSql+ ex.getMessage() + ":");
ex.printStackTrace();
throw new ITMException(ex);
}
catch (Exception e)
{
System.out.println("Exception :generateTranId:" + e.getMessage() + ":");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
}
}
return tranId;
}//generateTranTd()
private String getMsg(String trace,String Code,Connection conn) throws ITMException, Exception
{
String mainStr ="";
try
{
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
String errString = "";
errString = itmDBAccessEJB.getErrorString("",Code,"","",conn);
String begPart = errString.substring(0,errString.indexOf("<message>")+9);
String begDesc = errString.substring(0,errString.indexOf("<description>")+13);
String endDesc = errString.substring(errString.indexOf("</description>"));
mainStr= begPart + trace + " </message><description>";
mainStr= mainStr+endDesc;
begPart = null;
itmDBAccessEJB = null;
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return mainStr;
}
private String checkNullAndTrim(String inputVal)
{
if ( inputVal == null || "null".equals(inputVal))
{
inputVal = "";
}
else
{
inputVal = inputVal.trim();
}
return inputVal;
}
private String checkNull(String input)
{
if (input == null || "null".equals(input))
{
input = "";
}
return input;
}
}
package ibase.webitm.ejb.fin;
import ibase.webitm.ejb.ProcessLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import org.w3c.dom.Document;
@Local // added for ejb3
public interface RecPayXfrPrcLocal extends ProcessLocal
{
public String process() throws RemoteException,ITMException;
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(Document dom, Document dom2, String windowNamem, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.fin;
import ibase.webitm.ejb.ProcessRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
import javax.ejb.Remote;
import org.w3c.dom.Document;
@Remote // added for ejb3
public interface RecPayXfrPrcRemote extends ProcessRemote
{
public String process() throws RemoteException,ITMException;
public String process(Document dom, Document dom2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String process(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(String xmlString, String xmlString2, String windowName, String xtraParams) throws RemoteException,ITMException;
public String getData(Document dom, Document dom2, String windowNamem, String xtraParams) 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