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.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.HrmPrmKPAFinalDtlBean;
import wenrgise.hrms.bean.HrmPrmKPAPoswiseDtlBean;
import wenrgise.hrms.bean.HrmPrmKPARatingHdrBean;
import wenrgise.hrms.vo.HrmPrmKPARatingQVO;

public class HrmPrmKPARatingBO extends HrmBaseBO {
  public HrmPrmKPARatingBO() {}
  
  public HrmPrmKPARatingBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public LovVO getPosNoLOVdataQ(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("");
    arylstHeaderList.add("hrm.HrmPrmKPARating.positionCode");
    arylstHeaderList.add("hrm.HrmPrmKPARating.desc");
    arylstHeaderList.add("hrm.HrmPrmKPARating.hierarchy");
    arylstHeaderList.add("hrm.HrmPrmKPARating.designation");
    arylstHeaderList.add("hrm.HrmPrmKPARating.scale");
    oLovVO.setHeaderList(arylstHeaderList);
    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 arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 2, -10));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMPRMKPARATING.proc_GetPositionNoLOVQuery(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstParam.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstParam = new ArrayList(); 
      count++;
      oRow = (QueryRow)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());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
  
  public LovVO getPosNoLOVdataN(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("");
    arylstHeaderList.add("hrm.HrmPrmKPARating.positionCode");
    arylstHeaderList.add("hrm.HrmPrmKPARating.desc");
    arylstHeaderList.add("hrm.HrmPrmKPARating.hierarchy");
    arylstHeaderList.add("hrm.HrmPrmKPARating.designation");
    arylstHeaderList.add("hrm.HrmPrmKPARating.scale");
    oLovVO.setHeaderList(arylstHeaderList);
    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 arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 2, -10));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMPRMKPARATING.proc_GetPositionNoLOVNew(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstParam.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstParam = new ArrayList(); 
      count++;
      oRow = (QueryRow)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_ID").getString());
      oLOVBean.setDetailField6(oRow.get("SCALE_ID").getString());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
  
  public LovVO getRatNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("");
    arylstHeaderList.add("hrm.HrmPrmKPARating.rating");
    arylstHeaderList.add("hrm.HrmPrmKPARating.maxRating");
    arylstHeaderList.add("hrm.HrmPrmKPARating.minRating");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    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(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 2, -10));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMPRMKPARATING.proc_GetRatingNoLOV(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstParam.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstParam = new ArrayList(); 
      count++;
      oRow = (QueryRow)iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("CODE").getString());
      oLOVBean.setDetailField3(oRow.get("max_rating").getString());
      oLOVBean.setDetailField4(oRow.get("min_rating").getString());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
  
  public LovVO getRatNoLOVQdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("");
    arylstHeaderList.add("hrm.HrmPrmKPARating.rating");
    arylstHeaderList.add("hrm.HrmPrmKPARating.maxRating");
    arylstHeaderList.add("hrm.HrmPrmKPARating.minRating");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    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(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 2, -10));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMPRMKPARATING.proc_GetRatingNoQLOV(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstParam.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstParam = new ArrayList(); 
      count++;
      oRow = (QueryRow)iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("CODE").getString());
      oLOVBean.setDetailField3(oRow.get("max_rating").getString());
      oLOVBean.setDetailField4(oRow.get("min_rating").getString());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
  
  public LovVO getKPAGrpCodeLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("");
    arylstHeaderList.add("hrm.HrmPrmKPARating.txtKPAGroupCode");
    arylstHeaderList.add("hrm.HrmPrmKPARating.txtKPAGroupDesc");
    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(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 2, -10));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMPRMKPARATING.proc_GetKPAGrpCodeLOV(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstParam.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstParam = new ArrayList(); 
      count++;
      oRow = (QueryRow)iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("CODE").getString());
      oLOVBean.setDetailField3(oRow.get("DESCRIPTION").getString());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
  
  public RecordMetaInfo getPrmKPARatingHdrMetaInfo(HrmPrmKPARatingQVO oHrmPrmKPARatingQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmPrmKPARatingQVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(2, 1, 12, oHrmPrmKPARatingQVO.getRatingId()));
    oParameters.add(new DBObject(3, 2, -5));
    oParameters.add(new DBObject(4, 2, 93));
    oParameters.add(new DBObject(5, 2, 12));
    oParameters.add(new DBObject(6, 2, 12));
    oParameters.add(new DBObject(7, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMKPARATING.PROC_KPARATINGCOUNT(?,?,?,?,?,?,?)");
    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 getPrmKPARatingInfo(HrmPrmKPARatingQVO oHrmPrmKPARatingQVO, 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 (oHrmPrmKPARatingQVO == null)
      oHrmPrmKPARatingQVO = new HrmPrmKPARatingQVO(); 
    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, oHrmPrmKPARatingQVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(4, 1, 12, oHrmPrmKPARatingQVO.getRatingId()));
    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, "HRMPRMKPARATING.proc_KPARatingHdrInfo(?,?,?,?,?,?,?,?)");
    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();
      HrmPrmKPARatingHdrBean oHrmPrmKPARatingHdrBean = new HrmPrmKPARatingHdrBean();
      oHrmPrmKPARatingHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmPrmKPARatingHdrBean.setGradeId(oRow.get("GRADE_ID").getString());
      oHrmPrmKPARatingHdrBean.setGradeCode(oRow.get("gradeCode").getString());
      oHrmPrmKPARatingHdrBean.setGradeDesc(oRow.get("grade").getString());
      oHrmPrmKPARatingHdrBean.setDesigId(oRow.get("DESIGNATION_ID").getString());
      oHrmPrmKPARatingHdrBean.setDesigCode(oRow.get("designationCode").getString());
      oHrmPrmKPARatingHdrBean.setDesigDesc(oRow.get("designation").getString());
      oHrmPrmKPARatingHdrBean.setRatingId(oRow.get("Rating_Id").getString());
      oHrmPrmKPARatingHdrBean.setRatingNo(oRow.get("Rating_Code").getString());
      oHrmPrmKPARatingHdrBean.setMaxRating(oRow.get("MAX_RATING").getString());
      oHrmPrmKPARatingHdrBean.setMinRating(oRow.get("MIN_RATING").getString());
      oHeaderList.add(oHrmPrmKPARatingHdrBean);
    } 
    return oHeaderList;
  }
  
  public RecordMetaInfo getPrmKPARatingPosDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, lPrimaryKey));
    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, "HRMPRMKPARATING.proc_KPARatingPosDtlCount(?,?,?,?,?,?)");
    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 getPrmKPARatingPosDtlInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmPrmKPAPoswiseDtl = 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, lPrimaryKey));
    oParameters.add(new DBObject(4, 2, -10));
    oParameters.add(new DBObject(5, 2, 12));
    oParameters.add(new DBObject(6, 2, 12));
    oParameters.add(new DBObject(7, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMKPARATING.proc_KPARatingPosDtlInfo(?,?,?,?,?,?,?)");
    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)
        arylstHrmPrmKPAPoswiseDtl = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmPrmKPAPoswiseDtlBean oHrmPrmKPAPoswiseDtlBean = new HrmPrmKPAPoswiseDtlBean();
      oHrmPrmKPAPoswiseDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmPrmKPAPoswiseDtlBean.setTxtKPAGroupId(oRow.get("APR_KPA_HD_ID").getString());
      oHrmPrmKPAPoswiseDtlBean.setTxtPromKPARatingHdrId(oRow.get("prom_kpa_rating_hdr_id").getString());
      oHrmPrmKPAPoswiseDtlBean.setTxtKPAGroupCode(oRow.get("CODE").getString());
      oHrmPrmKPAPoswiseDtlBean.setTxtKPAGroupDesc(oRow.get("DESCRIPTION").getString());
      oHrmPrmKPAPoswiseDtlBean.setTxtReqAvgRating(oRow.get("AVG_RATING").getString());
      arylstHrmPrmKPAPoswiseDtl.add(oHrmPrmKPAPoswiseDtlBean);
    } 
    return arylstHrmPrmKPAPoswiseDtl;
  }
  
  public RecordMetaInfo getPrmKPARatingFinDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, lPrimaryKey));
    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, "HRMPRMKPARATING.proc_KPARatingFinDtlCount(?,?,?,?,?,?)");
    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 getPrmKPARatingFinDtlInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmPrmKPAFinalDtl = 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, lPrimaryKey));
    oParameters.add(new DBObject(4, 2, -10));
    oParameters.add(new DBObject(5, 2, 12));
    oParameters.add(new DBObject(6, 2, 12));
    oParameters.add(new DBObject(7, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMKPARATING.proc_KPARatingFinDtlInfo(?,?,?,?,?,?,?)");
    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)
        arylstHrmPrmKPAFinalDtl = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean = new HrmPrmKPAFinalDtlBean();
      oHrmPrmKPAFinalDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmPrmKPAFinalDtlBean.setTxtPromKPARatingHdrFId(oRow.get("prom_kpa_rating_hdr_id").getString());
      oHrmPrmKPAFinalDtlBean.setStartField(oRow.get("FROM_RATING").getString());
      oHrmPrmKPAFinalDtlBean.setEndField(oRow.get("TO_RATING").getString());
      oHrmPrmKPAFinalDtlBean.setTxtPoints(oRow.get("POINTS").getString());
      arylstHrmPrmKPAFinalDtl.add(oHrmPrmKPAFinalDtlBean);
    } 
    return arylstHrmPrmKPAFinalDtl;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "hrm_advt_hdr";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmPrmKPARating")) {
      savePoswiseDtl(sHeaderPrimaryKey, oDetailBeanArray);
    } else {
      saveFinalDtl(sHeaderPrimaryKey, oDetailBeanArray);
    } 
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmPrmKPARatingHdrBean oHrmPrmKPARatingHdrBean = (HrmPrmKPARatingHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      oParameters = new ArrayList();
      oParameters.add(new DBObject(1, 1, 12, "N"));
      oParameters.add(new DBObject(2, 1, 12, oHrmPrmKPARatingHdrBean.getRatingId()));
      oParameters.add(new DBObject(3, 1, 12, oHrmPrmKPARatingHdrBean.getGradeId()));
      oParameters.add(new DBObject(4, 1, 12, oHrmPrmKPARatingHdrBean.getDesigId()));
      oParameters.add(new DBObject(5, 1, 12, this.oUserInfo.getSiteId()));
      oParameters.add(new DBObject(6, 1, 12, this.oUserInfo.getUserId()));
      oParameters.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
      oParameters.add(new DBObject(8, 2, 12));
      oParameters.add(new DBObject(9, 2, 12));
      oParameters.add(new DBObject(10, 2, 12));
      oParameters.add(new DBObject(11, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMKPARATING.proc_UpsertKPARatingHdr(?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
    } 
    return returnString;
  }
  
  private void savePoswiseDtl(String sHeaderPrimaryKey, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bDelete = false;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator oIt = oDetailBeanArray.iterator();
    while (oIt.hasNext()) {
      HrmPrmKPAPoswiseDtlBean oHrmPrmKPAPoswiseDtlBean = oIt.next();
      if (oHrmPrmKPAPoswiseDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMKPARATING.proc_UpsertKPARatingPosDtl(?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "N"));
        oParameters.add(new DBObject(2, 1, 12, null));
        oParameters.add(new DBObject(3, 1, 12, oHrmPrmKPAPoswiseDtlBean.getTxtReqAvgRating()));
        oParameters.add(new DBObject(4, 1, 12, sHeaderPrimaryKey));
        oParameters.add(new DBObject(5, 1, 12, oHrmPrmKPAPoswiseDtlBean.getTxtKPAGroupId()));
        oParameters.add(new DBObject(6, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(7, 1, 12, this.oUserInfo.getUserId()));
        oParameters.add(new DBObject(8, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(oParameters);
        continue;
      } 
      if (oHrmPrmKPAPoswiseDtlBean.getStatus().equals("U")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMKPARATING.proc_UpsertKPARatingPosDtl(?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "U"));
        oParameters.add(new DBObject(2, 1, 12, oHrmPrmKPAPoswiseDtlBean.getDetailId()));
        oParameters.add(new DBObject(3, 1, 12, oHrmPrmKPAPoswiseDtlBean.getTxtReqAvgRating()));
        oParameters.add(new DBObject(4, 1, 12, sHeaderPrimaryKey));
        oParameters.add(new DBObject(5, 1, 12, oHrmPrmKPAPoswiseDtlBean.getTxtKPAGroupId()));
        oParameters.add(new DBObject(6, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(7, 1, 12, this.oUserInfo.getUserId()));
        oParameters.add(new DBObject(8, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(oParameters);
        continue;
      } 
      if (oHrmPrmKPAPoswiseDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMPRMKPARATING.proc_DeleteKPARatingPosDtl(?)");
          bDelete = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, oHrmPrmKPAPoswiseDtlBean.getDetailId()));
        oBean1.addToBatch(oParameters);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  private void saveFinalDtl(String sHeaderPrimaryKey, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bDelete = false;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator oIt = oDetailBeanArray.iterator();
    while (oIt.hasNext()) {
      HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean = oIt.next();
      if (oHrmPrmKPAFinalDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMKPARATING.proc_UpsertKPARatingFinDtl(?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "N"));
        oParameters.add(new DBObject(2, 1, 12, null));
        oParameters.add(new DBObject(3, 1, 12, oHrmPrmKPAFinalDtlBean.getStartField()));
        oParameters.add(new DBObject(4, 1, 12, oHrmPrmKPAFinalDtlBean.getEndField()));
        oParameters.add(new DBObject(5, 1, 12, oHrmPrmKPAFinalDtlBean.getTxtPoints()));
        oParameters.add(new DBObject(6, 1, 12, sHeaderPrimaryKey));
        oParameters.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(8, 1, 12, this.oUserInfo.getUserId()));
        oParameters.add(new DBObject(9, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(oParameters);
        continue;
      } 
      if (oHrmPrmKPAFinalDtlBean.getStatus().equals("U")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMKPARATING.proc_UpsertKPARatingFinDtl(?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "U"));
        oParameters.add(new DBObject(2, 1, 12, oHrmPrmKPAFinalDtlBean.getDetailId()));
        oParameters.add(new DBObject(3, 1, 12, oHrmPrmKPAFinalDtlBean.getStartField()));
        oParameters.add(new DBObject(4, 1, 12, oHrmPrmKPAFinalDtlBean.getEndField()));
        oParameters.add(new DBObject(5, 1, 12, oHrmPrmKPAFinalDtlBean.getTxtPoints()));
        oParameters.add(new DBObject(6, 1, 12, sHeaderPrimaryKey));
        oParameters.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(8, 1, 12, this.oUserInfo.getUserId()));
        oParameters.add(new DBObject(9, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(oParameters);
        continue;
      } 
      if (oHrmPrmKPAFinalDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMPRMKPARATING.proc_DeleteKPARatingFinDtl(?)");
          bDelete = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, oHrmPrmKPAFinalDtlBean.getDetailId()));
        oBean1.addToBatch(oParameters);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    System.out.println("Update ille!");
  }
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "saveNewHeaderImpl ille!";
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrorList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmPrmKPARatingHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged) {
      if (sScreenName.equalsIgnoreCase("HrmPrmKPARating")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int rowCount = 1;
        while (oIt1.hasNext()) {
          HrmPrmKPAPoswiseDtlBean oHrmPrmKPAPoswiseDtlBean = oIt1.next();
          if (!oHrmPrmKPAPoswiseDtlBean.getStatus().equalsIgnoreCase("D")) {
            checkMandatoryDtls(oHrmPrmKPAPoswiseDtlBean, rowCount);
            checkforNumericfields(oHrmPrmKPAPoswiseDtlBean, rowCount);
            rowCount++;
          } 
        } 
      } 
      if (sScreenName.equalsIgnoreCase("HrmPrmKPARatingF")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int rowCount = 1;
        while (oIt1.hasNext()) {
          HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean = oIt1.next();
          if (!oHrmPrmKPAFinalDtlBean.getStatus().equalsIgnoreCase("D")) {
            checkMandatoryDtls(oHrmPrmKPAFinalDtlBean, rowCount);
            checkforNumericfields(oHrmPrmKPAFinalDtlBean, rowCount);
            rowCount++;
          } 
        } 
      } 
    } 
  }
  
  private void checkMandatoryHeader(HrmPrmKPARatingHdrBean oHrmPrmKPARatingHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmPrmKPARatingHdrBean.getGradeCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.gradeCode");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmPrmKPARatingHdrBean.getRatingNo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.rating");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  private void checkMandatoryDtls(HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean, int rowCount) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmPrmKPAFinalDtlBean.getStartField())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtFromRating");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParam, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmPrmKPAFinalDtlBean.getEndField())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtToRating");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParam, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmPrmKPAFinalDtlBean.getTxtPoints())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtPoints");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParam, "E"));
    } 
    reportError(oErrorList);
  }
  
  private void checkMandatoryDtls(HrmPrmKPAPoswiseDtlBean oHrmPrmKPAPoswiseDtlBean, int rowCount) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmPrmKPAPoswiseDtlBean.getTxtKPAGroupCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtKPAGroupCode");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParam, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmPrmKPAPoswiseDtlBean.getTxtKPAGroupDesc())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtKPAGroupDesc");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParam, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmPrmKPAPoswiseDtlBean.getTxtReqAvgRating())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtReqAvgRating");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParam, "E"));
    } 
    reportError(oErrorList);
  }
  
  private void checkUniquePoswiseDtl(String sHeaderPrimaryKey, ArrayList oDetailBeanArray, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    int count = 1;
    Iterator oIt1 = oDetailBeanArray.iterator();
    while (oIt1.hasNext()) {
      HrmPrmKPAPoswiseDtlBean oHrmPrmKPAPoswiseDtlBean = oIt1.next();
      String sQuery = String.valueOf(String.valueOf(String.valueOf(" Select ID from HRM_PROM_KPA_RATING where PROM_KPA_RATING_HDR_ID=").concat(String.valueOf(sHeaderPrimaryKey))).concat(String.valueOf(" and APR_KPA_HD_ID="))).concat(String.valueOf(oHrmPrmKPAPoswiseDtlBean.getTxtKPAGroupId()));
      System.out.println(sQuery);
      DBUtilitiesBean oBean = new DBUtilitiesBean();
      ArrayList oList = oBean.executeQuery(sQuery);
      Iterator oIt = oList.iterator();
      if (oIt.hasNext()) {
        QueryRow oRow = oIt.next();
        if (!oRow.get("ID").getString().equalsIgnoreCase(oHrmPrmKPAPoswiseDtlBean.getDetailId())) {
          ArrayList oParams = new ArrayList();
          MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtKPAGroupCode");
          oParams.add(oMessageKey);
          oParams.add(new Integer(count));
          oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.uniqueKeyViolated", oParams, "E"));
        } 
      } 
      count++;
    } 
    reportError(oErrorList);
  }
  
  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 oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    HrmPrmKPARatingHdrBean oHrmPrmKPARatingHdrBean = (HrmPrmKPARatingHdrBean)oBaseHeaderBean;
    String maxRating = oHrmPrmKPARatingHdrBean.getMaxRating();
    String minRating = oHrmPrmKPARatingHdrBean.getMinRating();
    ArrayList oErrorList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkUniqueHeader((HrmPrmKPARatingHdrBean)oBaseHeaderBean, oErrorList);  
    if (bDetailDataChanged) {
      if (sScreenName.equalsIgnoreCase("HrmPrmKPARating")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int rowcount = 1;
        while (oIt1.hasNext()) {
          HrmPrmKPAPoswiseDtlBean oHrmPrmKPAPoswiseDtlBean = oIt1.next();
          if (!oHrmPrmKPAPoswiseDtlBean.getStatus().equalsIgnoreCase("D"))
            checkUniquePoswiseDtl(oHrmPrmKPARatingHdrBean.getHeaderPrimaryKey(), oDetailBeanArray, oErrorList); 
        } 
      } 
      if (sScreenName.equalsIgnoreCase("HrmPrmKPARatingF")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int rowcount = 1;
        while (oIt1.hasNext()) {
          HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean = oIt1.next();
          if (!oHrmPrmKPAFinalDtlBean.getStatus().equalsIgnoreCase("D")) {
            checkPointOrder(oDetailBeanArray, oErrorList);
            checkMaxMinRating(oHrmPrmKPAFinalDtlBean, rowcount, maxRating, minRating);
          } 
        } 
      } 
    } 
    reportError(oErrorList);
  }
  
  private void checkUniqueHeader(HrmPrmKPARatingHdrBean oHrmPrmKPARatingHdrBean, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = String.valueOf(String.valueOf(String.valueOf(String.valueOf(String.valueOf(String.valueOf(" Select ID as ID from hrm_prom_kpa_rating_hdr where GRADE_ID='").concat(String.valueOf(oHrmPrmKPARatingHdrBean.getGradeId()))).concat(String.valueOf("' and DESIGNATION_ID='"))).concat(String.valueOf(oHrmPrmKPARatingHdrBean.getDesigId()))).concat(String.valueOf("' and RATING_HDR_ID='"))).concat(String.valueOf(oHrmPrmKPARatingHdrBean.getRatingId()))).concat(String.valueOf("' "));
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstList = oBean.executeQuery(sQuery);
    Iterator itrBean = arylstList.iterator();
    if (itrBean.hasNext()) {
      QueryRow oRow = itrBean.next();
      if (!oRow.get("ID").getString().equalsIgnoreCase(oHrmPrmKPARatingHdrBean.getHeaderPrimaryKey())) {
        MessageKey oMessageKey1 = new MessageKey("hrm.HrmPrmKPARating.gradeCode");
        MessageKey oMessageKey2 = new MessageKey("hrm.HrmPrmKPARating.desigCode");
        MessageKey oMessageKey3 = new MessageKey("hrm.HrmPrmKPARating.rating");
        ArrayList oParams = new ArrayList();
        oParams.add(oMessageKey1);
        oParams.add(oMessageKey2);
        oParams.add(oMessageKey3);
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.promKpa.uniqueConstraintViolated", oParams, "E"));
      } 
    } 
  }
  
  private void checkforNumericfields(HrmPrmKPAPoswiseDtlBean oHrmPrmKPAPoswiseDtlBean, int rowCount) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrList = new ArrayList();
    if (!EnrgiseUtil.checkNumber(oHrmPrmKPAPoswiseDtlBean.getTxtReqAvgRating(), 5, 2, "P")) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtReqAvgRating");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrList.add(new EnrgiseMessageKeyException("hrm.advt.detail.nonnumeric", oParam));
    } 
    reportError(oErrList);
  }
  
  private void checkforNumericfields(HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean, int rowCount) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrList = new ArrayList();
    if (!EnrgiseUtil.checkNumber(oHrmPrmKPAFinalDtlBean.getStartField(), 5, 2, "P")) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtFromRating");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrList.add(new EnrgiseMessageKeyException("hrm.advt.detail.nonnumeric", oParam));
    } 
    if (!EnrgiseUtil.checkNumber(oHrmPrmKPAFinalDtlBean.getEndField(), 6, 2, "P")) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtToRating");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrList.add(new EnrgiseMessageKeyException("hrm.advt.detail.nonnumeric", oParam));
    } 
    if (!EnrgiseUtil.checkNumber(oHrmPrmKPAFinalDtlBean.getTxtPoints(), 5, 2, "P")) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmKPARating.txtPoints");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrList.add(new EnrgiseMessageKeyException("hrm.advt.detail.nonnumeric", oParam));
    } 
    reportError(oErrList);
  }
  
  private void checkDates(HrmPrmKPARatingHdrBean oHrmPrmKPARatingHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  private void checkPointOrder(ArrayList oDetailBeanArray, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    Iterator oIt = oDetailBeanArray.iterator();
    int i = 1;
    while (oIt.hasNext()) {
      int rowCount = 1;
      HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean = oIt.next();
      if (i != 1) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        while (oIt1.hasNext()) {
          HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean1 = oIt1.next();
          if (Double.parseDouble(oHrmPrmKPAFinalDtlBean.getStartField()) > Double.parseDouble(oHrmPrmKPAFinalDtlBean1.getStartField()) && Double.parseDouble(oHrmPrmKPAFinalDtlBean.getTxtPoints()) < Double.parseDouble(oHrmPrmKPAFinalDtlBean1.getTxtPoints())) {
            ArrayList oParam = new ArrayList();
            oParam.add(new Integer(i));
            throw new EnrgiseApplicationException("hrm.HrmTestScore.errorinPoints", oParam, "E");
          } 
          rowCount++;
        } 
      } 
      i++;
    } 
  }
  
  private void checkMaxMinRating(HrmPrmKPAFinalDtlBean oHrmPrmKPAFinalDtlBean, int rowcount, String maxRating, String minRating) throws EnrgiseApplicationException, EnrgiseSystemException {
    if (EnrgiseUtil.checkString(oHrmPrmKPAFinalDtlBean.getStartField()) && EnrgiseUtil.checkString(oHrmPrmKPAFinalDtlBean.getEndField()))
      if (Double.parseDouble(oHrmPrmKPAFinalDtlBean.getStartField()) < Double.parseDouble(minRating) || Double.parseDouble(oHrmPrmKPAFinalDtlBean.getEndField()) > Double.parseDouble(maxRating)) {
        ArrayList oParam = new ArrayList();
        oParam.add(new Integer(rowcount));
        throw new EnrgiseApplicationException("hrm.HrmPrmKPARating.errorinrating", oParam, "E");
      }  
  }
  
  public LovVO getPromKPARatingGradeNLOVData(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(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");
    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 getPromKPARatingDesignationNLOVData(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(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("gradeId");
    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;
  }
}
