Commit bb3be12d authored by asant's avatar asant

w_emp_overtime : migrate confirmation logic to java

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@211944 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 4d30206c
package ibase.webitm.ejb.adm.adv;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import javax.ejb.Stateless;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.adm.AdmCommon;
import ibase.webitm.ejb.sys.UtilMethods;
import ibase.webitm.utility.ITMException;
@Stateless
public class EmpOvertimeConfirm extends ActionHandlerEJB implements EmpOvertimeConfirmLocal,EmpOvertimeConfirmRemote {
public String confirm(String tranId, String xtraParams, String forcedFlag)
{
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
Connection conn = null;
String errCode = "";
try {
conn = getConnection();
errCode = approveOvertime (tranId, xtraParams,forcedFlag, conn);
} catch (Exception e) {
e.printStackTrace();
}
if( errCode.length() > 0)
{
try
{
errCode = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
try {
conn.rollback();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (RemoteException e) {
e.printStackTrace();
} catch (ITMException e) {
e.printStackTrace();
}
} else {
errCode = "VTMCONF2";
try {
errCode = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
} catch (RemoteException e1) {
e1.printStackTrace();
} catch (ITMException e1) {
e1.printStackTrace();
}
try {
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
return errCode;
}
private String approveOvertime (String tranId, String xtraParams, String forcedFlag, Connection conn) throws Exception {
E12GenericUtility genericUtility = new E12GenericUtility();
UtilMethods utilMethods = new UtilMethods();
UserInfoBean userInfoBean = getUserInfo();
AdmCommon admCommon = new AdmCommon();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String errCode = "", grade = "", siteCode = "", limitType = "", empCode = "",
status = "", prdCode = "", extraArg ="";
double limtHrs = 0, overTimeHrs = 0, overTimeCur = 0;
Timestamp overTimeDate = null, currentDatetime = null;
Date toDate = null, fromDate = null;
int from = 0, to = 0, month = 0, year = 0, maxProcNo = 0;
String sqlQuery = "", overTMDate = "", loginEmpCode = "", chngTerm = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
loginEmpCode = genericUtility.checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode"));//userInfoBean.getLoginCode();
chngTerm = genericUtility.checkNull(genericUtility.getValueFromXTRA_PARAMS(xtraParams, "termId"));//userInfoBean.getRemoteAddress();
System.out.println("#### loginEmpCode "+loginEmpCode);
System.out.println("#### chngTerm "+chngTerm);
sqlQuery = "SELECT STATUS, OT_DATE, EMP_CODE, OT_HOURS FROM EMPOTIME WHERE TRAN_ID = ?";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if( rs.next())
{
status = genericUtility.checkNull(rs.getString("STATUS"));
overTimeDate = rs.getTimestamp("OT_DATE");
empCode = genericUtility.checkNull(rs.getString("EMP_CODE"));
overTimeCur = rs.getDouble("OT_HOURS");
if ("A".equalsIgnoreCase(status))
return "VTMCONF1";
if ("X".equalsIgnoreCase(status))
return "VTOTCANC01";
}else {
return "NORECFND";
}
System.out.println("#### status "+status);
System.out.println("#### overTimeDate "+overTimeDate);
System.out.println("#### empCode "+empCode);
System.out.println("#### overTimeCur "+overTimeCur);
} catch (SQLException e) {
System.out.println("#### Exception EMPOTIME SQL "+e);
}finally
{
if(rs != null) {rs.close(); rs = null;}
if(pstmt != null) {pstmt.close(); pstmt = null;}
}
sqlQuery = "SELECT GRADE, WORK_SITE FROM EMPLOYEE WHERE EMP_CODE = ?";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setString(1, empCode);
rs= pstmt.executeQuery();
if( rs.next())
{
grade = genericUtility.checkNull(rs.getString("GRADE"));
siteCode = genericUtility.checkNull(rs.getString("WORK_SITE"));
}else {
return "NORECFND";
}
System.out.println("#### grade "+grade);
System.out.println("#### siteCode "+siteCode);
}catch(Exception e) {
System.out.println("#### Exception EMPLOYEE SQL "+e);
}finally
{
if(rs != null) {rs.close(); rs = null;}
if(pstmt != null) {pstmt.close(); pstmt = null;}
}
sqlQuery = "SELECT LIMIT_TYPE,LIMIT_HRS FROM GRADE_SITE_OT WHERE GRADE_CODE = ? AND SITE_CODE = ? ";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setString(1, grade);
pstmt.setString(2, siteCode);
rs= pstmt.executeQuery();
if( rs.next()) // while ?
{
limitType = genericUtility.checkNull(rs.getString("LIMIT_TYPE"));
limtHrs = rs.getDouble("LIMIT_HRS");
}else
{
return "VTSITEOT1";
}
System.out.println("#### limitType "+limitType);
System.out.println("#### limtHrs "+limtHrs);
}catch (Exception e) {
System.out.println("#### Exception GRADE_SITE_OT SQL "+e);
}finally
{
if(rs != null) {rs.close(); rs = null;}
if(pstmt != null) {pstmt.close(); pstmt = null;}
}
try {
month = utilMethods.month(overTimeDate);
year = utilMethods.year(overTimeDate);
System.out.println("#### month "+month);
System.out.println("#### year "+year);
} catch (ITMException e) {
e.printStackTrace();
}
switch ( limitType )
{
case "M" :
{
from = month;
to = from;
}
break;
case "Q" :
{
if (month < 4 ) {
from = 1;
}
else if (month < 7 ) {
from = 4;
}
else if (month < 10 ) {
from = 7;
}
else {
from = 10;
}
to = from + 2;
}
break;
case "H" :
{
if (month < 7) {
from = 1;
}
else {
from = 7;
}
to = from + 5;
}
break;
case "Y" :
{
from = 1;
to = 12;
}
break;
}
fromDate = utilMethods.date(year,from,1);
toDate = utilMethods.date(year,to,1);
System.out.println("#### fromDate "+fromDate);
System.out.println("#### toDate "+toDate);
sqlQuery = "SELECT SUM(OT_HOURS) AS OT_HOURS FROM EMPOTIME WHERE EMP_CODE = ? AND OT_DATE BETWEEN ? AND ? AND STATUS = 'A'";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setString(1, empCode);
pstmt.setDate(2, fromDate);
pstmt.setDate(3, toDate);
rs= pstmt.executeQuery();
if( rs.next()) // while ?
{
overTimeHrs = rs.getDouble("OT_HOURS");
if ((overTimeHrs + overTimeCur) > limtHrs) {
return "VTOTLIMIT";
}
}else
{
return "NORECFND";
}
}catch (Exception e) {
System.out.println("#### Exception EMPOTIME SQL "+e);
}finally
{
if(rs != null) {rs.close(); rs = null;}
if(pstmt != null) {pstmt.close(); pstmt = null;}
}
sqlQuery = "SELECT CODE FROM PERIOD WHERE FR_DATE <= ? AND TO_DATE >= ?";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setTimestamp(1, overTimeDate);
pstmt.setTimestamp(2, overTimeDate);
rs= pstmt.executeQuery();
if( rs.next()) {
prdCode = genericUtility.checkNull(rs.getString("CODE"));
}else {
return "NORECFND";
}
System.out.println("#### prdCode "+prdCode);
}catch (Exception e) {
System.out.println("#### Exception PERIOD SQL "+e);
}finally
{
if(rs != null) {rs.close(); rs = null;}
if(pstmt != null) {pstmt.close(); pstmt = null;}
}
extraArg = loginEmpCode +"~t" + chngTerm;
System.out.println("#### extraArg "+extraArg);
if(overTimeDate != null)
{
overTMDate = sdf.format(overTimeDate);
}
errCode = admCommon.payarrToProcUpdation(prdCode, prdCode, empCode, empCode, "AR", "W_OVERTIME", " ", "OTAMT", overTimeCur, overTMDate, overTMDate, extraArg, conn);
System.out.println("#### errCode "+errCode);
if (errCode.length() > 0)
return errCode;
sqlQuery = "SELECT MAX(PROC_NO) AS PROC_NO FROM EMPOTIME WHERE EMP_CODE = ? AND PRD_CODE = ? AND CASE WHEN STATUS IS NULL THEN 'N' ELSE STATUS END IN ('A')";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setString(1, empCode);
pstmt.setString(2, prdCode);
rs= pstmt.executeQuery();
if( rs.next())
{
maxProcNo = rs.getInt("PROC_NO");
//li_max_proc_no++ ?
}
System.out.println("#### maxProcNo "+maxProcNo);
}catch (Exception e) {
System.out.println("#### Exception EMPOTIME SQL "+e);
}finally
{
if(rs != null) {rs.close(); rs = null;}
if(pstmt != null) {pstmt.close(); pstmt = null;}
}
currentDatetime = new Timestamp(System.currentTimeMillis());
sqlQuery = "UPDATE EMPOTIME SET STATUS = 'A', STATUS_DATE = ?, EMP_CODE__APRV = ?, APRV_DATE = ?, PROC_NO = ? WHERE TRAN_ID = ?";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setTimestamp(1, currentDatetime);
pstmt.setString(2, loginEmpCode);
pstmt.setTimestamp(3, currentDatetime);
pstmt.setInt(4, maxProcNo);
pstmt.setString(5, tranId);
int updateSql = pstmt.executeUpdate();
System.out.println("#### count "+updateSql);
if( updateSql == 0) {
return "DS000NR";
}
}catch (Exception e) {
System.out.println("#### Exception UPDATE EMPOTIME SQL "+e);
}finally {
if(pstmt != null) {pstmt.close(); pstmt = null;}
}
//SQL Is there, but as no need to implementation of edi block. Code migration is done. [AS per Piyush sir]
/*sqlQuery = "UPDATE EMPOTIME_DET SET APPROVED_FLAG = 'A' WHERE TRAN_ID = ? AND CASE WHEN APPROVED_FLAG IS NULL THEN 'U' ELSE APPROVED_FLAG END NOT IN ('A','P')";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setString(1, as_tranid);
int updateSql = pstmt.executeUpdate();
}catch (Exception e) {
e.printStackTrace();
}finally
{
if(pstmt != null) {pstmt.close(); pstmt = null;}
}
sqlQuery = "SELECT EDI_OPTION FROM TRANSETUP WHERE TRAN_WINDOW = ?";
try {
pstmt = conn.prepareStatement(sqlQuery);
pstmt.setString(1, "w_emp_overtime");
rs= pstmt.executeQuery();
if( rs.next()) {
ediOption = genericUtility.checkNull(rs.getString("EDI_OPTION"));
}else {
return "NORECFND";
}
}catch (Exception e) {
e.printStackTrace();
}finally {
if(rs != null) {rs.close(); rs = null;}
if(pstmt != null) {pstmt.close(); pstmt = null;}
}*/
return errCode;
}
}
package ibase.webitm.ejb.adm.adv;
import javax.ejb.Local;
import ibase.webitm.ejb.ActionHandlerLocal;
@Local
public interface EmpOvertimeConfirmLocal extends ActionHandlerLocal {
public String confirm(String tranId, String xtraParams, String forcedFlag);
}
package ibase.webitm.ejb.adm.adv;
import javax.ejb.Remote;
import ibase.webitm.ejb.ActionHandlerRemote;
@Remote
public interface EmpOvertimeConfirmRemote extends ActionHandlerRemote {
public String confirm(String tranId, String xtraParams, String forcedFlag);
}
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