package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
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.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseMessageKeyException;
import wenrgise.common.exception.EnrgiseSystemException;
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.BaseQueryVO;
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.HrmPrmCriteriaDtlBean;
import wenrgise.hrms.bean.HrmPrmCriteriaHdrBean;
import wenrgise.hrms.bean.HrmTrngEmpAttHdrBean;
import wenrgise.hrms.vo.HrmPrmCriteriaQVO;
import wenrgise.hrms.vo.HrmTrngEmpAttQVO;

public class HrmPrmCriteriaBO extends HrmBaseBO {
  public HrmPrmCriteriaBO() {}
  
  public HrmPrmCriteriaBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmTrngEmpAttHdrMetaInfo(HrmTrngEmpAttQVO oHrmTrngEmpAttQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    String sId = oHrmTrngEmpAttQueryVO.getCourseNameId();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, sId));
    oParameters.add(new DBObject(2, 2, -5));
    oParameters.add(new DBObject(3, 2, 93));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 12));
    oParameters.add(new DBObject(6, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMCRITERIA.proc_HrEmpTrngAttHdrCount(?,?,?,?,?,?)");
    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 getHrmTrngEmpAttHeaderInfo(HrmTrngEmpAttQVO oHrmTrngEmpAttQueryVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    ArrayList oHeaderList = null;
    if (oHrmTrngEmpAttQueryVO == null)
      oHrmTrngEmpAttQueryVO = new HrmTrngEmpAttQVO(); 
    String sId = oHrmTrngEmpAttQueryVO.getCourseNameId();
    String sPK = oHrmTrngEmpAttQueryVO.getHeaderPrimaryKey();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    oParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    oParameters.add(new DBObject(3, 1, 12, sId));
    oParameters.add(new DBObject(4, 1, 12, sPK));
    oParameters.add(new DBObject(5, 2, -10));
    oParameters.add(new DBObject(6, 2, 12));
    oParameters.add(new DBObject(7, 2, 12));
    oParameters.add(new DBObject(8, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMCRITERIA.proc_HrEmpTrngAttHdr(?,?,?,?,?,?,?,?)");
    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();
      HrmTrngEmpAttHdrBean oHrmTrngEmpAttHdrBean = new HrmTrngEmpAttHdrBean();
      oHrmTrngEmpAttHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmTrngEmpAttHdrBean.setCourseName(oRow.get("CRS_NAME").getString());
      oHrmTrngEmpAttHdrBean.setInstitutionName(oRow.get("INST_NAME").getString());
      oHrmTrngEmpAttHdrBean.setStartDate(EnrgiseUtil.convertToString(oRow.get("START_DATE").getDate()));
      oHrmTrngEmpAttHdrBean.setEndDate(EnrgiseUtil.convertToString(oRow.get("END_DATE").getDate()));
      oHeaderList.add(oHrmTrngEmpAttHdrBean);
    } 
    return oHeaderList;
  }
  
  public RecordMetaInfo getHrmPrmCriteriaDetailMetaInfo(BaseQueryVO oBaseQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    HrmPrmCriteriaQVO oQVO = (HrmPrmCriteriaQVO)oBaseQVO;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oQVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(2, 1, 12, oQVO.getToGradeId()));
    oParameters.add(new DBObject(3, 1, 12, oQVO.getFromDesigId()));
    oParameters.add(new DBObject(4, 1, 12, oQVO.getToDesigId()));
    oParameters.add(new DBObject(5, 2, -5));
    oParameters.add(new DBObject(6, 2, 93));
    oParameters.add(new DBObject(7, 2, 12));
    oParameters.add(new DBObject(8, 2, 12));
    oParameters.add(new DBObject(9, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMCRITERIA.proc_PrmCriteriaDtlCount(?,?,?,?,?,?,?,?,?)");
    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 getHrmPrmCriteriaDetailInfo(BaseQueryVO oBaseQVO, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    HrmPrmCriteriaQVO oQVO = (HrmPrmCriteriaQVO)oBaseQVO;
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstDetail = null;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    oParameters.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    oParameters.add(new DBObject(3, 1, 12, oQVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(4, 1, 12, oQVO.getToGradeId()));
    oParameters.add(new DBObject(5, 1, 12, oQVO.getFromDesigId()));
    oParameters.add(new DBObject(6, 1, 12, oQVO.getToDesigId()));
    oParameters.add(new DBObject(7, 2, -10));
    oParameters.add(new DBObject(8, 2, 12));
    oParameters.add(new DBObject(9, 2, 12));
    oParameters.add(new DBObject(10, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMCRITERIA.proc_PrmCriteriaDtl(?,?,?,?,?,?,?,?,?,?)");
    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)
        arylstDetail = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmPrmCriteriaDtlBean oDtlBean = new HrmPrmCriteriaDtlBean();
      oDtlBean.setDetailId(oRow.get("ID").getString());
      oDtlBean.setTxtDescription(oRow.get("description").getString());
      oDtlBean.setTxtCriteriaStartDate(EnrgiseUtil.convertToString(oRow.get("criteria_fr_dt").getDate()));
      oDtlBean.setDisabbutCriteriaEndDate("true");
      oDtlBean.setDisabbutCriteriaStartDate("true");
      oDtlBean.setTxtCriteriaEndDate(EnrgiseUtil.convertToString(oRow.get("criteria_to_dt").getDate()));
      oDtlBean.setTxtMinServicePeriod(oRow.get("min_service_period").getString());
      oDtlBean.setTxtReqYears(oRow.get("years_in_current_post").getString());
      oDtlBean.setTxtYearAPAR(oRow.get("no_of_years_apar").getString());
      arylstDetail.add(oDtlBean);
    } 
    return arylstDetail;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_EMP_TRNG_HDR";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {}
  
  public void saveDetailImpl(BaseHeaderBean oBaseHdrBean, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator oIt = oDetailBeanArray.iterator();
    HrmPrmCriteriaHdrBean oHdrBean = (HrmPrmCriteriaHdrBean)oBaseHdrBean;
    while (oIt.hasNext()) {
      HrmPrmCriteriaDtlBean oDtlBean = oIt.next();
      if (oDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMCRITERIA.proc_UpsertPrmCriteriaDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "N"));
        oParameters.add(new DBObject(2, 1, 12, oHdrBean.getHeaderPrimaryKey()));
        oParameters.add(new DBObject(3, 1, 12, oHdrBean.getToGradeId()));
        oParameters.add(new DBObject(4, 1, 12, oHdrBean.getFromDesigId()));
        oParameters.add(new DBObject(5, 1, 12, oHdrBean.getToDesigId()));
        oParameters.add(new DBObject(6, 1, 12, oDtlBean.getTxtDescription()));
        oParameters.add(new DBObject(7, 1, 12, oDtlBean.getTxtCriteriaStartDate()));
        oParameters.add(new DBObject(8, 1, 12, oDtlBean.getTxtCriteriaEndDate()));
        oParameters.add(new DBObject(9, 1, 12, oDtlBean.getTxtMinServicePeriod()));
        oParameters.add(new DBObject(10, 1, 12, oDtlBean.getTxtReqYears()));
        oParameters.add(new DBObject(11, 1, 12, oDtlBean.getTxtYearAPAR()));
        oParameters.add(new DBObject(12, 1, 12, this.oUserInfo.getUserId()));
        oParameters.add(new DBObject(13, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(14, 1, 12, null));
        oBean.addToBatch(oParameters);
      } 
      if (oDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMCRITERIA.proc_UpsertPrmCriteriaDtl(?,?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "U"));
        oParameters.add(new DBObject(2, 1, 12, oHdrBean.getHeaderPrimaryKey()));
        oParameters.add(new DBObject(3, 1, 12, oHdrBean.getToGradeId()));
        oParameters.add(new DBObject(4, 1, 12, oHdrBean.getFromDesigId()));
        oParameters.add(new DBObject(5, 1, 12, oHdrBean.getToDesigId()));
        oParameters.add(new DBObject(6, 1, 12, oDtlBean.getTxtDescription()));
        oParameters.add(new DBObject(7, 1, 12, oDtlBean.getTxtCriteriaStartDate()));
        oParameters.add(new DBObject(8, 1, 12, oDtlBean.getTxtCriteriaEndDate()));
        oParameters.add(new DBObject(9, 1, 12, oDtlBean.getTxtMinServicePeriod()));
        oParameters.add(new DBObject(10, 1, 12, oDtlBean.getTxtReqYears()));
        oParameters.add(new DBObject(11, 1, 12, oDtlBean.getTxtYearAPAR()));
        oParameters.add(new DBObject(12, 1, 12, this.oUserInfo.getUserId()));
        oParameters.add(new DBObject(13, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(14, 1, 12, oDtlBean.getDetailId()));
        oBean.addToBatch(oParameters);
      } 
      if (oDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMCRITERIA.proc_DeletePrmCriteriaDtl(?)");
          bDelete = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, oDtlBean.getDetailId()));
        oBean.addToBatch(oParameters);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean.executeBatch(); 
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "!";
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp param2, String param3, String param4, boolean param5, ArrayList oDtlBeanArray, boolean param7, Timestamp param8) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList arylstErrorList = new ArrayList();
    int iCount = 0;
    checkMandatoryHeader((HrmPrmCriteriaHdrBean)oBaseHeaderBean, arylstErrorList);
    Iterator itrDtlBean = oDtlBeanArray.iterator();
    while (itrDtlBean.hasNext()) {
      iCount++;
      HrmPrmCriteriaDtlBean oDtlBean = itrDtlBean.next();
      if (!oDtlBean.getStatus().equals("D")) {
        if (!EnrgiseUtil.checkString(oDtlBean.getTxtCriteriaStartDate())) {
          MessageKey oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtCriteriaStartDate");
          ArrayList arylstParams = new ArrayList();
          arylstParams.add(oMessageKey);
          arylstParams.add(new Integer(iCount));
          arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", arylstParams, "E"));
        } 
        if (!EnrgiseUtil.checkString(oDtlBean.getTxtReqYears())) {
          MessageKey oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtReqYears");
          ArrayList arylstParams = new ArrayList();
          arylstParams.add(oMessageKey);
          arylstParams.add(new Integer(iCount));
          arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", arylstParams, "E"));
        } 
        if (!EnrgiseUtil.checkString(oDtlBean.getTxtYearAPAR())) {
          MessageKey oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtYearAPAR");
          ArrayList arylstParams = new ArrayList();
          arylstParams.add(oMessageKey);
          arylstParams.add(new Integer(iCount));
          arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", arylstParams, "E"));
        } 
        if (!EnrgiseUtil.checkString(oDtlBean.getTxtDescription())) {
          MessageKey oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtDescription");
          ArrayList arylstParams = new ArrayList();
          arylstParams.add(oMessageKey);
          arylstParams.add(new Integer(iCount));
          arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", arylstParams, "E"));
        } 
      } 
    } 
    if (arylstErrorList.size() != 0)
      reportError(arylstErrorList); 
  }
  
  private void checkMandatoryHeader(HrmPrmCriteriaHdrBean oHdrBean, ArrayList arylstErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList arylstParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHdrBean.getFromGradeCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.fromGradeCode");
      arylstParams = new ArrayList();
      arylstParams.add(oMessageKey);
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", arylstParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHdrBean.getToGradeCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.toGradeCode");
      arylstParams = new ArrayList();
      arylstParams.add(oMessageKey);
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", arylstParams, "E"));
    } 
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String param1) throws EnrgiseSystemException {
    return "saveHeaderImpl toBeDone";
  }
  
  public void additionalBusinessValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList oDtlBeanArray, boolean param7, Timestamp param8) throws EnrgiseApplicationException, EnrgiseSystemException {
    int iCount = 0;
    Iterator itrDtlBean = oDtlBeanArray.iterator();
    ArrayList arylstErrorList = new ArrayList();
    String sPrevStartDt = null;
    String sPrevEndDt = null;
    while (itrDtlBean.hasNext()) {
      iCount++;
      HrmPrmCriteriaDtlBean oDtlBean = itrDtlBean.next();
      if (!oDtlBean.getStatus().equals("D")) {
        if (EnrgiseUtil.checkString(oDtlBean.getTxtCriteriaEndDate()))
          if (EnrgiseUtil.compareDates(new SimpleDateFormat("dd-MMM-yyyy"), oDtlBean.getTxtCriteriaEndDate(), oDtlBean.getTxtCriteriaStartDate()) < 0) {
            MessageKey oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtCriteriaStartDate");
            ArrayList arylstParams = new ArrayList();
            arylstParams.add(oMessageKey);
            oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtCriteriaEndDate");
            arylstParams.add(oMessageKey);
            arylstParams.add(new Integer(iCount));
            arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmPrmCriteria.error.dateRangeInvalid", arylstParams, "E"));
          }  
        if (iCount > 1)
          if (EnrgiseUtil.compareDates(new SimpleDateFormat("dd-MMM-yyyy"), oDtlBean.getTxtCriteriaStartDate(), sPrevStartDt) < 0) {
            MessageKey oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtCriteriaStartDate");
            ArrayList arylstParams = new ArrayList();
            arylstParams.add(oMessageKey);
            arylstParams.add(new Integer(iCount));
            oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtCriteriaStartDate");
            arylstParams.add(oMessageKey);
            arylstParams.add(new Integer(iCount - 1));
            arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmPrmCriteria.error.dateOverlapping", arylstParams, "E"));
          }  
        if (EnrgiseUtil.checkString(sPrevEndDt))
          if (EnrgiseUtil.compareDates(new SimpleDateFormat("dd-MMM-yyyy"), oDtlBean.getTxtCriteriaStartDate(), sPrevEndDt) < 0) {
            MessageKey oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtCriteriaStartDate");
            ArrayList arylstParams = new ArrayList();
            arylstParams.add(oMessageKey);
            arylstParams.add(new Integer(iCount));
            oMessageKey = new MessageKey("hrm.HrmPrmCriteria.txtCriteriaEndDate");
            arylstParams.add(oMessageKey);
            arylstParams.add(new Integer(iCount - 1));
            arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmPrmCriteria.error.dateOverlapping", arylstParams, "E"));
          }  
      } 
      sPrevStartDt = oDtlBean.getTxtCriteriaStartDate();
      sPrevEndDt = oDtlBean.getTxtCriteriaEndDate();
    } 
    if (arylstErrorList.size() != 0)
      reportError(arylstErrorList); 
  }
  
  public LovVO getPostLOV(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    ArrayList arylstOutArray;
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("hrm.id");
    oHeaderList.add("hrm.HrmPrmCriteria.code");
    oHeaderList.add("hrm.HrmPrmCriteria.description");
    oHeaderList.add("hrm.HrmPrmCriteria.hierarchy");
    oHeaderList.add("hrm.HrmPrmCriteria.designation");
    oHeaderList.add("hrm.HrmPrmCriteria.scale");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    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();
    String sHierarchy = null;
    if (oLovQueryVO.getProperty("hierarchy") != null)
      sHierarchy = oLovQueryVO.getProperty("hierarchy").trim(); 
    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, 1, 12, sHierarchy));
    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));
    String sDirection = oLovQueryVO.getProperty("direction");
    if (sDirection.equalsIgnoreCase("to")) {
      arylstOutArray = oBean.callProc(arylstParameters, "HRMPRMCRITERIA.proc_GetToPostLOV(?,?,?,?,?,?,?)");
    } else {
      arylstOutArray = oBean.callProc(arylstParameters, "HRMPRMCRITERIA.proc_GetFromPostLOV(?,?,?,?,?,?,?)");
    } 
    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("code").getString());
      oLOVBean.setDetailField3(oRow.get("description").getString());
      oLOVBean.setDetailField4(oRow.get("hierarchy").getString());
      oLOVBean.setDetailField5(oRow.get("Designation").getString());
      oLOVBean.setDetailField6(oRow.get("Scale").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getPromKPARatingFromGradeNLOVData(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = "select distinct hcd.id,hcd.code,hcd.name,hcd.HIERARCHY_LEVEL as gradeSeq  from hrm_class_mst hcm,hrm_class_dtl hcd  ";
    sQuery = String.valueOf(sQuery).concat(String.valueOf(" where hcd.CLS_MST_ID=hcm.id and hcm.code='20'  "));
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField1()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hcd.code) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField1()))).concat(String.valueOf("%') ")); 
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField2()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hcd.name) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField2()))).concat(String.valueOf("%') ")); 
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oResultList = oBean.executeQuery(sQuery);
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    ArrayList oList = new ArrayList();
    oHeaderList.add("gradeId");
    oHeaderList.add("hrm.HrmPrmOrder.gradeCode");
    oHeaderList.add("hrm.HrmPrmOrder.gradeName");
    oHeaderList.add("gradeSeq");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("H");
    oLovVO.setVisibilityList(arylstVisibility);
    QueryRow oRow = null;
    Iterator oIt = oResultList.iterator();
    while (oIt.hasNext()) {
      oRow = oIt.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("id").getString());
      oLOVBean.setDetailField2(oRow.get("code").getString());
      oLOVBean.setDetailField3(oRow.get("name").getString());
      oLOVBean.setDetailField4(oRow.get("gradeSeq").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public LovVO getPromKPARatingFromDesignationNLOVData(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = "select distinct hcd.id,hcd.code,hcd.name,hcd.HIERARCHY_LEVEL as desigSeq  from hrm_class_mst hcm,hrm_class_dtl hcd  ";
    sQuery = String.valueOf(sQuery).concat(String.valueOf(" where hcd.CLS_MST_ID=hcm.id and hcm.code='10'  "));
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField1()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hcd.code) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField1()))).concat(String.valueOf("%') ")); 
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField2()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hcd.name) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField2()))).concat(String.valueOf("%') ")); 
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oResultList = oBean.executeQuery(sQuery);
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    ArrayList oList = new ArrayList();
    oHeaderList.add("desigId");
    oHeaderList.add("hrm.HrmPrmOrder.desigCode");
    oHeaderList.add("hrm.HrmPrmOrder.desigName");
    oHeaderList.add("desigSeq");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("H");
    oLovVO.setVisibilityList(arylstVisibility);
    QueryRow oRow = null;
    Iterator oIt = oResultList.iterator();
    while (oIt.hasNext()) {
      oRow = oIt.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("id").getString());
      oLOVBean.setDetailField2(oRow.get("code").getString());
      oLOVBean.setDetailField3(oRow.get("name").getString());
      oLOVBean.setDetailField4(oRow.get("desigSeq").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public LovVO getPromKPARatingToGradeNLOVData(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = "select distinct hcd.id,hcd.code,hcd.name  from hrm_class_mst hcm,hrm_class_dtl hcd  ";
    sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" where hcd.CLS_MST_ID=hcm.id and hcm.code='20' and hcd.HIERARCHY_LEVEL < '"))).concat(String.valueOf(oLovQueryVO.getProperty("gradeSeq")))).concat(String.valueOf("' "));
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField1()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hcd.code) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField1()))).concat(String.valueOf("%') ")); 
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField2()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hcd.name) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField2()))).concat(String.valueOf("%') ")); 
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oResultList = oBean.executeQuery(sQuery);
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    ArrayList oList = new ArrayList();
    oHeaderList.add("gradeId");
    oHeaderList.add("hrm.HrmPrmOrder.gradeCode");
    oHeaderList.add("hrm.HrmPrmOrder.gradeName");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    QueryRow oRow = null;
    Iterator oIt = oResultList.iterator();
    while (oIt.hasNext()) {
      oRow = oIt.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;
  }
  
  public LovVO getPromKPARatingToDesignationNLOVData(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = "select distinct hcd.id,hcd.code,hcd.name,hcd.HIERARCHY_LEVEL as desigSeq  from hrm_class_mst hcm,hrm_class_dtl hcd  ";
    sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" where hcd.CLS_MST_ID=hcm.id and hcm.code='10' and hcd.HIERARCHY_LEVEL < '"))).concat(String.valueOf(oLovQueryVO.getProperty("desigSeq")))).concat(String.valueOf("' "));
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField1()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hcd.code) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField1()))).concat(String.valueOf("%') ")); 
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField2()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hcd.name) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField2()))).concat(String.valueOf("%') ")); 
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oResultList = oBean.executeQuery(sQuery);
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    ArrayList oList = new ArrayList();
    oHeaderList.add("desigId");
    oHeaderList.add("hrm.HrmPrmOrder.desigCode");
    oHeaderList.add("hrm.HrmPrmOrder.desigName");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    QueryRow oRow = null;
    Iterator oIt = oResultList.iterator();
    while (oIt.hasNext()) {
      oRow = oIt.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;
  }
}
