package wenrgise.hrms.ejb.business;

import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.bean.LOVBean;
import wenrgise.common.ejb.business.HrmCommonBO;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseMessageKeyException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.DateUtility;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.MessageKey;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.utility.UserInfo;
import wenrgise.common.utility.WorkFlowServiceLocator;
import wenrgise.common.vo.BaseHeaderVO;
import wenrgise.common.vo.LovQueryVO;
import wenrgise.common.vo.LovVO;
import wenrgise.ejb.common.helper.DBObject;
import wenrgise.ejb.common.helper.QueryRow;
import wenrgise.ejb.common.utility.DBUtilitiesBean;
import wenrgise.hrms.bean.HrmDeputationApplicationHdrBean;
import wenrgise.hrms.vo.HrmATDDptnApplQVO;
import wenrgise.workflow.bean.WflAuthorizationBean;
import wenrgise.workflow.core.WflDocumentInfo;
import wenrgise.workflow.core.WflResource;
import wenrgise.workflow.core.WflSite;
import wenrgise.workflow.core.WflStatus;
import wenrgise.workflow.core.impl.WflDocumentInfoImpl;
import wenrgise.workflow.core.impl.WflResourceImpl;
import wenrgise.workflow.core.impl.WflSiteImpl;
import wenrgise.workflow.ejb.facade.WorkFlowFacade;
import wenrgise.workflow.ejb.facade.WorkFlowFacadeHome;

public class HrmATDDptnApplBO extends HrmBaseBO {
  public HrmATDDptnApplBO() {}
  
  public HrmATDDptnApplBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmEmpDeputAppHdrMetaInfo(HrmATDDptnApplQVO oHrmATDDptnApplQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int iCount = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, oHrmATDDptnApplQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmATDDptnApplQVO.getEmployeeNo()));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmATDDptnApplQVO.getApplnNo()));
    arylstParameters.add(new DBObject(4, 2, -5));
    arylstParameters.add(new DBObject(5, 2, 93));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 12));
    arylstParameters.add(new DBObject(8, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMEMPDEPUTAPP.proc_GetHrEmpDeputAppHdrCount(?,?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmEmpDeputAppHeaderInfo(HrmATDDptnApplQVO oHrmATDDptnApplQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int iCount = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    ArrayList arylstHeaderList = null;
    if (oHrmATDDptnApplQVO == null)
      oHrmATDDptnApplQVO = new HrmATDDptnApplQVO(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmATDDptnApplQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmATDDptnApplQVO.getEmployeeNo()));
    arylstParameters.add(new DBObject(5, 1, 12, oHrmATDDptnApplQVO.getApplnNo()));
    arylstParameters.add(new DBObject(6, 2, -10));
    arylstParameters.add(new DBObject(7, 2, 12));
    arylstParameters.add(new DBObject(8, 2, 12));
    arylstParameters.add(new DBObject(9, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMEMPDEPUTAPP.proc_GetHrEmpDeputAppHdr(?,?,?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator oIt = arylstList.iterator();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (oIt.hasNext()) {
      if (iCount == 0)
        arylstHeaderList = new ArrayList(); 
      iCount++;
      oRow = oIt.next();
      HrmDeputationApplicationHdrBean oDeputApplnHeader = new HrmDeputationApplicationHdrBean();
      oDeputApplnHeader.setHeaderPrimaryKey(oRow.get("ID").getString());
      oDeputApplnHeader.setApplnNo(oRow.get("APPLICATION_NO").getString());
      oDeputApplnHeader.setDeputType(oRow.get("DEPUT_TYPE").getString());
      oDeputApplnHeader.setEmployeeNo(oRow.get("EMP_NO").getString());
      oDeputApplnHeader.setEmployeeNoId(oRow.get("E_PER_DTL_ID").getString());
      oDeputApplnHeader.setEmpName(oRow.get("EMPNAME").getString());
      oDeputApplnHeader.setAdvtNo(oRow.get("ADVT_NO").getString());
      oDeputApplnHeader.setSelfOfficeFlag(oRow.get("SELF_OFFICE_FLAG").getString());
      oDeputApplnHeader.setApplnDate(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oDeputApplnHeader.setAdvtDate(EnrgiseUtil.convertToString(oRow.get("ADVT_DATE").getDate()));
      oDeputApplnHeader.setOrgName(oRow.get("ORG_NAME").getString());
      oDeputApplnHeader.setPostId(oRow.get("DEPUT_POST_ID").getString());
      oDeputApplnHeader.setPostCode(oRow.get("POST_CODE").getString());
      oDeputApplnHeader.setPostName(oRow.get("POST_NAME").getString());
      oDeputApplnHeader.setReason(oRow.get("REASON").getString());
      oDeputApplnHeader.setDeputStatus(oRow.get("APPROVED_FLAG").getString());
      arylstHeaderList.add(oDeputApplnHeader);
    } 
    return arylstHeaderList;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_EMP_DEPUT_APPL";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {}
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return new String();
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalBusinessValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public LovVO getHrmDeputApplnNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmDeputationApplicn.applnNo");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int iCount = 0;
    String sQuerySearch2 = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMDEPTNLOV.proc_GetHrmDeputApplnLOVdata(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (iCount == 0)
        arylstList = new ArrayList(); 
      iCount++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("APPLICATION_NO").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmDeputEmpNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmDeputationApplicn.employeeNo");
    arylstHeaderList.add("hrm.HrmDeputationApplicn.empName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int iCount = 0;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMDEPTNLOV.proc_GetHrmDeputEmpNoILOVdata(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (iCount == 0)
        arylstList = new ArrayList(); 
      iCount++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("EMPNAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmDeputEmpNoQLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmDeputationApplicn.employeeNo");
    arylstHeaderList.add("hrm.HrmDeputationApplicn.empName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int iCount = 0;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMDEPTNLOV.proc_GetHrmDeputEmpNoQLOVdata(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (iCount == 0)
        arylstList = new ArrayList(); 
      iCount++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("EMPNAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmDeputAdvtNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmDeputationApplicn.advtNo");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int iCount = 0;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 2, -10));
    arylstParameters.add(new DBObject(3, 2, 12));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMDEPTNLOV.proc_GetHrmDeputAdvtLOVdata(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (iCount == 0)
        arylstList = new ArrayList(); 
      iCount++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("ADVT_NO").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmDeputPostNameLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmDeputationApplicn.postCode");
    arylstHeaderList.add("hrm.HrmDeputationApplicn.postName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int iCount = 0;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMDEPTNLOV.proc_GetHrmDeputPostLOVdata(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (iCount == 0)
        arylstList = new ArrayList(); 
      iCount++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("CODE").getString());
      oLOVBean.setDetailField3(oRow.get("DESCRIPTION").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmDeputationApplicationHdrBean oHrmDeputApplnHdrBean = (HrmDeputationApplicationHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, "N"));
      arylstParameters.add(new DBObject(2, 1, 12, oHrmDeputApplnHdrBean.getEmployeeNoId()));
      arylstParameters.add(new DBObject(3, 1, 12, oHrmDeputApplnHdrBean.getApplnNo()));
      arylstParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmDeputApplnHdrBean.getApplnDate())));
      arylstParameters.add(new DBObject(5, 1, 12, oHrmDeputApplnHdrBean.getDeputType()));
      arylstParameters.add(new DBObject(6, 1, 12, "A"));
      arylstParameters.add(new DBObject(7, 1, 12, oHrmDeputApplnHdrBean.getAdvtNo()));
      arylstParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmDeputApplnHdrBean.getAdvtDate())));
      arylstParameters.add(new DBObject(9, 1, 12, oHrmDeputApplnHdrBean.getOrgName()));
      arylstParameters.add(new DBObject(10, 1, 12, oHrmDeputApplnHdrBean.getPostCode()));
      arylstParameters.add(new DBObject(11, 1, 12, oHrmDeputApplnHdrBean.getPostName()));
      arylstParameters.add(new DBObject(12, 1, 12, oHrmDeputApplnHdrBean.getReason()));
      arylstParameters.add(new DBObject(13, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParameters.add(new DBObject(14, 1, 12, this.oUserInfo.getSiteId()));
      arylstParameters.add(new DBObject(15, 1, 12, null));
      arylstParameters.add(new DBObject(16, 2, 12));
      arylstParameters.add(new DBObject(17, 2, 12));
      arylstParameters.add(new DBObject(18, 2, 12));
      arylstParameters.add(new DBObject(19, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMEMPDEPUTAPP.proc_UpsertHrDeputAppHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, "U"));
      arylstParameters.add(new DBObject(2, 1, 12, oHrmDeputApplnHdrBean.getEmployeeNoId()));
      arylstParameters.add(new DBObject(3, 1, 12, oHrmDeputApplnHdrBean.getApplnNo()));
      arylstParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmDeputApplnHdrBean.getApplnDate())));
      arylstParameters.add(new DBObject(5, 1, 12, oHrmDeputApplnHdrBean.getDeputType()));
      arylstParameters.add(new DBObject(6, 1, 12, oHrmDeputApplnHdrBean.getDeputStatus()));
      arylstParameters.add(new DBObject(7, 1, 12, oHrmDeputApplnHdrBean.getAdvtNo()));
      arylstParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmDeputApplnHdrBean.getAdvtDate())));
      arylstParameters.add(new DBObject(9, 1, 12, oHrmDeputApplnHdrBean.getOrgName()));
      arylstParameters.add(new DBObject(10, 1, 12, oHrmDeputApplnHdrBean.getPostCode()));
      arylstParameters.add(new DBObject(11, 1, 12, oHrmDeputApplnHdrBean.getPostName()));
      arylstParameters.add(new DBObject(12, 1, 12, oHrmDeputApplnHdrBean.getReason()));
      arylstParameters.add(new DBObject(13, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParameters.add(new DBObject(14, 1, 12, this.oUserInfo.getSiteId()));
      arylstParameters.add(new DBObject(15, 1, 12, oHrmDeputApplnHdrBean.getHeaderPrimaryKey()));
      arylstParameters.add(new DBObject(16, 2, 12));
      arylstParameters.add(new DBObject(17, 2, 12));
      arylstParameters.add(new DBObject(18, 2, 12));
      arylstParameters.add(new DBObject(19, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMEMPDEPUTAPP.proc_UpsertHrDeputAppHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("D")) {
      arylstParameters.add(new DBObject(1, 1, 12, oHrmDeputApplnHdrBean.getHeaderPrimaryKey()));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMEMPDEPUTAPP.proc_DeleteHrmEmpDeputAppHdr(?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = null;
    } 
    return returnString;
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrorList = new ArrayList();
    HrmDeputationApplicationHdrBean oHrmDeputApplnHdrBean = (HrmDeputationApplicationHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged) {
      if (!sScreenMode.equalsIgnoreCase("D")) {
        checkMandatoryHeader((HrmDeputationApplicationHdrBean)oBaseHeaderBean);
        checkHeaderFields((HrmDeputationApplicationHdrBean)oBaseHeaderBean);
        if (sScreenMode.equalsIgnoreCase("N"));
      } 
      if (sScreenMode.equalsIgnoreCase("D")) {
        HrmCommonBO oCommonBO = new HrmCommonBO();
        String sRefId = oCommonBO.getRefList("HRM_EMP_DEPUT_ORDER_DTL", "DEPUT_APPL_ID ", oHrmDeputApplnHdrBean.getHeaderPrimaryKey(), "ID");
        if (EnrgiseUtil.checkString(sRefId))
          oErrorList.add(new EnrgiseApplicationException("wenrgise.common.deletion")); 
        if (!oHrmDeputApplnHdrBean.getDeputStatus().equalsIgnoreCase("N"))
          if (oErrorList.isEmpty())
            oErrorList.add(new EnrgiseApplicationException("wenrgise.common.deletion.rejected"));  
      } 
    } 
    reportError(oErrorList);
  }
  
  private void checkMandatoryHeader(HrmDeputationApplicationHdrBean oHrmDeputationApplicationHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getApplnNo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmDeputationApplicn.applnNo");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getApplnDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmDeputationApplicn.applnDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getDeputType())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmDeputationApplicn.deputType");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getReason())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmDeputationApplicn.reason");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getEmployeeNo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmDeputationApplicn.employeeNo");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (oHrmDeputationApplicationHdrBean.getDeputType().equalsIgnoreCase("F") || oHrmDeputationApplicationHdrBean.getDeputType().equalsIgnoreCase("O"))
      if (!EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getOrgName())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmDeputationApplicn.orgName");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
      }  
    if (!oHrmDeputationApplicationHdrBean.getAdvtNo().equalsIgnoreCase(null))
      if (!EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getAdvtDate())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmDeputationApplicn.advtDate");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
      }  
    reportError(oErrorList);
  }
  
  private void checkHeaderFields(HrmDeputationApplicationHdrBean oHrmDeputApplnHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList arylstList1 = new ArrayList();
    if (!oHrmDeputApplnHdrBean.getDeputType().equalsIgnoreCase("W"))
      if (!EnrgiseUtil.checkString(oHrmDeputApplnHdrBean.getOrgName()))
        arylstList1.add(new EnrgiseApplicationException("wenrgise.common.header.mandatoryfieldmissing"));  
    reportError(arylstList1);
    if (EnrgiseUtil.checkString(oHrmDeputApplnHdrBean.getAdvtNo()))
      if (!EnrgiseUtil.checkString(oHrmDeputApplnHdrBean.getAdvtDate()))
        arylstList1.add(new EnrgiseApplicationException("wenrgise.common.header.mandatoryfieldmissing"));  
    reportError(arylstList1);
  }
  
  public String submitDeputAppln(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    HrmDeputationApplicationHdrBean oHrmDeputationApplicationHdrBean = (HrmDeputationApplicationHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    if (!EnrgiseUtil.checkString(oBaseHeaderBean.getWorkListId())) {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", "Initiated");
    } else {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", (String)null);
    } 
    if (status.getStatus().equalsIgnoreCase("Pending")) {
      oBean = new DBUtilitiesBean();
      ArrayList arylstParameters = new ArrayList();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMEMPDEPUTAPP.procSubmitDeputAppln(?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  public String approveDeputAppln(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    HrmDeputationApplicationHdrBean oHrmDeputationApplicationHdrBean = (HrmDeputationApplicationHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    if (!EnrgiseUtil.checkString(oBaseHeaderBean.getWorkListId())) {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", "Initiated");
    } else {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", (String)null);
    } 
    if (status.getStatus().equalsIgnoreCase("FinallyApproved")) {
      oBean = new DBUtilitiesBean();
      ArrayList arylstParameters = new ArrayList();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMEMPDEPUTAPP.procApproveDeputAppln(?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  public String rejectDeputAppln(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    HrmDeputationApplicationHdrBean oHrmDeputationApplicationHdrBean = (HrmDeputationApplicationHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    if (!EnrgiseUtil.checkString(oBaseHeaderBean.getWorkListId())) {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Reject", "Initiated");
    } else {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Reject", (String)null);
    } 
    if (status.getStatus().equalsIgnoreCase("Rejected")) {
      oBean = new DBUtilitiesBean();
      ArrayList arylstParameters = new ArrayList();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMEMPDEPUTAPP.procRejectDeputAppln(?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  public WflStatus callWorkFlow(BaseHeaderBean oBaseHeaderBean, ArrayList arylstDetailBeanArray, String activity, String initiatedFlag) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      WorkFlowFacadeHome oHome = (WorkFlowFacadeHome)WorkFlowServiceLocator.getLocator().getService("WorkFlowFacade");
      WorkFlowFacade workFlowFacade = oHome.create();
      HrmDeputationApplicationHdrBean oHrmDeputationApplicationHdrBean = (HrmDeputationApplicationHdrBean)oBaseHeaderBean;
      WflResourceImpl wflResourceImpl = new WflResourceImpl();
      wflResourceImpl.setEmployeeId(this.oUserInfo.getUserTypeId());
      WflSiteImpl wflSiteImpl = new WflSiteImpl();
      wflSiteImpl.setSiteId(this.oUserInfo.getSiteId());
      wflResourceImpl.setLoginSite((WflSite)wflSiteImpl);
      WflDocumentInfoImpl wflDocumentInfoImpl = new WflDocumentInfoImpl();
      wflDocumentInfoImpl.setRequester((WflResource)wflResourceImpl);
      wflDocumentInfoImpl.setDocumentId(oHrmDeputationApplicationHdrBean.getHeaderPrimaryKey());
      wflDocumentInfoImpl.setDocumentType("Deputation");
      wflDocumentInfoImpl.setInitiatedFlag(initiatedFlag);
      String documentTypeId = workFlowFacade.getDocumentTypeId("DeputationAppln");
      if (documentTypeId == null)
        throw new EnrgiseSystemException(); 
      if (!EnrgiseUtil.checkString(initiatedFlag))
        wflDocumentInfoImpl.setWorkListId(oBaseHeaderBean.getWorkListId()); 
      String activityId = workFlowFacade.getActivityId(activity);
      if (activityId == null)
        throw new EnrgiseSystemException(); 
      wflDocumentInfoImpl.setDocumentTypeId(documentTypeId);
      if (!activity.equalsIgnoreCase("Reject")) {
        wflDocumentInfoImpl.setDocumentNumber(String.valueOf(String.valueOf("Deputation Application No:").concat(String.valueOf(oHrmDeputationApplicationHdrBean.getHeaderPrimaryKey()))).concat(String.valueOf("is pending for approval")));
        wflDocumentInfoImpl.setDocDesc(String.valueOf("The following document has been pending for approval:Training Requirement:").concat(String.valueOf(oHrmDeputationApplicationHdrBean.getHeaderPrimaryKey())));
      } else if (!activity.equalsIgnoreCase("Approve")) {
        wflDocumentInfoImpl.setDocumentNumber(String.valueOf(String.valueOf("Deputation Application No:").concat(String.valueOf(oHrmDeputationApplicationHdrBean.getHeaderPrimaryKey()))).concat(String.valueOf("is pending for rejection")));
        wflDocumentInfoImpl.setDocDesc(String.valueOf("The following document has been pending for rejection:Deputation Application No:").concat(String.valueOf(oHrmDeputationApplicationHdrBean.getHeaderPrimaryKey())));
      } 
      wflDocumentInfoImpl.setModuleId("8");
      wflDocumentInfoImpl.setCreator((WflResource)wflResourceImpl);
      wflDocumentInfoImpl.setRequesterAction(activityId);
      HashMap oProp = new HashMap();
      oProp.put("1", "1");
      wflDocumentInfoImpl.setDocumentAttributes(oProp);
      WflAuthorizationBean wflAuthBean = workFlowFacade.canDo((WflDocumentInfo)wflDocumentInfoImpl);
      if (EnrgiseUtil.checkString(wflAuthBean.getErrorCode()))
        throw new EnrgiseApplicationException(wflAuthBean.getErrorCode()); 
      if (!wflAuthBean.isAuthStatus())
        throw new EnrgiseApplicationException("wenrgise.workflow.submit.notauthorized"); 
      WflStatus wflStatus = workFlowFacade.process((WflDocumentInfo)wflDocumentInfoImpl);
      if (wflStatus.getStatus().equals("Error"))
        throw new EnrgiseSystemException(); 
      workFlowFacade.remove();
      return wflStatus;
    } catch (RemoteException oRtEx) {
      throw new EnrgiseSystemException("wenrgise.workflow.connect", oRtEx);
    } catch (CreateException oCx) {
      throw new EnrgiseSystemException("wenrgise.workflow.connect", oCx);
    } catch (RemoveException oRx) {
      throw new EnrgiseSystemException("wenrgise.workflow.connect", oRx);
    } 
  }
}
