package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.bean.LOVBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseMessageKeyException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.utility.UserInfo;
import wenrgise.common.vo.BaseDetailVO;
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.helper.QueryValue;
import wenrgise.ejb.common.utility.DBUtilitiesBean;
import wenrgise.hrms.bean.HrmSepClrEmpDtlBean;
import wenrgise.hrms.bean.HrmSepClrEmpHdrBean;
import wenrgise.hrms.vo.HrmSepClrEmpQVO;

public class HrmSepClrEmpBO extends HrmBaseBO {
  public HrmSepClrEmpBO() {}
  
  public HrmSepClrEmpBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmSepClrEmpHdrMetaInfo(HrmSepClrEmpQVO oHrmSepClrEmpQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, oHrmSepClrEmpQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmSepClrEmpQVO.getEmpNoId()));
    arylstParameters.add(new DBObject(3, 2, -5));
    arylstParameters.add(new DBObject(4, 2, 93));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLREMP.proc_GetSepClrEmpHdrCount(?,?,?,?,?,?,?)");
    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 getHrmSepClrEmpHeaderInfo(HrmSepClrEmpQVO oHrmSepClrEmpQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    HrmSepClrEmpHdrBean oHeaderBean = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    ArrayList arylstHeaderList = new ArrayList();
    String sEmpNo = oHrmSepClrEmpQVO.getEmpNo();
    if (oHrmSepClrEmpQVO == null)
      oHrmSepClrEmpQVO = new HrmSepClrEmpQVO(); 
    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, oHrmSepClrEmpQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmSepClrEmpQVO.getEmpNoId()));
    arylstParameters.add(new DBObject(5, 2, -10));
    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, "HRMSEPCLREMP.proc_GetSepClrEmpHdr(?,?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHeaderList = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      oHeaderBean = new HrmSepClrEmpHdrBean();
      oHeaderBean.setTmplDescId(oRow.get("ID").getString());
      oHeaderBean.setTmplDesc(oRow.get("tmpl_description").getString());
      oHeaderBean.setEmpNoId(oRow.get("emp_id").getString());
      oHeaderBean.setEmpNo(oRow.get("emp_no").getString());
      oHeaderBean.setHeaderPrimaryKey(oRow.get("emp_id").getString());
      arylstHeaderList.add(oHeaderBean);
    } 
    return arylstHeaderList;
  }
  
  public RecordMetaInfo getHrmSepClrEmpDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    if (lPrimaryKey == null)
      return null; 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(2, 2, -5));
    arylstParameters.add(new DBObject(3, 2, 93));
    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, "HRMSEPCLREMP.proc_GetSepClrEmpDtlCount(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmSepClrEmpDetailInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstDetailBean = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLREMP.proc_GetSepClrEmpDtl(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstDetailBean = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmSepClrEmpDtlBean oDetailBean = new HrmSepClrEmpDtlBean();
      oDetailBean.setDetailId(oRow.get("ID").getString());
      oDetailBean.setTxtClrDesc(oRow.get("clr_desc").getString());
      String sCheckFlag = oRow.get("clr_flag").getString().equals("Y") ? "on" : "off";
      oDetailBean.setTxtCheckFlag(sCheckFlag);
      oDetailBean.setTxtComment(oRow.get("reason").getString());
      arylstDetailBean.add(oDetailBean);
    } 
    return arylstDetailBean;
  }
  
  public LovVO getTmplLOV(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmSepClrEmp.txtClrDesc");
    arylstHeaderList.add("hrm.HrmSepClrEmp.obsoleteFlag");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 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(); 
    String sEmpId = oLovQueryVO.getProperty("empId");
    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, "HRMSEPCLREMP.proc_GetTmplDescLOV(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("TMPL_DESCRIPTION").getString());
      oLOVBean.setDetailField3(oRow.get("OBSOLETE_FLAG").getString());
      oLOVBean.setDetailField4(oRow.get("ELIG_SQL").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getEmpNoLOVQ(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add(" ");
    arylstHeaderList.add("hrm.HrmSepClrEmp.empNo");
    arylstHeaderList.add("hrm.HrmSepClrEmp.empName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 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, "HRMSEPCLREMP.proc_GetEmpNoLOVQ(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("EMP_ID").getString());
      oLOVBean.setDetailField2(oRow.get("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("EMP_NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getEmpNoLOVN(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add(" ");
    arylstHeaderList.add("hrm.HrmSepClrEmp.empNo");
    arylstHeaderList.add("hrm.HrmSepClrEmp.empName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 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, "HRMSEPCLREMP.proc_GetEmpNoLOVN(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("EMP_ID").getString());
      oLOVBean.setDetailField2(oRow.get("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("EMP_NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_SEP_TMPL_HDR";
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    HrmSepClrEmpHdrBean oHrmSepClrEmpHdrBean = (HrmSepClrEmpHdrBean)oBaseHeaderBean;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    ArrayList arylstClrList = getClrList(oHrmSepClrEmpHdrBean.getTmplDescId());
    oBean.createBatch("HRMSEPCLREMP.proc_UpsertSepClrEmpHdr(?,?,?,?)");
    Iterator itrBean = arylstClrList.iterator();
    while (itrBean.hasNext()) {
      arylstParameters.add(new DBObject(1, 1, 12, oHrmSepClrEmpHdrBean.getEmpNoId()));
      String sClrId = itrBean.next();
      arylstParameters.add(new DBObject(2, 1, 12, sClrId));
      arylstParameters.add(new DBObject(3, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParameters.add(new DBObject(4, 1, 12, this.oUserInfo.getSiteId()));
      oBean.addToBatch(arylstParameters);
    } 
    oBean.executeBatch();
    HrmSepClrEmpHdrBean oHeaderBean = new HrmSepClrEmpHdrBean();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add(oHrmSepClrEmpHdrBean);
    return oHrmSepClrEmpHdrBean.getEmpNoId();
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmSepClrEmp"))
      saveHrmSepClrEmpDetail(sHeaderPrimaryKey, arylstDetailBeanArray); 
  }
  
  private void saveHrmSepClrEmpDetail(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DBUtilitiesBean oBean1 = null;
    oBean.createBatch("HRMSEPCLREMP.proc_UpsertSepClrEmpDtl(?,?,?)");
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmSepClrEmpDtlBean oHrmSepClrEmpDtlBean = itrBean.next();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, oHrmSepClrEmpDtlBean.getDetailId()));
      String sCheckFlag = oHrmSepClrEmpDtlBean.getTxtCheckFlag().equals("on") ? "Y" : "N";
      arylstParameters.add(new DBObject(2, 1, 12, sCheckFlag));
      arylstParameters.add(new DBObject(3, 1, 12, oHrmSepClrEmpDtlBean.getTxtComment()));
      oBean.addToBatch(arylstParameters);
    } 
    oBean.executeBatch();
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return null;
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmSepClrEmpHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmSepClrEmp")) {
        Iterator itrBean1 = arylstDetailBeanArray.iterator();
        int iCount = 1;
        while (itrBean1.hasNext()) {
          HrmSepClrEmpDtlBean oHrmSepClrEmpDtlBean = itrBean1.next();
          if (!oHrmSepClrEmpDtlBean.getStatus().equalsIgnoreCase("D"))
            checkMandatory(oHrmSepClrEmpDtlBean, iCount, arylstErrorList); 
          iCount++;
        } 
      }  
    reportError(arylstErrorList);
  }
  
  private void checkMandatory(HrmSepClrEmpDtlBean oHrmSepClrEmpDtlBean, int iCount, ArrayList arylstErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {}
  
  private void checkMandatoryHeader(HrmSepClrEmpHdrBean oHrmSepClrEmpHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList arylstParam = null;
    ArrayList arylstErrorList = null;
    if (oHrmSepClrEmpHdrBean.getEmpNoId() == null) {
      arylstParam = new ArrayList();
      arylstParam.add(new String("hrm.HrmSepClrEmp.empNo"));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", arylstParam));
    } 
    if (arylstErrorList != null)
      reportError(arylstErrorList); 
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    HrmSepClrEmpHdrBean oHrmSepClrEmpHdrBean = (HrmSepClrEmpHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkUniqueHeader((HrmSepClrEmpHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (sScreenMode.equalsIgnoreCase("N"))
        if (sScreenName.equalsIgnoreCase("HrmSepClrEmp"))
          EnrgiseUtil.checkDuplicate(arylstDetailBeanArray, "txtClrDescId", "hrm.HrmSepClrEmp.txtClrDesc", arylstErrorList, true);   
    reportError(arylstErrorList);
  }
  
  public void checkRefferenceKey(String sSkillHeaderId) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  private void checkUniqueHeader(HrmSepClrEmpHdrBean oHrmSepClrEmpHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  private ArrayList getClrList(String sTmplId) throws EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters.add(new DBObject(1, 1, 12, sTmplId));
    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, "HRMSEPCLREMP.proc_GetClrId(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0);
    Iterator itrClrList = arylstList.iterator();
    ArrayList arylstClrList = new ArrayList();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    int count = 0;
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      arylstClrList.add(oRow.get("CLR_ID").getString());
    } 
    return arylstClrList;
  }
  
  private ArrayList getFilteredLeaveList(ArrayList arylstList, String sEmpId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstNewList = new ArrayList();
    LOVBean oNewLovBean = null;
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Iterator itrList = arylstList.iterator();
    while (itrList.hasNext()) {
      LOVBean oLovBean = itrList.next();
      String sEligSql = oLovBean.getDetailField4();
      StringBuffer sbEligSql = new StringBuffer(sEligSql);
      if (sbEligSql.lastIndexOf("?") != -1) {
        sbEligSql.replace(sbEligSql.lastIndexOf("?"), sbEligSql.lastIndexOf("?") + 1, sEmpId);
        sEligSql = sbEligSql.toString();
        ArrayList arylstOutArray = oBean.executeQuery(sEligSql);
        if (arylstOutArray.size() == 0)
          continue; 
        oNewLovBean = new LOVBean();
        oNewLovBean.setDetailField1(oLovBean.getDetailField1());
        oNewLovBean.setDetailField2(oLovBean.getDetailField2());
        oNewLovBean.setDetailField3(oLovBean.getDetailField3());
        arylstNewList.add(oNewLovBean);
      } 
    } 
    return arylstNewList;
  }
  
  public LovVO getHrmSepEligLOV(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add(" ");
    arylstHeaderList.add("hrm.HrmSepClrEmp.tmplDesc");
    arylstHeaderList.add("hrm.HrmSepClrEmp.obsoleteFlag");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 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, "HRMSEPCLREMP.proc_GetHrmSepEligLOV(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("tmpl_description").getString());
      oLOVBean.setDetailField3(oRow.get("obsolete_flag").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public void updateSeparationEligRule(String sSql, String sId, String sUserId, String sUserSiteId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sSql));
    arylstParam.add(new DBObject(2, 1, 12, sId));
    arylstParam.add(new DBObject(3, 1, 12, sUserId));
    arylstParam.add(new DBObject(4, 1, 12, sUserSiteId));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMSEPCLREMP.proc_UpdateSepTmplHdr(?,?,?,?,?,?,?)");
  }
}
