Commit 73e8f845 authored by Ketan Patil's avatar Ketan Patil

Added by Pravin for Wildfly20

parent 2cc8121d
package ibase.webitm.ejb.fin.advfield;
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.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import ibase.utility.E12GenericUtility;
import ibase.utility.EMail;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.XML2DBEJB;
import ibase.webitm.reports.utility.GetXMLData;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.ejb.Stateless;
import ibase.webitm.utility.GenerateXmlFromDB;
import ibase.webitm.utility.ITMException;
@Stateless
public class VoucherAdvSuppCancel extends ActionHandlerEJB implements VoucherAdvSuppCancelLocal, VoucherAdvSuppCancelRemote {
E12GenericUtility genericUtility = new E12GenericUtility();
public String confirm()
throws RemoteException, ITMException
{
return "";
}
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException, ITMException {
String resultStr = "";
Connection conn = null;
try
{
conn = getConnection();
resultStr = confirm(tranId, xtraParams, forcedFlag, conn);
System.out.println("resultStr:::::" + resultStr);
if (conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception e)
{
System.out.println("Exception [01][cancel]::" + e.getMessage());
e.printStackTrace();
System.out.println("Exception ::" + e.getMessage());
throw new ITMException(e);
}
finally
{
if (conn != null)
{
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
System.out.println("Returning Result from cancel::" + resultStr);
return resultStr;
}
public String confirm(String tranId, String xtraParams, String forcedFlag, Connection conn) throws RemoteException,ITMException
{
System.out.println("- - - - - - - Inside cancel method start -----");
PreparedStatement pstmt = null, pstmt1 = null;
PreparedStatement pstmt2 = null;
ResultSet rs = null;
String sql = "", sql1 = "";
int cnt=0;
String status="";
String retString = "";
ITMDBAccessEJB itmdbAccess = null;
String loginCode="",loginEmpCode="",objName="",winName="";
try
{
itmdbAccess = new ITMDBAccessEJB();
Date date=null;
java.sql.Date date1=null;
SimpleDateFormat sdf;
sdf = new SimpleDateFormat(
genericUtility.getApplDateFormat());
Calendar currentDate = Calendar.getInstance();
String sysDate = sdf.format(currentDate.getTime());
date=sdf.parse(sysDate);
date1 = new java.sql.Date(date.getTime());
// String dateToStr = DateFormat.getDateInstance().format(currentDate);
Date date3 = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yy");
String strDate= formatter.format(date3);
System.out.println(strDate);
//--------------------------------------------------------------------------------
Calendar currentDate1 = Calendar.getInstance();
String sysDate1 = sdf.format(currentDate.getTime());
date=sdf.parse(sysDate1);
date1 = new java.sql.Date(date.getTime());
System.out.println("date1"+date1);
Date date4 = new Date();
SimpleDateFormat formatter1 = new SimpleDateFormat("dd-MMM-yyyy");
String strDate1= formatter1.format(date4);
System.out.println(strDate1);
System.out.println("strDate1"+strDate1);
//------------------------------------------------------------------------
System.out.println("strDate"+strDate);
loginEmpCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
System.out.println("loginEmpCode---["+loginEmpCode+"]");
objName = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "objName");
System.out.println("objName---["+objName+"]");
sql = "SELECT status FROM cash_voucher WHERE tran_id = ?";
System.out.println("sql-->"+sql);
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId);
rs=pstmt.executeQuery();
if (rs.next())
{
status = rs.getString("status").trim();
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if(status.equalsIgnoreCase("O"))
{
sql1="update cash_voucher set status='X', cancelled_date=? where tran_id = ?";
System.out.println("sql1-->"+sql1);
pstmt2 = conn.prepareStatement(sql1);
pstmt2.setDate(1,date1);
pstmt2.setString(2,tranId);
cnt =pstmt2.executeUpdate();
System.out.println("----- Rows To Be Updated ......"+cnt);
winName="w_"+objName;
if (cnt >= 1)
{
retString = itmdbAccess.getErrorString("", "STATCHGRJ4", "", "", conn);
XML2DBEJB xml2dbObj = new XML2DBEJB();
GenerateXmlFromDB generateXmlFromDB = new GenerateXmlFromDB();
String retXml = generateXmlFromDB.getXMLData(winName, tranId, conn , true);
System.out.println(">>>In invokeWorkflow retXml:"+retXml);
retXml = retXml.replace("<Root>", "");
retXml = retXml.replace("</Root>", "");
System.out.println(">>>In invokeWorkflow retXmlererttr:"+retXml);
String transInfoXml = "";
StringBuffer xmlStringBuff = new StringBuffer();
String bifurString = retXml.substring(0, retXml.indexOf("</prv_amt>")+10);
System.out.println("transInfoXml1>>"+bifurString);
bifurString = bifurString+"<activity_date><![CDATA["+strDate1+"]]></activity_date>";
System.out.println("transInfoXml2>>"+bifurString);
bifurString =bifurString+retXml.substring(retXml.indexOf("</Detail2>"), retXml.indexOf("</DocumentRoot>")+15);
System.out.println("transInfoXml3>>"+bifurString);
retXml=bifurString.toString();
System.out.println("CHANGES FOR REMARK>>"+retXml);
if(winName.equalsIgnoreCase("w_voucher_advfield")){
sendMail(retXml, "", "", tranId, "1", "ADVCANL", "E", loginEmpCode,"");
}
if(winName.equalsIgnoreCase("w_voucher_advsupp"))
{
sendMail(retXml, "", "", tranId, "1", "ASUPPCANL", "E", loginEmpCode,"");
}
if(winName.equalsIgnoreCase("w_voucher_advfield_user"))
{
sendMail(retXml, "", "", tranId, "1", "ADVCANL_F", "E", loginEmpCode,"");
}
}
pstmt2.close();
pstmt2 = null;
}
else {
retString = itmdbAccess.getErrorString("", "VTEMPSPA11", "", "", conn);
}
System.out.println("- - - - - - - Inside cancel end -----");
}
catch (Exception ex)
{
System.out.println("Exception in cancel[CashVoucher] :"+ex.getMessage());
ex.printStackTrace();
throw new ITMException(ex);
}
finally
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (pstmt2 != null)
{
pstmt2.close();
pstmt2 = null;
}
if (rs != null) {
rs.close();
rs = null;
}
if (conn != null) {
conn.close();
conn = null;
}
}
catch (SQLException se)
{
throw new ITMException(se);
}
}
return retString;
}
private String checkNull(String input) {
return input == null ? "" : input;
}
private String getAttribValue(Node detailNode, String attribStr)
{
String attribValue = "";
try
{
if( detailNode != null && detailNode.getAttributes() != null)
{
Node attribNode = detailNode.getAttributes().getNamedItem( attribStr );
if( attribNode != null )
{
attribValue = checkNull( attribNode.getNodeValue() );
}
}
}
catch(Exception e)
{
System.out.println("Exception : getAttribValue :" + e.getMessage());
}
return attribValue;
}
private String getAttribValue(Node detailNode, String nodeName, String attribStr)
{
String attribValue = "";
try
{
String domStr = genericUtility.serializeDom(detailNode);
Document dom = genericUtility.parseString(domStr);
if( dom != null /*&& dom.getAttributes() != null*/)
{
Node attributeNode = dom.getElementsByTagName( nodeName ).item(0);
attribValue = getAttribValue(attributeNode, attribStr);
}
}
catch(Exception e)
{
System.out.println("Exception : getAttribValue :" + e.getMessage());
}
return attribValue;
}
private void sendMail(String transInfo, String refSer, String objName, String refId,String lineNo,String formatCode,String entityType,String entityCode, String mailIdCcAdd )throws ITMException
{
System.out.println("sendMail Sending mail for cancellation ...........");
boolean emailFlag = false;
String emailType="link";
System.out.println("refId>>"+refId);
System.out.println("formatCode>>"+formatCode);
System.out.println("entityType>>"+entityType);
System.out.println("entityCode>>"+entityCode);
System.out.println("mailIdCcAdd>>"+mailIdCcAdd);
try
{
Document xmlDom = null;
/*if (transInfo.length() > 0)
{
xmlDom = GenericUtility.getInstance().parseString(transInfo);
transInfo = GenericUtility.getInstance().serializeDom(xmlDom);
System.out.println("after Parse["+transInfo+"]");
}*/
System.out.println("after Parse["+transInfo+"]");
if(formatCode != null)
{
String mailDomStr = "<ROOT>"
+"<TRANS_INFO>"
+"<OBJ_NAME>"+objName+"</OBJ_NAME>"
+"<REF_ID>"+refId+"</REF_ID>"
+"<REF_SER>"+refSer+"</REF_SER>"
+"<LINE_NO>"+lineNo+"</LINE_NO>"
+"</TRANS_INFO>"
+"<MAIL>"
+"<EMAIL_TYPE>"+emailType+"</EMAIL_TYPE>"
+"<ENTITY_TYPE>"+entityType+"</ENTITY_TYPE>"
+"<FORMAT_CODE>"+formatCode+"</FORMAT_CODE>"
+"<ENTITY_CODE>"+entityCode+"</ENTITY_CODE>"
+"<CC_ADD>"+ mailIdCcAdd +"</CC_ADD>"
+"<SUBJECT>"+""+"</SUBJECT>"
+"<ATTACHMENT>"
+"<BODY></BODY>"
+"<LOCATION></LOCATION>"
+"</ATTACHMENT>"
+"</MAIL>"
+"<XML_DATA>"+transInfo+"</XML_DATA>"
//+"<LINK_ADDR>"+"ITMTransactionEditor.jsp?Status=OUTER&amp;OBJ_CONTEXT=1&amp;OBJ_NAME="+objName+"&amp;EDIT_FLAG=V&amp;DB_ID="+refId+"</LINK_ADDR>"
// +"<LINK_ADDR>"+"signature.jsp?OBJ_NAME=supp_bank_dtls&amp;REF_SER=SUB&amp;REF_ID="+refId+"&amp;LINE_NO=1&amp;XSL_FILE_NAME=SUPPBANKDETAILS_NEW"+"</LINK_ADDR>"
+"</ROOT>";
EMail email = new EMail();
email.sendMail(mailDomStr, "ITM");
}
}
catch (ITMException itme)
{
throw itme;
}
catch (Exception e)
{
throw new ITMException(e);
}
}
}
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