Commit 34b05a88 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@216730 ce508802-f39f-4f6c-b175-0d175dae99d5
parent ae0fd949
package ibase.webitm.ejb.adm.adv;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.CommonConstants;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.adm.AdmCommon;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.TransIDGenerator;
@Stateless
public class PayStruChgReqConfirm extends ActionHandlerEJB implements PayStruChgReqConfirmLocal,PayStruChgReqConfirmRemote
{
AdmCommon admCommon = new AdmCommon();
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException
{
String retString = "";
ITMDBAccessEJB itmDbAcess = new ITMDBAccessEJB();
Connection conn=null;
String userId = "";
try
{
System.out.println(":::Inside PayStruChgReqConfirm : confirm():::");
conn= getConnection();
retString = postLogic(tranId, xtraParams, forcedFlag, conn);
System.out.println("retString from postLogic : "+retString);
if(retString != null && retString.trim().length() > 0)
{
conn.rollback();
}
else
{
conn.commit();
retString = itmDbAcess.getErrorString("","VTSUCC" , userId, "", conn);
return retString;
}
}
catch(Exception e)
{
System.out.println("Exception :PayStruChgReqConfirm :confirm():" + e.getMessage() + ":");
retString = GenericUtility.getInstance().createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
return retString;
}
public String postLogic(String Tranid,String xtraParams,String forcedFlag,Connection conn) throws ITMException
{
String lsConf = "";
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null;
ITMDBAccessEJB itmDbAcess = new ITMDBAccessEJB();
E12GenericUtility genericUtility = new E12GenericUtility();
String errString = "";
String userId = "",wfStatus="",empCode="";
double amountTotal=0,amountOrgTotal=0;
try
{
System.out.println(":::Inside PayStruChgReqConfirm : postLogic():::");
userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"));
sql="select REQ_STATUS, WF_STATUS,emp_code from PAY_STRU_CHG_REQ_HDR where tran_id = ? for update nowait";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,Tranid);
rs = pstmt.executeQuery();
if(rs.next())
{
lsConf=checkNull(rs.getString("REQ_STATUS"));
wfStatus=checkNull(rs.getString("WF_STATUS"));
empCode=checkNull(rs.getString("emp_code"));
}
else
{
errString=checkNull(itmDbAcess.getErrorString("", "VTPAYALC04",userId, "", conn));
return errString;
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
///
sql="select sum(amount) as amountTotal,sum(AMOUNT_ORIG) as amountOrgTotal from PAY_STRU_CHG_REQ_DET where TRAN_ID= ? and AMOUNT_TYPE='F'";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,Tranid);
rs = pstmt.executeQuery();
if(rs.next())
{
amountTotal=rs.getDouble("amountTotal");
amountOrgTotal=rs.getDouble("amountOrgTotal");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
///
if("A".equalsIgnoreCase(lsConf))
{
System.out.println("::: if 'A' :::");
errString=checkNull(itmDbAcess.getErrorString("", "VTPAYALC05",userId, "", conn));
return errString;
}
else if("C".equalsIgnoreCase(lsConf))
{
System.out.println("::: if 'C' :::");
errString=checkNull(itmDbAcess.getErrorString("", "VTPAYALC06",userId, "", conn));
return errString;
}
else if("S".equalsIgnoreCase(wfStatus))
{
System.out.println("::: if 'WF_STATUS <> S' :::");
errString=checkNull(itmDbAcess.getErrorString("", "VTPAYALC07",userId, "", conn));
return errString;
}
else if(amountOrgTotal != amountTotal)
{
System.out.println("::: total amount not equal for fixed type :::");
errString=checkNull(itmDbAcess.getErrorString("", "VTPAYALC11",userId, "", conn));
return errString;
}
else
{
errString = gbfUpdation(Tranid, "A", xtraParams,empCode, conn);
}
}
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 e) {
e.printStackTrace();
}
}
System.out.println("errString inside postLogic -->"+errString);
return errString;
}
public String gbfUpdation(String tranId, String forcedFlag, String xtraParams,String empCode ,Connection conn) throws ITMException
{
System.out.println("--------------gbfUpdation method of PayStruChgReqConfirm -------------");
ResultSet rs = null;
PreparedStatement pstmt = null;
String sql = "";
String loginEmpCode = "",tranDate="";
String adCode = "",amount="",amt_type="";
String effDate = "";
boolean empStatus = false;
String userId = "";
String errString = "",keyString="";
String termId = "";
String empCodeAprv = "",refSer="";
Timestamp chgDate = null;
Timestamp ldConfDate = null;
String todayDate = "";
int payrollDetCnt=0;
ArrayList<String> prdCodeList = new ArrayList<String>();
ArrayList<Date> effDateList = new ArrayList<Date>();
SimpleDateFormat sdf = null;
E12GenericUtility genericUtility = new E12GenericUtility();
ITMDBAccessEJB itmDbAcess = new ITMDBAccessEJB();
try
{
userId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginCode"));
termId = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId"));
loginEmpCode = checkNull( genericUtility.getValueFromXTRA_PARAMS( xtraParams, "loginEmpCode" ) );
int count=0;
sdf=new SimpleDateFormat(genericUtility.getApplDateFormat());
todayDate=sdf.format(new java.util.Date());
effDate=todayDate;
chgDate = Timestamp.valueOf(genericUtility.getValidDateString(todayDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
sql = "select key_string as keystr, REF_SER as REF_SER from transetup where tran_window = 'w_emp_ad'";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next())
{
keyString = checkNull(rs.getString("keystr"));
refSer = checkNull(rs.getString("REF_SER"));
}
else
{
errString=checkNull(itmDbAcess.getErrorString("", "VTPAYALC08",userId, "", conn));
return errString;
}
System.out.println("keyString"+keyString);
if( rs != null)
{
rs.close();
rs = null;
}
if( pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (refSer == null || refSer.trim().length() == 0)
{
refSer = "E-AD";
}
int prdCnt = 0;
sql="select CODE,fr_date from period where to_date >= ? ORDER BY fr_date";
pstmt=conn.prepareStatement(sql);
pstmt.setTimestamp(1,Timestamp.valueOf(genericUtility.getValidDateString(effDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0"));
rs = pstmt.executeQuery();
while (rs.next())
{
prdCnt = prdCnt + 1;
prdCodeList.add(checkNull(rs.getString("CODE")));
effDateList.add(rs.getDate("fr_date"));
if (prdCnt == 2)
{
break;
}
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(prdCnt < 2)
{
System.out.println("::: if 'A' :::");
errString=checkNull(itmDbAcess.getErrorString("", "VTPAYALC09",userId, "", conn));
return errString;
}
sql="select count(1) as cnt from PAYROLL where emp_code= ? and prd_code = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,empCode);
pstmt.setString(2,(String)prdCodeList.get(0));
rs = pstmt.executeQuery();
if(rs.next())
{
payrollDetCnt=rs.getInt("cnt");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (payrollDetCnt > 0)
{
System.out.println("effDate 1>>>>>"+effDateList.get(1));
effDate = sdf.format(effDateList.get(1));
System.out.println("effDate 1>>>>>"+effDate);
}
else
{
System.out.println("effDate 1>>>>>"+effDateList.get(0));
effDate = sdf.format(effDateList.get(0));
System.out.println("effDate 0>>>>>"+effDate);
}
sql="select * from PAY_STRU_CHG_REQ_DET where tran_id = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,tranId);
rs = pstmt.executeQuery();
while(rs.next())
{
adCode = checkNull(rs.getString("ad_code"));
amount=checkNull(rs.getString("amount"));
amt_type=checkNull(rs.getString("amount_type"));
System.out.println("effDate>>>>>"+effDate);
System.out.println("adCode>>>>>"+adCode);
System.out.println("amount>>>>>"+amount);
System.out.println("amt_type>>>>>"+amt_type);
System.out.println("empCode>>>>>"+empCode);
empStatus = admCommon.empPrevRec(empCode, adCode, effDate, conn);
System.out.println("empStatus from adm>>>"+empStatus);
String xmlValues = "";
xmlValues ="<?xml version=\"1.0\" encoding=\"utf-8\"?><Root>";
xmlValues = xmlValues + "<Header></Header>";
xmlValues = xmlValues + "<Detail1>";
xmlValues = xmlValues + "<tran_id></tran_id>";
xmlValues = xmlValues + "<tran_date>" + tranDate + "</tran_date>";
xmlValues = xmlValues + "<emp_code>" + empCode + "</emp_code>";
xmlValues = xmlValues + "</Detail1></Root>";
System.out.println("xmlValues for PayStruChgReqConfirm :["+xmlValues+"]");
TransIDGenerator tg = new TransIDGenerator(xmlValues, userId, CommonConstants.DB_NAME);
String newtranId = tg.generateTranSeqID(refSer, "tran_id", keyString, conn);
System.out.println("Generated tran Id:::"+tranId);
empStatus=insertEmpAd(empCode, adCode, effDate, amount, amt_type, userId, termId, newtranId, todayDate, conn);
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(empStatus)
{
System.out.println("forcedFlag::"+forcedFlag);
if("A".equalsIgnoreCase(forcedFlag))
{
ldConfDate = Timestamp.valueOf(genericUtility.getValidDateString(todayDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
sql="update PAY_STRU_CHG_REQ_HDR set REQ_STATUS = ? , STATUS_DATE = ?, EMP_CODE__APRV = ? where tran_id = ?";
pstmt =conn.prepareStatement(sql);
pstmt.setString(1,"A");
pstmt.setTimestamp(2, ldConfDate);
pstmt.setString(3,loginEmpCode);
pstmt.setString(4,tranId);
count = pstmt.executeUpdate();
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("confirm updated -------->>>>>>>>>updCount :"+count);
}
}
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 e)
{
System.out.println("Exception ::" + e);
e.printStackTrace();
throw new ITMException(e);
}
}
return errString;
}
private String checkNull(String input)
{
if (input == null)
{
input = "";
}
else
{
input = input.trim();
}
return input;
}
public boolean insertEmpAd(String empCode, String adCode, String effDate,String amount,String amt_type,String chgUser,String chgTerm,String tranId, String currDate,Connection conn) throws ITMException
{
boolean status = false;
String updSql = "";
int instCnt = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
conn.setAutoCommit(false);
GenericUtility genericUtility = GenericUtility.getInstance();
updSql = "insert into EMPLOYEE_AD (EMP_CODE,AD_CODE,EFF_DATE,EXP_DATE,AMOUNT,TYPE,CHG_DATE,CHG_USER,CHG_TERM,TRAN_ID,MAX_BASIC,MIN_AMT,MIN_BASIC,MAX_AMT,CONFIRMED) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
System.out.println("Insert sql In [empPrevRec][updSql][1]........:: " + updSql);
pstmt = conn.prepareStatement(updSql);
pstmt.setString(1, empCode);
pstmt.setString(2, adCode);
pstmt.setTimestamp(3,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(effDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
pstmt.setTimestamp(4,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString("31/12/35",genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
pstmt.setString(5, amount);
pstmt.setString(6, amt_type);
pstmt.setTimestamp(7,java.sql.Timestamp.valueOf(genericUtility.getValidDateTimeString(currDate,genericUtility.getApplDateFormat(),genericUtility.getDBDateFormat())));
pstmt.setString(8, chgUser);
pstmt.setString(9, chgTerm);
pstmt.setString(10, tranId);
pstmt.setString(11, "0");
pstmt.setString(12, "0");
pstmt.setString(13, "0");
pstmt.setString(14, "0");
pstmt.setString(15, "Y");
instCnt = pstmt.executeUpdate();
if(instCnt == 1)
{
status = true;
System.out.println("Insert Into EMPLOYEE_AD Sucessfully......! [updCnt] :: "+ instCnt);
}
else
{
status = false;
System.out.println("No Insert into EMPLOYEE_AD......! [updCnt] :: "+ instCnt);
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception ex){}
}
return status;
}
}
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