package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
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.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.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.HrmEmpDepDtlBean;
import wenrgise.hrms.bean.HrmEmpDepHdrBean;
import wenrgise.hrms.vo.HrmEmpDepDtlQVO;

public class HrmEmpDepDtlBO extends HrmBaseBO {
  public HrmEmpDepDtlBO() {}
  
  public HrmEmpDepDtlBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmEmpDepDtlHdrMetaInfo(HrmEmpDepDtlQVO oHrmEmpDepDtlQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oHrmEmpDepDtlQVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(2, 1, 12, oHrmEmpDepDtlQVO.getEmployeeNo()));
    arylstParam.add(new DBObject(3, 2, -5));
    arylstParam.add(new DBObject(4, 2, 93));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMEMPDEPDTL.proc_EmpDepHdrCount(?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTimeObject = oOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    DBObject oTotalRecord = oOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmEmpDepDtlHdrInfo(HrmEmpDepDtlQVO oHrmEmpDepDtlQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    ArrayList oHeaderList = null;
    if (oHrmEmpDepDtlQVO == null)
      oHrmEmpDepDtlQVO = new HrmEmpDepDtlQVO(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    arylstParam.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    arylstParam.add(new DBObject(3, 1, 12, oHrmEmpDepDtlQVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(4, 1, 12, oHrmEmpDepDtlQVO.getEmployeeNo()));
    arylstParam.add(new DBObject(5, 2, -10));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 12));
    arylstParam.add(new DBObject(8, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMEMPDEPDTL.proc_GetEmpDepHdr(?,?,?,?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oHeaderList = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmEmpDepHdrBean oEmployeeDependantDetailsHeader = new HrmEmpDepHdrBean();
      oEmployeeDependantDetailsHeader.setHeaderPrimaryKey(oRow.get("ID").getString());
      oEmployeeDependantDetailsHeader.setEmployeeNo(oRow.get("EMP_NO").getString());
      oEmployeeDependantDetailsHeader.setEmployeeName(oRow.get("EMPNAME").getString());
      oHeaderList.add(oEmployeeDependantDetailsHeader);
    } 
    return oHeaderList;
  }
  
  public RecordMetaInfo getHrmEmpDepDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParam.add(new DBObject(2, 2, -5));
    arylstParam.add(new DBObject(3, 2, 93));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMEMPDEPDTL.proc_EmpDepDtlCount(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = oOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = oOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmEmpDepDtlInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList oHrmEmpDepDtlsDetail = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    arylstParam.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    arylstParam.add(new DBObject(3, 1, 12, lPrimaryKey));
    arylstParam.add(new DBObject(4, 2, -10));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMEMPDEPDTL.proc_GetEmpDepDtl(?,?,?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oHrmEmpDepDtlsDetail = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmEmpDepDtlBean oEmployeeDependantDetailsDtlBean = new HrmEmpDepDtlBean();
      oEmployeeDependantDetailsDtlBean.setDetailId(oRow.get("ID").getString());
      oEmployeeDependantDetailsDtlBean.setTxtRelationTypeId(oRow.get("reltn_mst_id").getString());
      oEmployeeDependantDetailsDtlBean.setTxtRelationType(oRow.get("NAME").getString());
      oEmployeeDependantDetailsDtlBean.setTxtDepName(oRow.get("DEPD_NAME").getString());
      oEmployeeDependantDetailsDtlBean.setTxtSex(oRow.get("SEX").getString());
      oEmployeeDependantDetailsDtlBean.setTxtDOB(EnrgiseUtil.convertToString(oRow.get("DOB").getDate()));
      oEmployeeDependantDetailsDtlBean.setTxtOrgName(oRow.get("ORGANISATION_NAME").getString());
      oEmployeeDependantDetailsDtlBean.setTxtIncomeAmount(oRow.get("INCOME_AMOUNT").getString());
      oHrmEmpDepDtlsDetail.add(oEmployeeDependantDetailsDtlBean);
    } 
    return oHrmEmpDepDtlsDetail;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_EMP_PERS";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmEmpDepDtl"))
      saveHrmEmpDependantDtl(sHeaderPrimaryKey, oDetailBeanArray); 
  }
  
  private void saveHrmEmpDependantDtl(String sHeaderPrimaryKey, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator oIt = oDetailBeanArray.iterator();
    while (oIt.hasNext()) {
      HrmEmpDepDtlBean oHrmEmpDepDtlBean = oIt.next();
      if (oHrmEmpDepDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMEMPDEPDTL.proc_UpsertHrEmpDepDtl(?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "I"));
        arylstParam.add(new DBObject(2, 1, 12, null));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmEmpDepDtlBean.getTxtRelationTypeId()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmEmpDepDtlBean.getTxtDepName()));
        arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpDepDtlBean.getTxtDOB())));
        arylstParam.add(new DBObject(7, 1, 12, oHrmEmpDepDtlBean.getTxtSex()));
        arylstParam.add(new DBObject(8, 1, 12, oHrmEmpDepDtlBean.getTxtOrgName()));
        arylstParam.add(new DBObject(9, 1, 12, oHrmEmpDepDtlBean.getTxtIncomeAmount()));
        arylstParam.add(new DBObject(10, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParam.add(new DBObject(11, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmEmpDepDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMEMPDEPDTL.proc_UpsertHrEmpDepDtl(?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "U"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmEmpDepDtlBean.getDetailId()));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmEmpDepDtlBean.getTxtRelationTypeId()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmEmpDepDtlBean.getTxtDepName()));
        arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpDepDtlBean.getTxtDOB())));
        arylstParam.add(new DBObject(7, 1, 12, oHrmEmpDepDtlBean.getTxtSex()));
        arylstParam.add(new DBObject(8, 1, 12, oHrmEmpDepDtlBean.getTxtOrgName()));
        arylstParam.add(new DBObject(9, 1, 12, oHrmEmpDepDtlBean.getTxtIncomeAmount()));
        arylstParam.add(new DBObject(10, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParam.add(new DBObject(11, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmEmpDepDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMEMPDEPDTL.proc_DeleteEmpDepDtl(?)");
          bDelete = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, oHrmEmpDepDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParam);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return new String();
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String param1) 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 additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oList = new ArrayList();
    ArrayList arylstErrorList = new ArrayList();
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        if (sScreenName.equalsIgnoreCase("HrmEmpDepDtl")) {
          Iterator oIt1 = oDetailBeanArray.iterator();
          int rowCount = 1;
          while (oIt1.hasNext()) {
            HrmEmpDepDtlBean oHrmEmpDepDtlBean = oIt1.next();
            if (!oHrmEmpDepDtlBean.getStatus().equalsIgnoreCase("D"))
              checkMandatoryDepDtlsDtls(oHrmEmpDepDtlBean, rowCount, arylstErrorList); 
            rowCount++;
          } 
        }   
  }
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    HrmEmpDepHdrBean oHrmEmpDepHdrBean = (HrmEmpDepHdrBean)oBaseHeaderBean;
    ArrayList oList = new ArrayList();
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmEmpDepDtl")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int count = 0;
        int countF = 0;
        int countM = 0;
        int countW = 0;
        int countH = 0;
        while (oIt1.hasNext()) {
          HrmEmpDepDtlBean oHrmEmpDepDtlBean = oIt1.next();
          if (!oHrmEmpDepDtlBean.getStatus().equalsIgnoreCase("D")) {
            String sRelType = oHrmEmpDepDtlBean.getTxtRelationType();
            if (sRelType.equalsIgnoreCase("FATHER")) {
              countF++;
              if (countF >= 2)
                oList.add(new EnrgiseApplicationException("wenrgise.empDepDtl.father")); 
              continue;
            } 
            if (sRelType.equalsIgnoreCase("MOTHER")) {
              countM++;
              if (countM >= 2)
                oList.add(new EnrgiseApplicationException("wenrgise.empDepDtl.mother")); 
              continue;
            } 
            if (sRelType.equalsIgnoreCase("WIFE")) {
              countW++;
              if (countW >= 2)
                oList.add(new EnrgiseApplicationException("wenrgise.empDepDtl.wife")); 
              continue;
            } 
            if (sRelType.equalsIgnoreCase("HUSBAND")) {
              countH++;
              if (countH >= 2)
                oList.add(new EnrgiseApplicationException("wenrgise.empDepDtl.husband")); 
            } 
          } 
        } 
      }  
    reportError(oList);
  }
  
  private void checkMandatoryDepDtlsDtls(HrmEmpDepDtlBean oHrmEmpDepDtlBean, int iCount, ArrayList arylstErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmEmpDepDtlBean.getTxtRelationType())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmployeeDependantDetails.relationType");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpDepDtlBean.getTxtDepName())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmployeeDependantDetails.depName");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpDepDtlBean.getTxtSex())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmployeeDependantDetails.sex");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpDepDtlBean.getTxtDOB())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmployeeDependantDetails.DOB");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    DateUtility d = new DateUtility();
    System.out.println(d.getSysDate());
    HrmCommonBO oBO = new HrmCommonBO();
    String sysDate = oBO.getddmmmyyyyDateFormat(d.getSysDate());
    int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmEmpDepDtlBean.getTxtDOB(), sysDate);
    if (dateFlag == 1 && dateFlag != -2)
      arylstErrorList.add(new EnrgiseApplicationException("wenrgise.dateOfBirth.dateConstraintViolated")); 
    reportError(arylstErrorList);
  }
  
  public LovVO getHrmEmpDepDtlEmpNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmEmployeeDependantDetails.employeeNo");
    arylstHeaderList.add("hrm.HrmEmployeeDependantDetails.employeeName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = 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(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParam.add(new DBObject(3, 2, -10));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMEMPDEPDTL.procGetDepDtlsEmpLOV(?,?,?,?,?,?)");
    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("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("EMPNAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmEmpDepDtlRelTypeLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("ID");
    oHeaderList.add("hrm.HrmEmployeeDependantDetails.code");
    oHeaderList.add("hrm.HrmEmployeeDependantDetails.relationType");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = 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(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParam.add(new DBObject(3, 2, -10));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 4));
    ArrayList oOutArray = oBean.callProc(arylstParam, "HRMEMPDEPDTL.proc_GetHrmRelationTypeLOVdata(?,?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = oList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        oList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("CODE").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
}
