Commit 57bd48e5 authored by ssalve's avatar ssalve

Sarita : Added updated Component for MonthWise AD Code on 19 AUGUST 2019

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@205418 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 985604c8
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.StringTokenizer;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException;
public class MthAdChangeIC extends ValidatorEJB implements MthAdChangeICLocal, MthAdChangeICRemote
{
E12GenericUtility genericUtility = new E12GenericUtility();
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 errString = "";
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);
}
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
System.out.println("ErrString :" + errString);
}
catch(Exception e)
{
System.out.println("Exception :AdChangeIC :wfValData(String xmlString):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("Returning from EmpITDeclarationIC wfValData");
return errString;
}
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
String userId = null;
String errString = "";
String empCode = "";
String sql = "";
Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
NodeList parentList = null;
NodeList childList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
int counterChild = 0;
int noOfChilds = 0;
int currentFormNo = 0;
int cnt = 0;
String adCode = "", erroCode = "",refNo = "",errorType = "",errCode = "", loginSite = "";
String effDateStr = "",paySite = "",refType = "",expDateStr = "", balOpt = "";
java.sql.Timestamp effDate = null , expDate = null;
ArrayList<String> errList = new ArrayList<String>();
ArrayList<String> errFields = new ArrayList<String>();
AdmCommon admCommon = new AdmCommon();
StringBuffer errStringXml = new StringBuffer("<?xml version = \"1.0\"?> \r\n <Root> <Errors>");
try
{
System.out.println("In case 1 ::::::::");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
loginSite = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode"));
conn = getConnection();
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
System.out.println("currentFormNo:::"+currentFormNo);
switch(currentFormNo)
{
case 1:
{
parentList = dom.getElementsByTagName("Detail" + currentFormNo);
parentNode = parentList.item(0);
childList = parentNode.getChildNodes();
noOfChilds = childList.getLength();
System.out.println("noOfChilds == "+noOfChilds);
for(counterChild = 1; counterChild < noOfChilds; counterChild++)
{
childNode = childList.item(counterChild);
childNodeName = childNode.getNodeName();
if("emp_code".equalsIgnoreCase(childNodeName))
{
empCode = checkNull(genericUtility.getColumnValue("emp_code", dom));
effDateStr = checkNull(genericUtility.getColumnValue("eff_date", dom));
if(effDateStr != null && effDateStr.trim().length() > 0)
{
effDate = Timestamp.valueOf(genericUtility.getValidDateString(effDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
System.out.println("emp_code ["+empCode+"]");
sql = "select count(*) as cnt from employee where emp_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCode);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("cnt");
}
System.out.println("cnt is ::"+cnt);
closeResources(pstmt,rs);
if(cnt == 0)
{
errCode = "VMEMP1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else
{
sql = "select pay_site from employee where emp_code = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCode);
rs = pstmt.executeQuery();
if(rs.next())
{
paySite = rs.getString("pay_site");
}
closeResources(pstmt,rs);
errCode = admCommon.gbfEmp(empCode, effDate, paySite, loginSite, conn);
System.out.println("errCode is ::: ["+errCode+"]");
if(erroCode != null && erroCode.trim().length() > 0)
{
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}//End of Validation for Employee Code
if("eff_date".equalsIgnoreCase(childNodeName))
{
effDateStr = checkNull(genericUtility.getColumnValue("eff_date", dom));
System.out.println("eff_date is :: ["+effDateStr+"]");
if(effDateStr == null || effDateStr.trim().length() == 0)
{
errCode = "VTDATE11";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}//End of Validation for eff_date
if("exp_date".equalsIgnoreCase(childNodeName))
{
effDateStr = checkNull(genericUtility.getColumnValue("eff_date", dom));
expDateStr = checkNull(genericUtility.getColumnValue("exp_date", dom));
System.out.println("eff_date : ["+effDateStr+"] \t exp_date : ["+expDateStr+"]");
if(effDateStr != null && effDateStr.trim().length() > 0)
{
effDate = Timestamp.valueOf(genericUtility.getValidDateString(effDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
if(expDateStr != null && expDateStr.trim().length() > 0)
{
expDate = Timestamp.valueOf(genericUtility.getValidDateString(expDateStr, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00.0");
}
if(expDateStr == null || expDateStr.trim().length() == 0)
{
errCode = "VTDATE11";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else if(effDateStr == null || effDateStr.trim().length() == 0)
{
errCode = "VTDATE11";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
if((effDate != null && (expDate != null)) && effDate.after(expDate))
{
errCode = "VMEXPDATE";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}//End of Validation for exp_date
if("ref_type".equalsIgnoreCase(childNodeName))
{
refType = checkNull(genericUtility.getColumnValue("ref_type", dom));
empCode = checkNull(genericUtility.getColumnValue("emp_code", dom));
refNo = checkNull(genericUtility.getColumnValue("ref_no", dom));
System.out.println("ref_type is ::: ["+refType+"] \t emp_code is ::: ["+empCode+"]");
if(!"O".equalsIgnoreCase(refType) && !"L".equalsIgnoreCase(refType))
{
errCode = "VTREF1";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
else if ("L".equalsIgnoreCase(refType))
{
cnt = 0;
sql = "select count(*) as count from loans where loan_no = ? and emp_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, refNo);
pstmt.setString(2, empCode);
rs = pstmt.executeQuery();
if(rs.next())
{
cnt = rs.getInt("count");
}
closeResources(pstmt,rs);
if(cnt == 0)
{
errCode = "VTLOAN3";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
else if("O".equalsIgnoreCase(refType))
{
adCode = checkNull(genericUtility.getColumnValue("ad_code", dom));
System.out.println("AD Code is :: ["+adCode+"]");
closeResources(pstmt,rs);
sql = "select bal_opt from allwdedn where ad_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, adCode);
rs = pstmt.executeQuery();
if(rs.next())
{
balOpt = rs.getString("bal_opt");
}
closeResources(pstmt,rs);
if("C".equalsIgnoreCase(balOpt))
{
errCode = "VTCONS";
errList.add(errCode);
errFields.add(childNodeName.toLowerCase());
}
}
}//End of Validation for ref_type
}//end of case statement
}
break;
}
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)
{
System.out.println("Exception :AdChangeIC :wfValData(Document dom):" + e.getMessage() + ":");
errString = genericUtility.createErrorString(e);
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(stmt != null)
{
stmt.close();
stmt = null;
}
if(conn != null)
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
System.out.println("Closing Connection...........");
e.printStackTrace();
throw new ITMException(e);
}
}
errString = errStringXml.toString();
System.out.println("testing : final errString : " + errString);
return errString;
}
public String itemChanged(String xmlString, String xmlStringHdr, String xmlStringAll, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
Document dom = null, domHdr = null, domAll = null;
String valueXmlString = "";
try {
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = genericUtility.parseString(xmlString);
}
if (xmlStringHdr != null && xmlStringHdr.trim().length() > 0)
{
domHdr = genericUtility.parseString(xmlStringHdr);
}
if (xmlStringAll != null && xmlStringAll.trim().length() > 0)
{
domAll = genericUtility.parseString(xmlStringAll);
}
valueXmlString = itemChanged(dom, domHdr, domAll, objContext, currentColumn, editFlag, xtraParams);
}
catch (Exception e)
{
System.out.println("Exception [" + this.getClass().getSimpleName() + "] : [itemChanged(S)] " + e.getMessage());
throw new ITMException(e);
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
{
String sql = "", empCode = "", adCode = "", empFname = "", empLname = "";
String effDateStr = "", expDateStr = "", propYn = "", refType = "", refNo = "",logInEmpCode = "";
int currentFormNo = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
StringBuffer valueXmlString = new StringBuffer();
Calendar cal = Calendar.getInstance();
java.sql.Timestamp joinDate = null , effDate1 = null;
String today = "", monthCode = "", paySite = "",lsDate = "";
AdmCommon admCommon = new AdmCommon();
UtilMethods utilmethod = new UtilMethods();
String lsEmpadAprv = "";
Date mdate1 = null;
DateFormat df = new SimpleDateFormat("yy");
Date ldEffdate = null,lveToDate1 = null, ldTemp = null ;
try
{
conn = getConnection();
if (objContext != null && objContext.trim().length() > 0)
{
currentFormNo = Integer.parseInt(objContext);
}
logInEmpCode = getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
System.out.println("[" + this.getClass().getSimpleName() + "] [itemChanged(D)]:currentFormNo:" + currentFormNo);
System.out.println("currentColumn:::::" + currentColumn);
valueXmlString = new StringBuffer("<?xml version=\"1.0\" encoding=''?>\r\n<Root>\r\n<header>\r\n<editFlag>");
valueXmlString.append(editFlag).append("</editFlag>\r\n</header>\r\n");
switch (currentFormNo)
{
case 1:
{
valueXmlString.append("<Detail1>\r\n");
if ("itm_default".equalsIgnoreCase(currentColumn))
{
System.out.println("--------Inside itm_default-------- \n xtraParams-------" + xtraParams);
adCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "ad_code"));
empCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"emp_code"));
monthCode = checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams,"month_code"));
refType = checkNull(genericUtility.getColumnValue("ref_type", dom));
refNo = checkNull(genericUtility.getColumnValue("ref_no", dom));
sql = "select pay_site as ls_site "
+ "from employee "
+ "where "
+ "emp_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCode);
rs = pstmt.executeQuery();
if (rs.next())
{
paySite = checkNull(rs.getString("ls_site"));
}
System.out.println("ls_site is == "+paySite);
closeResources(pstmt,rs);
String lsMonth = "" , lsTemp = "";
mdate1 = utilmethod.today();
String year = String.valueOf(utilmethod.year(mdate1));
System.out.println("Date is :: " +mdate1 + "\t" + year);
lsDate = "01/"+ monthCode + "/" + df.format(Calendar.getInstance().getTime());
ldEffdate= new SimpleDateFormat("dd/mm/yy").parse(lsDate);
/* ldTemp = utilmethod.RelativeDate(ldEffdate, 27);
lsMonth = utilmethod.mid(String.valueOf(ldTemp), 4, 2);
System.out.println("lsDate ["+lsDate+"] \n ldEffdate ["+ldEffdate+"] \n "
+ "ldTemp ["+ldTemp+"] \n lsMonth ["+lsMonth+"]");
do
{
ldTemp = utilmethod.RelativeDate(ldTemp, 1);
lsTemp = utilmethod.mid(String.valueOf(ldTemp), 4, 2);
System.out.println("Inside DO :: ldTemp["+ldTemp+"] \t lsTemp["+lsTemp+"]");
}
while(lsTemp.equalsIgnoreCase(lsMonth));
ldExpdate = utilmethod.RelativeDate(ldTemp, -1);
System.out.println("Final ldTemp is ::" +ldExpdate);*/
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd/MM/yy", Locale.US);
LocalDate date = LocalDate.parse(lsDate, dateFormat);
LocalDate ldExpdate = date.withDayOfMonth(date.getMonth().length(date.isLeapYear()));
System.out.println(ldExpdate);
expDateStr = String.valueOf(ldExpdate);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date expDate = sdf.parse(expDateStr);
sdf = new SimpleDateFormat("dd/MM/yy");
expDateStr = sdf.format(expDate); System.out.println(sdf.format(expDate));
/*System.out.println("1111111111111" + ldExpdateStr);
SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yy");
String st = sdf.format(ldExpdateStr);
System.out.println(":: ["+ldTemp+"]\t :: ["+lsTemp+"]\t :: ["+ldExpdate+"] :: + ["+st+"]");*/
sql = "select prop_yn as ls_propyn from allwdedn where ad_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, adCode);
rs = pstmt.executeQuery();
if (rs.next())
{
propYn = checkNull(rs.getString("ls_propyn"));
}
System.out.println("prop_yn is == "+propYn);
closeResources(pstmt,rs);
if(propYn == null || propYn.trim().length() == 0)
{
propYn = "N";
}
valueXmlString.append("<emp_code><![CDATA[" +empCode+ "]]></emp_code>\r\n");
valueXmlString.append("<month_code><![CDATA[" +monthCode+ "]]></month_code>\r\n");
valueXmlString.append("<ad_code><![CDATA[" +adCode+ "]]></ad_code>\r\n");
valueXmlString.append("<pay_site><![CDATA["+paySite+"]]></pay_site>\r\n");
valueXmlString.append("<eff_date><![CDATA["+lsDate+"]]></eff_date>\r\n");
valueXmlString.append("<exp_date><![CDATA["+expDateStr+"]]></exp_date>\r\n");
valueXmlString.append("<prop_yn><![CDATA["+propYn+"]]></prop_yn>\r\n");
valueXmlString.append("<ref_type><![CDATA["+refType+"]]></ref_type>\r\n");
valueXmlString.append("<ref_no><![CDATA["+refNo+"]]></ref_no>\r\n");
}
else if("emp_code".equalsIgnoreCase(currentColumn))
{
empCode = checkNull(genericUtility.getColumnValue("emp_code", dom));
System.out.println("Employee Code Itemchange :: empCode["+empCode+"]");
sql = "Select emp_fname, emp_lname from employee where emp_code = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, empCode);
rs = pstmt.executeQuery();
if(rs.next())
{
empFname = checkNull(rs.getString("emp_fname"));
empLname = checkNull(rs.getString("emp_lname"));
}
closeResources(pstmt,rs);
valueXmlString.append("<emp_fname><![CDATA[").append(empFname).append("]]></emp_fname>");
valueXmlString.append("<emp_lname><![CDATA[").append(empLname).append("]]></emp_lname>");
}
valueXmlString.append("</Detail1>\r\n");
}
break;
}
valueXmlString.append("</Root>\r\n");
} catch (Exception e) {
System.out.println("Exception in EJB["+this.getClass().getSimpleName()+"]:[" + e.getMessage()+"]");
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try {
if(conn != null)
{
conn.close();
conn = null;
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("Closed all Database Resource...!");
} catch (Exception e)
{
System.out.println("Exception in EJB["+this.getClass().getSimpleName()+"]::itemChanged::[" + e.getMessage()+"]");
throw new ITMException(e);
}
}
System.out.println("Itemchange ::==== ["+valueXmlString.toString()+"]");
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");
}
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != 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 input)
{
return input == null ? "" : input.trim();
}
private void closeResources(PreparedStatement pstmt,ResultSet rs)
{
try{
if (rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
public interface MthAdChangeICLocal extends ValidatorLocal
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.adm;
import java.rmi.RemoteException;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
public interface MthAdChangeICRemote extends ValidatorRemote
{
public String wfValData() throws RemoteException,ITMException;
public String wfValData(String xmlString, String xmlString1, String xmlString2, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged() throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String xmlString2, String objContext, String currentColumn, String editFlag, 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