Commit 91c6c515 authored by sanashaikh's avatar sanashaikh

Sana S: Added on 17/02/20

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@216727 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 94f107c7
package ibase.webitm.ejb.adm.adv;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.ejb.Stateless;
import ibase.utility.E12GenericUtility;
import ibase.utility.EMail;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.adm.AdmCommon;
import ibase.webitm.utility.ITMException;
@Stateless
public class PayStruChgReqCancel extends ActionHandlerEJB implements PayStruChgReqCancelLocal,PayStruChgReqCancelRemote
{
AdmCommon admCommon = new AdmCommon();
ITMDBAccessEJB itmDbAcess = new ITMDBAccessEJB();
E12GenericUtility genericUtility = new E12GenericUtility();
public String cancel(String tranId, String xtraParams, String forcedFlag)
{
Connection conn = null;
String userId = "";
String retString = "";
try
{
System.out.println(":::Inside PayStruChgReqCancel : cancel():::");
conn = getConnection();
retString = postLogic(tranId, xtraParams, forcedFlag, conn);
System.out.println("retString from postLogic : "+retString);
if(retString != null && retString.trim().length() > 0 && retString.indexOf("VTPAYALC12")<0)
{
conn.rollback();
}
else
{
conn.commit();
retString = itmDbAcess.getErrorString("","VTPAYALC12" , userId, "", conn);
}
}
catch(Exception e)
{
System.out.println("Exception :PayStruChgReqCancel :Cancel():" + e.getMessage() + ":");
retString = genericUtility.createErrorString(e);
e.printStackTrace();
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return retString;
}
@SuppressWarnings("resource")
public String postLogic(String Tranid,String xtraParams,String forcedFlag,Connection conn) throws ITMException, SQLException
{
String errString = "";
String userId = "";
String sql = "";
//String workSite = "";
String empCodeHr = "";
String loginEmpCode = "",emailCC="";
String email = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
ArrayList<String> empList = new ArrayList<>();
int cnt = 0 , MailCnt = 0;
boolean isMailSend = false;
String workSite = "";
String reqStatus = "";
try
{
System.out.println(":::Inside PayStruChgReqCancel : postLogic():::");
userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode"));
loginEmpCode=userId;
workSite = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
sql = "SELECT REQ_STATUS FROM PAY_STRU_CHG_REQ_HDR WHERE TRAN_ID = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,Tranid);
rs = pstmt.executeQuery();
if(rs.next())
{
reqStatus = checkNull(rs.getString("REQ_STATUS"));
System.out.println("reqStatus:::==" +reqStatus);
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if("A".equalsIgnoreCase(reqStatus))
{
errString = checkNull(itmDbAcess.getErrorString("", "VTPAYALC13",userId, "", conn));//Already Approved
}
else if("C".equalsIgnoreCase(reqStatus))
{
errString = checkNull(itmDbAcess.getErrorString("", "VTPAYALC14",userId, "", conn));//Already Cancelled
}
else if("U".equalsIgnoreCase(reqStatus))
{
//
sql = "UPDATE PAY_STRU_CHG_REQ_HDR SET REQ_STATUS = 'C' where TRAN_ID = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,Tranid);
cnt = pstmt.executeUpdate();
System.out.println("CNT1111...." +cnt);
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(cnt > 0)
{
errString = checkNull(itmDbAcess.getErrorString("", "VTPAYALC12",userId, "", conn));//Status Updated successfully
System.out.println("Status Updated successfully...." +cnt);
sql = "SELECT EMAIL_ID_OFF FROM EMPLOYEE WHERE EMP_CODE = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,loginEmpCode);
rs = pstmt.executeQuery();
if(rs.next())
{
emailCC = checkNull(rs.getString("EMAIL_ID_OFF"));
System.out.println("emailCC:::==" +emailCC);
}
if(rs != null)
{
rs.close();
rs = null;
}
pstmt.clearParameters();
empList=getHREmpCode(loginEmpCode, conn);
System.out.println("empList getting is ::::" +empList.toString());
System.out.println("length of empList::::" +empList.toString().length());
if( empList.size() > 0 )
{
System.out.println("empList size "+empList.size());
for(int i = 0 ; i < empList.size(); i++)
{
empCodeHr = empList.get(i).toString();
System.out.println("empCodeHr FROM EMPLIST...."+empCodeHr);
pstmt.setString(1, empCodeHr);
rs = pstmt.executeQuery();
if(rs.next())
{
email = rs.getString("EMAIL_ID_OFF");
System.out.println("email generated from mailList:::::::" +email);
}
if(rs != null)
{
rs.close();
rs = null;
}
pstmt.clearParameters();
/**calling send mail method*/
// String objName=getObjName(domString, objContext);
isMailSend = sendMail(email, "PYALOC","pay_stru_chg_req_wiz",Tranid,"PYALCHRCAN", "E", empCodeHr, email,emailCC, conn);
if(isMailSend)
{
MailCnt++;
System.out.println("Payroll Process mail send successfully >> "+MailCnt);
}
}
}
}
if(isMailSend)
{
System.out.println("Payroll Process mail send successfully >> "+MailCnt);
}
//
}
}
catch (Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e1)
{
e1.printStackTrace();
throw new ITMException(e1);
}
}
System.out.println("errString inside postLogic of PayStruChgReqCancel-->"+errString);
return errString;
}
private String checkNull(String input)
{
if (input == null)
{
input = "";
}
else
{
input = input.trim();
}
return input;
}
private boolean sendMail(String transInfo, String refSer, String objName, String refId, String formatCode, String entityType, String entityCode,String empCodeMailId, String mailIdCcAdd, Connection conn)
throws ITMException
{
System.out.println("@@## [PayStruChgReqSubmit] :sendMail ...........");
boolean emailFlag = false;
try
{
if (formatCode != null)
{
String lineNo = "1";
StringBuffer valueXmlString = null;
valueXmlString = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><ROOT><TRANS_INFO>");
valueXmlString.append("<OBJ_NAME>").append("<![CDATA[" + objName + "]]>").append("</OBJ_NAME>");
valueXmlString.append("<REF_SER>").append("<![CDATA[" + refSer + "]]>").append("</REF_SER>");
valueXmlString.append("<REF_ID>").append("<![CDATA[" + refId + "]]>").append("</REF_ID>");
valueXmlString.append("<LINE_NO>").append("<![CDATA[" + lineNo + "]]>").append("</LINE_NO>");
valueXmlString.append("</TRANS_INFO>");
valueXmlString.append("<MAIL>");
valueXmlString.append("<ENTITY_TYPE>").append("<![CDATA[" + entityType + "]]>").append("</ENTITY_TYPE>");
valueXmlString.append("<ENTITY_CODE>").append("<![CDATA[" + entityCode + "]]>").append("</ENTITY_CODE>");
valueXmlString.append("<FORMAT_CODE>").append("<![CDATA[" + formatCode +"]]>").append("</FORMAT_CODE>");
valueXmlString.append("<TO_ADD>").append("<![CDATA[" + empCodeMailId +"]]>").append("</TO_ADD>");
valueXmlString.append("<CC_ADD>").append("<![CDATA[" + mailIdCcAdd +"]]>").append("</CC_ADD>");
// valueXmlString.append("<LINK_ADDR>").append("<![CDATA[" + "" + "]]>").append("</LINK_ADDR>");
valueXmlString.append("</MAIL>");
valueXmlString.append("<XML_DATA>").append(transInfo).append("</XML_DATA>");
//valueXmlString.append("<EMAIL_TYPE>").append("<![CDATA[" + "link" + "]]>").append("</EMAIL_TYPE>");
valueXmlString.append("</ROOT>");
String mailDomStr = valueXmlString.toString();
System.out.println(" [PayStruChgReqSubmit] :sendMail mailDomStr :-->" + mailDomStr);
EMail email = new EMail();
email.sendMail(mailDomStr, "ITM", conn);
System.out.println("PayStruChgReqSubmit mail delivered successfully" );
emailFlag = true;
}
}
catch (Exception e)
{
System.out.println("Exception :[PayStruChgReqSubmit] :sendMail() :==>\n" + e.getMessage());
throw new ITMException(e);
}
return emailFlag;
}
private ArrayList<String> getHREmpCode (String empCode, Connection conn) throws ITMException
{
String hrEmpCode = "", hrEmpCode1 = "", hrEmpCode2 = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList<String> empCodeList=new ArrayList<>();
//int hrCnt=0;
try
{
//hrCnt++;
String sql = "SELECT FN_GET_HR_EMP_CODE( ?, 'PYALC', 1) AS HR_EMP_CODE, FN_GET_HR_EMP_CODE( ?, 'PYALC', 2) AS HR_EMP_CODE_1, FN_GET_HR_EMP_CODE( ?, 'PYALC', 3) AS HR_EMP_CODE_2 FROM DUAL";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCode);
pstmt.setString(2, empCode);
pstmt.setString(3, empCode);
rs = pstmt.executeQuery();
if(rs.next())
{
hrEmpCode = checkNull(rs.getString("HR_EMP_CODE"));
hrEmpCode1 = checkNull(rs.getString("HR_EMP_CODE_1"));
hrEmpCode2 = checkNull(rs.getString("HR_EMP_CODE_2"));
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(hrEmpCode.trim().length()>0)
{
empCodeList.add(hrEmpCode);
}
if(hrEmpCode1.trim().length()>0)
{
empCodeList.add(hrEmpCode1);
}
if(hrEmpCode2.trim().length()>0)
{
empCodeList.add(hrEmpCode2);
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt =null;
}
}
catch(SQLException sqle)
{
sqle.printStackTrace();
throw new ITMException(sqle);
}
}
return empCodeList;
}
}
\ 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