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.HrmAppTempHdrBean;
import wenrgise.hrms.bean.HrmAppraisalTemplateKpaDtlBean;
import wenrgise.hrms.bean.HrmAppraisalTemplateSecDtlBean;
import wenrgise.hrms.vo.HrmAppTempQueryVO;

public class HrmAppTempBusinessObject extends HrmBaseBO {
  public HrmAppTempBusinessObject() {}
  
  public HrmAppTempBusinessObject(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmAppTemplateHdrMetaInfo(HrmAppTempQueryVO oHrmAppTempQueryVO) 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, oHrmAppTempQueryVO.getRatingCode()));
    arylstParam.add(new DBObject(2, 1, 12, oHrmAppTempQueryVO.getTemplateName()));
    arylstParam.add(new DBObject(3, 1, 12, oHrmAppTempQueryVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(4, 2, -5));
    arylstParam.add(new DBObject(5, 2, 93));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 12));
    arylstParam.add(new DBObject(8, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetHrmAprslTmplHdrCount(?,?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmAppTempHeaderInfo(HrmAppTempQueryVO oHrmAppTempQueryVO, 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 arylstHeaderList = null;
    if (oHrmAppTempQueryVO == null)
      oHrmAppTempQueryVO = new HrmAppTempQueryVO(); 
    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, oHrmAppTempQueryVO.getRatingCode()));
    arylstParam.add(new DBObject(4, 1, 12, oHrmAppTempQueryVO.getTemplateName()));
    arylstParam.add(new DBObject(5, 1, 12, oHrmAppTempQueryVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(6, 2, -10));
    arylstParam.add(new DBObject(7, 2, 12));
    arylstParam.add(new DBObject(8, 2, 12));
    arylstParam.add(new DBObject(9, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetHrmAprslTmplHdr(?,?,?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator oIt = arylstList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        arylstHeaderList = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmAppTempHdrBean oHrmAppTempHdrBean = new HrmAppTempHdrBean();
      oHrmAppTempHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmAppTempHdrBean.setTemplateName(oRow.get("TEMPLATE_NAME").getString());
      oHrmAppTempHdrBean.setRatingCode(oRow.get("CODE").getString());
      oHrmAppTempHdrBean.setRatingId(oRow.get("RATE_HD_ID").getString());
      if (EnrgiseUtil.checkString(oRow.get("TMPL_APP_FLAG").getString()))
        if (oRow.get("TMPL_APP_FLAG").getString().equalsIgnoreCase("Y")) {
          oHrmAppTempHdrBean.setHeaderFlag("A");
          oHrmAppTempHdrBean.setStatusOfHeader("Approved");
        }  
      oHrmAppTempHdrBean.setObsolete(String.valueOf(oRow.get("OBSOLETE_FLAG").getString()).equalsIgnoreCase("Y") ? "on" : "off");
      oHrmAppTempHdrBean.setApplicableToAll(String.valueOf(oRow.get("ALL_FLAG").getString()).equalsIgnoreCase("Y") ? "on" : "off");
      arylstHeaderList.add(oHrmAppTempHdrBean);
    } 
    return arylstHeaderList;
  }
  
  public RecordMetaInfo getHrmAppTempSecDtlMetaInfo(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 arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetHrmAprslTmplDtlCount(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmAppTempSecDetailInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmTempSecDetail = 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 arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetHrmAprslTmplDtl(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator oIt = arylstList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        arylstHrmTempSecDetail = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmAppraisalTemplateSecDtlBean oSecDtlBean = new HrmAppraisalTemplateSecDtlBean();
      oSecDtlBean.setDetailId(oRow.get("ID").getString());
      oSecDtlBean.setTxtSrlNo(oRow.get("SRL_NO").getString());
      oSecDtlBean.setTxtSectionCode(oRow.get("SEC_CODE").getString());
      oSecDtlBean.setTxtAppraiserType(oRow.get("APPRAISER_TYP_FLAG").getString());
      oSecDtlBean.setTxtTemplateRemarks(oRow.get("TMPL_SEC_REMARK").getString());
      oSecDtlBean.setTxtSectionWeightage(oRow.get("SEC_WEIGHTAGE").getString());
      oSecDtlBean.setTxtParentSection(oRow.get("PARENTCODE").getString());
      oSecDtlBean.setTxtParentSecId(oRow.get("PARENT_SEC_ID").getString());
      oSecDtlBean.setTxtRatingReqd(String.valueOf(oRow.get("rating_required").getString()).equalsIgnoreCase("Y") ? "on" : "off");
      arylstHrmTempSecDetail.add(oSecDtlBean);
    } 
    return arylstHrmTempSecDetail;
  }
  
  public RecordMetaInfo getAppTempSecKPADetailMetaInfo(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 arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetHrmAprslTmplKPADtlCount(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrAppTempSecKPADetail(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList arylstList = null;
    Iterator oIt = null;
    ArrayList arylstAppTempKPADetail = 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 arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetHrmAprslTmplKPADtl(?,?,?,?,?,?,?)");
    arylstList = (ArrayList)((DBObject)arylstOutArray.get(0)).getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    count = 0;
    oIt = arylstList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        arylstAppTempKPADetail = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmAppraisalTemplateKpaDtlBean oAppTempSecKPADtlBean = new HrmAppraisalTemplateKpaDtlBean();
      oAppTempSecKPADtlBean.setDetailId(oRow.get("ID").getString());
      oAppTempSecKPADtlBean.setTxtKpaGroupCode(oRow.get("CODE").getString());
      oAppTempSecKPADtlBean.setTxtApprKpa(oRow.get("DESCRIPTION").getString());
      oAppTempSecKPADtlBean.setTxtWeightage(oRow.get("WEIGHTAGE").getString());
      oAppTempSecKPADtlBean.setTxtKpaId(oRow.get("APRSL_KPA_GRP_ID").getString());
      arylstAppTempKPADetail.add(oAppTempSecKPADtlBean);
    } 
    return arylstAppTempKPADetail;
  }
  
  public boolean chkHrmAppTempHdrByRatingIdCount(String sRatingId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    boolean flag = true;
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sRatingId));
    arylstParam.add(new DBObject(2, 2, -5));
    arylstParam.add(new DBObject(3, 2, 93));
    arylstParam.add(new DBObject(4, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMSAPPTEMP.proc_HrAppTempHdrCount(?,?,?,?)");
    DBObject oTotalRecord = arylstOutArray.get(0);
    long count1 = ((Long)oTotalRecord.getObject()).longValue();
    System.out.println(count1);
    if (count1 == 0L)
      flag = false; 
    return flag;
  }
  
  public void updateAppTempHdrMst(String sSql, String sId, String sUserId, String sUserSiteId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sSql));
    arylstParam.add(new DBObject(2, 1, 12, sId));
    arylstParam.add(new DBObject(3, 1, 12, sUserId));
    arylstParam.add(new DBObject(4, 1, 12, sUserSiteId));
    arylstParam.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMSAPPTEMP.proc_UpdateHrAppTempHdr(?,?,?,?,?)");
  }
  
  public LovVO getHrmAprslTmplNameLOVInfo(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("hrm.HrmAppraisalTemplate.templateName");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oLovQueryVO.getSearchField1()));
    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, "HRMAPRSLTMPLMST.procGetHrmAprslTmplCodeQLOV(?,?,?,?,?)");
    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("TEMPLATE_NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmAprslSecCodeLOVInfo(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("hrm.HrmAppraisalTemplate.sectionCode");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oLovQueryVO.getSearchField1()));
    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, "HRMAPRSLTMPLMST.procGetHrmAprslTmplSecCodeLOV(?,?,?,?,?)");
    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("SEC_CODE").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmAprslKPALOVInfo(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("txtKpaId");
    arylstHeaderNames.add("hrm.HrmAppraisalTemplateKpa.kpaGroupCode");
    arylstHeaderNames.add("hrm.HrmAppraisalTemplateKpa.apprKpa");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oLovQueryVO.getSearchField1()));
    arylstParam.add(new DBObject(2, 1, 12, oLovQueryVO.getSearchField2()));
    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, "HRMAPRSLTMPLMST.procGetHrmAprslTmplKPALOV(?,?,?,?,?,?)");
    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());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmAprslParentCodeLOVInfo(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("txtParentSecId");
    arylstHeaderNames.add("hrm.HrmAppraisalTemplate.parentSection");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    System.out.println(oLovQueryVO.getProperty("txtSectionCode"));
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oLovQueryVO.getProperty("txtSectionCode")));
    arylstParam.add(new DBObject(2, 1, 12, oLovQueryVO.getProperty("txtHdrId")));
    arylstParam.add(new DBObject(3, 1, 12, oLovQueryVO.getSearchField1()));
    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 arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetHrmAprslParentCodeLOV(?,?,?,?,?,?,?)");
    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("PARENT_ID").getString());
      oLOVBean.setDetailField2(oRow.get("SEC_CODE").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_APRSL_TMPL_HDR";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmAppraisalTemplateSection")) {
      saveHrmAprslTmplSecDetail(sHeaderPrimaryKey, oDetailBeanArray);
    } else if (sScreenName.equalsIgnoreCase("HrmAppraisalTemplateKPA")) {
      saveHrmAprslTmplKPADetail(sHeaderPrimaryKey, oDetailBeanArray);
    } 
  }
  
  private void saveHrmAprslTmplSecDetail(String sHeaderPrimaryKey, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = null;
    Iterator oIt = oDetailBeanArray.iterator();
    while (oIt.hasNext()) {
      HrmAppraisalTemplateSecDtlBean oHrmAppraisalTemplateSecDtlBean = oIt.next();
      String sRatingReqd = String.valueOf(oHrmAppraisalTemplateSecDtlBean.getTxtRatingReqd()).equalsIgnoreCase("on") ? "Y" : "N";
      if (oHrmAppraisalTemplateSecDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMAPRSLTMPLMST.procUpsertHrmAprslTmplSecDtl(?,?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "N"));
        arylstParam.add(new DBObject(2, 1, 12, null));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtSectionCode()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtSrlNo()));
        arylstParam.add(new DBObject(6, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtAppraiserType()));
        arylstParam.add(new DBObject(7, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtTemplateRemarks()));
        arylstParam.add(new DBObject(8, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId()));
        arylstParam.add(new DBObject(9, 1, 12, sRatingReqd));
        arylstParam.add(new DBObject(10, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage()));
        arylstParam.add(new DBObject(11, 1, 12, this.oUserInfo.getUserId()));
        arylstParam.add(new DBObject(12, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmAppraisalTemplateSecDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMAPRSLTMPLMST.procUpsertHrmAprslTmplSecDtl(?,?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "U"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmAppraisalTemplateSecDtlBean.getDetailId()));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtSectionCode()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtSrlNo()));
        arylstParam.add(new DBObject(6, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtAppraiserType()));
        arylstParam.add(new DBObject(7, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtTemplateRemarks()));
        arylstParam.add(new DBObject(8, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId()));
        arylstParam.add(new DBObject(9, 1, 12, sRatingReqd));
        arylstParam.add(new DBObject(10, 1, 12, oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage()));
        arylstParam.add(new DBObject(11, 1, 12, this.oUserInfo.getUserId()));
        arylstParam.add(new DBObject(12, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmAppraisalTemplateSecDtlBean.getStatus().equals("D"));
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
  }
  
  private void saveHrmAprslTmplKPADetail(String sHeaderPrimaryKey, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = null;
    Iterator oIt = oDetailBeanArray.iterator();
    while (oIt.hasNext()) {
      HrmAppraisalTemplateKpaDtlBean oHrmAppraisalTemplateKpaDtlBean = oIt.next();
      if (oHrmAppraisalTemplateKpaDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMAPRSLTMPLMST.procUpsertHrmAprslTmplKPADtl(?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "N"));
        arylstParam.add(new DBObject(2, 1, 12, null));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmAppraisalTemplateKpaDtlBean.getTxtKpaId()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmAppraisalTemplateKpaDtlBean.getTxtWeightage()));
        arylstParam.add(new DBObject(6, 1, 12, this.oUserInfo.getUserId()));
        arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmAppraisalTemplateKpaDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMAPRSLTMPLMST.procUpsertHrmAprslTmplKPADtl(?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "U"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmAppraisalTemplateKpaDtlBean.getDetailId()));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmAppraisalTemplateKpaDtlBean.getTxtKpaId()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmAppraisalTemplateKpaDtlBean.getTxtWeightage()));
        arylstParam.add(new DBObject(6, 1, 12, this.oUserInfo.getUserId()));
        arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmAppraisalTemplateKpaDtlBean.getStatus().equals("D"));
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.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 arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    checkMandatoryHdr((HrmAppTempHdrBean)oBaseHeaderBean, arylstErrorList);
    if (bDetailDataChanged) {
      if (sScreenName.equalsIgnoreCase("HrmAppraisalTemplateSection")) {
        Iterator itrBean1 = arylstDetailBeanArray.iterator();
        int iCount = 1;
        while (itrBean1.hasNext()) {
          HrmAppraisalTemplateSecDtlBean oHrmAppraisalTemplateSecDtlBean = itrBean1.next();
          if (!oHrmAppraisalTemplateSecDtlBean.getStatus().equalsIgnoreCase("D"))
            checkMandatory(oHrmAppraisalTemplateSecDtlBean, iCount, arylstErrorList); 
          iCount++;
        } 
      } 
      if (sScreenName.equalsIgnoreCase("HrmAppraisalTemplateKPA")) {
        Iterator itrBean1 = arylstDetailBeanArray.iterator();
        int iCount = 1;
        while (itrBean1.hasNext()) {
          HrmAppraisalTemplateKpaDtlBean oHrmAppraisalTemplateKpaDtlBean = itrBean1.next();
          if (!oHrmAppraisalTemplateKpaDtlBean.getStatus().equalsIgnoreCase("D"))
            checkMandatoryKPA(oHrmAppraisalTemplateKpaDtlBean, iCount, arylstErrorList); 
          iCount++;
        } 
      } 
    } 
    reportError(arylstErrorList);
  }
  
  private void checkMandatoryHdr(HrmAppTempHdrBean oHrmAppTempHdrBean, ArrayList oErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmAppTempHdrBean.getRatingCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAppraisalTemplateKpa.ratingCode");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmAppTempHdrBean.getTemplateName())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAppraisalTemplateKpa.templateName");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
  }
  
  private void checkMandatory(HrmAppraisalTemplateSecDtlBean oHrmAppraisalTemplateSecDtlBean, int iCount, ArrayList arylstErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmAppraisalTemplateSecDtlBean.getTxtSrlNo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAppraisalTemplate.srlNo");
      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(oHrmAppraisalTemplateSecDtlBean.getTxtSectionCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAppraisalTemplate.sectionCode");
      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(oHrmAppraisalTemplateSecDtlBean.getTxtAppraiserType())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAppraisalTemplate.appraiserType");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
  }
  
  private void checkMandatoryKPA(HrmAppraisalTemplateKpaDtlBean oHrmAppraisalTemplateKpaDtlBean, int iCount, ArrayList arylstErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmAppraisalTemplateKpaDtlBean.getTxtKpaGroupCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAppraisalTemplateKpa.kpaGroupCode");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(new Integer(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmAppTempHdrBean oHrmAppTempHdrBean = (HrmAppTempHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      String sAllFlag = String.valueOf(oHrmAppTempHdrBean.getApplicableToAll()).equalsIgnoreCase("on") ? "Y" : "N";
      String sObsoleteFlag = String.valueOf(oHrmAppTempHdrBean.getObsolete()).equalsIgnoreCase("on") ? "Y" : "N";
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "N"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmAppTempHdrBean.getRatingId()));
      arylstParam.add(new DBObject(3, 1, 12, oHrmAppTempHdrBean.getTemplateName()));
      arylstParam.add(new DBObject(4, 1, 12, sAllFlag));
      arylstParam.add(new DBObject(5, 1, 12, sObsoleteFlag));
      arylstParam.add(new DBObject(6, 1, 12, this.oUserInfo.getUserId()));
      arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(8, 1, 12, null));
      arylstParam.add(new DBObject(9, 2, 12));
      arylstParam.add(new DBObject(10, 2, 12));
      arylstParam.add(new DBObject(11, 2, 12));
      arylstParam.add(new DBObject(12, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procUpsertHrmAprslTmplHdr(?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      String sAllFlag = String.valueOf(oHrmAppTempHdrBean.getApplicableToAll()).equalsIgnoreCase("on") ? "Y" : "N";
      String sObsoleteFlag = String.valueOf(oHrmAppTempHdrBean.getObsolete()).equalsIgnoreCase("on") ? "Y" : "N";
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "U"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmAppTempHdrBean.getRatingId()));
      arylstParam.add(new DBObject(3, 1, 12, oHrmAppTempHdrBean.getTemplateName()));
      arylstParam.add(new DBObject(4, 1, 12, sAllFlag));
      arylstParam.add(new DBObject(5, 1, 12, sObsoleteFlag));
      arylstParam.add(new DBObject(6, 1, 12, this.oUserInfo.getUserId()));
      arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(8, 1, 12, oHrmAppTempHdrBean.getHeaderPrimaryKey()));
      arylstParam.add(new DBObject(9, 2, 12));
      arylstParam.add(new DBObject(10, 2, 12));
      arylstParam.add(new DBObject(11, 2, 12));
      arylstParam.add(new DBObject(12, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procUpsertHrmAprslTmplHdr(?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } 
    return returnString;
  }
  
  public String getSumWt(String sTmplHdrId, String sTab, String sParentId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    String sSumSecWt = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sTmplHdrId));
    arylstParam.add(new DBObject(2, 1, 12, sTab));
    arylstParam.add(new DBObject(3, 1, 12, sParentId));
    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 arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetSumWt(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    if (arylstParam.size() == 0);
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstParam.iterator();
    while (itrBean.hasNext()) {
      oRow = (QueryRow)itrBean.next();
      sSumSecWt = oRow.get("SUM").getString();
    } 
    return sSumSecWt;
  }
  
  public String getWtValInfo(String sTmplHdrId, String sDetailId, String sTab, String sParentId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    String sSecWt = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sTmplHdrId));
    arylstParam.add(new DBObject(2, 1, 12, sDetailId));
    arylstParam.add(new DBObject(3, 1, 12, sTab));
    arylstParam.add(new DBObject(4, 1, 12, sParentId));
    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 arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetWtInfo(?,?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    if (arylstParam.size() == 0);
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstParam.iterator();
    while (itrBean.hasNext()) {
      oRow = (QueryRow)itrBean.next();
      sSecWt = oRow.get("WEIGHTAGE").getString();
    } 
    return sSecWt;
  }
  
  public void updateSecWt(String sParentId, String sValue, String sHdrId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sParentId));
    arylstParam.add(new DBObject(2, 1, 12, sValue));
    arylstParam.add(new DBObject(3, 1, 12, sHdrId));
    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, "HRMAPRSLTMPLMST.upSecWt(?,?,?,?,?,?)");
  }
  
  public void updateKPAWt(String sTmplHdrId, String sValue) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sTmplHdrId));
    arylstParam.add(new DBObject(2, 1, 12, sValue));
    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, "HRMAPRSLTMPLMST.upKPAWt(?,?,?,?,?)");
  }
  
  public ArrayList getParentSecIdInfo() throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstParentSecId = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 2, -10));
    arylstParam.add(new DBObject(2, 2, 12));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procGetParentSecIdInfo(?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    if (arylstParam.size() == 0)
      arylstParentSecId = new ArrayList(); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstParam.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstParentSecId = new ArrayList(); 
      count++;
      oRow = (QueryRow)itrBean.next();
      HrmAppraisalTemplateSecDtlBean oHrmAppraisalTemplateSecDtlBean = new HrmAppraisalTemplateSecDtlBean();
      oHrmAppraisalTemplateSecDtlBean.setTxtParentSecId(oRow.get("PARENT_SEC_ID").getString());
      arylstParentSecId.add(oHrmAppraisalTemplateSecDtlBean);
    } 
    return arylstParentSecId;
  }
  
  public RecordMetaInfo getParentIdDetailMetaInfo(String sParentId, String shdrId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sParentId));
    arylstParam.add(new DBObject(2, 1, 12, shdrId));
    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 arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.procParentIdDtlCount(?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public 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 {
    String sSecSum = null;
    float secSum = 0.0F;
    float kpaSum = 0.0F;
    float secParentSum = 0.0F;
    String sSecSumVal = null;
    float secSumVal = 0.0F;
    float kpaSumVal = 0.0F;
    float secParentSumVal = 0.0F;
    float upCount = 0.0F;
    String sFlag = null;
    String sFlag1 = null;
    String sUpvalue = null;
    int count = 0;
    ArrayList oList = new ArrayList();
    HrmAppTempHdrBean oHrmAppTempHdrBean = (HrmAppTempHdrBean)oBaseHeaderBean;
    if (sScreenMode.equalsIgnoreCase("N"))
      checkUniqueTemp(oHrmAppTempHdrBean, oList); 
    String sum1 = getSumWt(oHrmAppTempHdrBean.getHeaderPrimaryKey(), "S", "");
    if (!EnrgiseUtil.checkString(sum1)) {
      secSum = 0.0F;
    } else {
      secSum = Float.parseFloat(sum1);
    } 
    String sum2 = getSumWt(oHrmAppTempHdrBean.getHeaderPrimaryKey(), "K", "");
    if (!EnrgiseUtil.checkString(sum2)) {
      kpaSum = 0.0F;
    } else {
      kpaSum = Float.parseFloat(sum2);
    } 
    if (bDetailDataChanged) {
      if (sScreenName.equalsIgnoreCase("HrmAppraisalTemplateSection")) {
        EnrgiseUtil.checkDuplicate(oDetailBeanArray, "txtSrlNo", "hrm.HrmAppraisalTemplate.srlNo", oList, true);
        EnrgiseUtil.checkDuplicate(oDetailBeanArray, "txtSectionCode", "hrm.HrmAppraisalTemplate.sectionCode", oList, true);
        Iterator oIt = oDetailBeanArray.iterator();
        while (oIt.hasNext()) {
          HrmAppraisalTemplateSecDtlBean oHrmAppraisalTemplateSecDtlBean = oIt.next();
          System.out.println(oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId());
          if (oHrmAppraisalTemplateSecDtlBean.getStatus().equalsIgnoreCase("U"))
            if (!EnrgiseUtil.checkString(oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId())) {
              String sWt1 = getWtValInfo(oHrmAppTempHdrBean.getHeaderPrimaryKey(), oHrmAppraisalTemplateSecDtlBean.getDetailId(), "S", "");
              if (EnrgiseUtil.checkString(sWt1))
                secSumVal = Float.parseFloat(sWt1); 
              if (EnrgiseUtil.checkString(oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage())) {
                secSum = secSum - secSumVal + Float.parseFloat(oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage());
              } else {
                secSum -= secSumVal;
                sFlag = "true";
              } 
              if (secSum == false || secSum < false) {
                RecordMetaInfo oRecordMetaInfo = getParentIdDetailMetaInfo("", oHrmAppTempHdrBean.getHeaderPrimaryKey());
                upCount = Float.parseFloat(String.valueOf(oRecordMetaInfo.getRecordCount()));
                sUpvalue = String.valueOf(100 / upCount);
                updateSecWt("", sUpvalue, oHrmAppTempHdrBean.getHeaderPrimaryKey());
                sFlag = "false";
              } 
            } else {
              if (count == 0)
                secParentSum = Float.parseFloat(getSumWt(oHrmAppTempHdrBean.getHeaderPrimaryKey(), "SP", oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId())); 
              ArrayList arylstParentId = getParentSecIdInfo();
              Iterator oIt1 = arylstParentId.iterator();
              while (oIt1.hasNext()) {
                HrmAppraisalTemplateSecDtlBean oHrmAppraisalTemplateSecDtlBean1 = oIt1.next();
                System.out.println(oHrmAppraisalTemplateSecDtlBean1.getTxtParentSecId());
                if (oHrmAppraisalTemplateSecDtlBean1.getTxtParentSecId().equals(oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId())) {
                  secParentSumVal = Float.parseFloat(getWtValInfo(oHrmAppTempHdrBean.getHeaderPrimaryKey(), oHrmAppraisalTemplateSecDtlBean.getDetailId(), "SP", oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId()));
                  if (EnrgiseUtil.checkString(oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage())) {
                    secParentSum = secParentSum - secParentSumVal + Float.parseFloat(oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage());
                  } else {
                    secParentSum -= secParentSumVal;
                    sFlag = "true";
                    count++;
                  } 
                  if (secParentSum == false || secParentSum < false) {
                    RecordMetaInfo oRecordMetaInfo = getParentIdDetailMetaInfo(oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId(), oHrmAppTempHdrBean.getHeaderPrimaryKey());
                    upCount = Float.parseFloat(String.valueOf(oRecordMetaInfo.getRecordCount()));
                    System.out.println(upCount);
                    sUpvalue = String.valueOf(100 / upCount);
                    updateSecWt(oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId(), sUpvalue, oHrmAppTempHdrBean.getHeaderPrimaryKey());
                    sFlag = "false";
                  } 
                } 
              } 
            }  
          if (oHrmAppraisalTemplateSecDtlBean.getStatus().equalsIgnoreCase("N")) {
            if (!EnrgiseUtil.checkString(oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId())) {
              if (EnrgiseUtil.checkString(oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage())) {
                secSum += Float.parseFloat(oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage());
                if (secSum > 100)
                  oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.value")); 
                continue;
              } 
              if (secSum > false)
                oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.enter")); 
              continue;
            } 
            String sSum = getSumWt(oHrmAppTempHdrBean.getHeaderPrimaryKey(), "SP", oHrmAppraisalTemplateSecDtlBean.getTxtParentSecId());
            if (!EnrgiseUtil.checkString(sSum)) {
              secParentSum = 0.0F;
            } else {
              secParentSum = Float.parseFloat(sSum);
            } 
            if (EnrgiseUtil.checkString(oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage())) {
              secParentSum += Float.parseFloat(oHrmAppraisalTemplateSecDtlBean.getTxtSectionWeightage());
              if (secParentSum > 100)
                oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.value")); 
              continue;
            } 
            if (secParentSum > false)
              oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.enter")); 
          } 
        } 
        if (EnrgiseUtil.checkString(sFlag))
          if (sFlag.equalsIgnoreCase("true"))
            oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.enter"));  
        if (secSum > 100)
          oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.value")); 
        if (secParentSum > 100)
          oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.value")); 
      } 
      if (sScreenName.equalsIgnoreCase("HrmAppraisalTemplateKPA")) {
        EnrgiseUtil.checkDuplicate(oDetailBeanArray, "txtKpaGroupCode", "hrm.HrmAppraisalTemplateKpa.kpaGroupCode", oList, true);
        Iterator oIt = oDetailBeanArray.iterator();
        while (oIt.hasNext()) {
          HrmAppraisalTemplateKpaDtlBean oHrmAppraisalTemplateKpaDtlBean = oIt.next();
          if (oHrmAppraisalTemplateKpaDtlBean.getStatus().equalsIgnoreCase("U")) {
            kpaSumVal = Float.parseFloat(getWtValInfo(oHrmAppTempHdrBean.getHeaderPrimaryKey(), oHrmAppraisalTemplateKpaDtlBean.getDetailId(), "K", ""));
            if (EnrgiseUtil.checkString(oHrmAppraisalTemplateKpaDtlBean.getTxtWeightage())) {
              kpaSum = kpaSum - kpaSumVal + Float.parseFloat(oHrmAppraisalTemplateKpaDtlBean.getTxtWeightage());
            } else {
              kpaSum -= kpaSumVal;
              sFlag1 = "true";
            } 
            if (kpaSum == false || kpaSum < false) {
              RecordMetaInfo oRecordMetaInfo = getAppTempSecKPADetailMetaInfo(oHrmAppTempHdrBean.getHeaderPrimaryKey());
              upCount = Float.parseFloat(String.valueOf(oRecordMetaInfo.getRecordCount()));
              sUpvalue = String.valueOf(100 / upCount);
              updateKPAWt(oHrmAppTempHdrBean.getHeaderPrimaryKey(), sUpvalue);
              sFlag1 = "false";
            } 
          } 
          if (oHrmAppraisalTemplateKpaDtlBean.getStatus().equalsIgnoreCase("N")) {
            if (EnrgiseUtil.checkString(oHrmAppraisalTemplateKpaDtlBean.getTxtWeightage())) {
              kpaSum += Float.parseFloat(oHrmAppraisalTemplateKpaDtlBean.getTxtWeightage());
              if (kpaSum > 100)
                oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.value")); 
              continue;
            } 
            if (kpaSum > false)
              oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.enter")); 
          } 
        } 
        if (EnrgiseUtil.checkString(sFlag1))
          if (sFlag1.equalsIgnoreCase("true"))
            oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.enter"));  
        if (kpaSum > 100)
          oList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.wt.value")); 
      } 
    } 
    reportError(oList);
  }
  
  private void checkUniqueTemp(HrmAppTempHdrBean oHrmAppTempHdrBean, ArrayList oErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    long lNoTmpl = 0L;
    oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmAppTempHdrBean.getTemplateName()));
    oParameters.add(new DBObject(2, 2, -5));
    oParameters.add(new DBObject(3, 2, 12));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMAPRSLTMPLMST.procGetTempNameCount(?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    lNoTmpl = ((Long)oOutObject.getObject()).longValue();
    if (lNoTmpl > 0L) {
      ArrayList oParams = new ArrayList();
      oErrorList.add(new EnrgiseMessageKeyException("hrm.Temp.Unique.Data", oParams, "E"));
    } 
  }
  
  public String approveHrmAprslTmpMst(BaseHeaderBean oBaseHeaderBean, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sFlagSec = null;
    String sFlagKpa = null;
    ArrayList oErrorList = new ArrayList();
    sFlagSec = checkSecWeightageValidation(oBaseHeaderBean.getHeaderPrimaryKey(), oErrorList);
    sFlagKpa = checkKpaWeightageValidation(oBaseHeaderBean.getHeaderPrimaryKey(), oErrorList);
    reportError(oErrorList);
    if (EnrgiseUtil.checkString(sFlagSec) && EnrgiseUtil.checkString(sFlagKpa))
      if (sFlagSec.equalsIgnoreCase("1") || sFlagKpa.equalsIgnoreCase("1"))
        updateTemFlag(oBaseHeaderBean.getHeaderPrimaryKey());  
    return oBaseHeaderBean.getHeaderPrimaryKey();
  }
  
  public RecordMetaInfo getHrmAprslTmpMstSecCount(String sParentId, String sHdrId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sParentId));
    arylstParam.add(new DBObject(2, 1, 12, sHdrId));
    arylstParam.add(new DBObject(3, 2, -5));
    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, "HRMAPRSLTMPLMST.proc_UpProperWtg(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    return oRecordMetaInfo;
  }
  
  public String checkSecWeightageValidation(String sHeaderPrimKey, ArrayList oErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    int count = 0;
    long lWeightage = 0L;
    String sParentId = null;
    String sWtg = null;
    String sSecFlag = null;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, sHeaderPrimKey));
    oParameters.add(new DBObject(2, 2, -10));
    oParameters.add(new DBObject(3, 2, 12));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMAPRSLTMPLMST.proc_ProperWtg(?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    if (oList.size() != 0) {
      Iterator iter = oList.iterator();
      while (iter.hasNext()) {
        if (count == 0)
          oList = new ArrayList(); 
        count++;
        oRow = iter.next();
        sParentId = oRow.get("parent_sec_id").getString();
        sWtg = oRow.get("totWtg").getString();
        if (EnrgiseUtil.checkString(sWtg)) {
          lWeightage = Long.parseLong(sWtg);
          if (lWeightage != 100L && lWeightage > 0L)
            oErrorList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.sec.wt.exact.value")); 
          if (lWeightage == 0L) {
            RecordMetaInfo oRecordMetaInfo = getHrmAprslTmpMstSecCount(sParentId, sHeaderPrimKey);
            float upCount = Float.parseFloat(String.valueOf(oRecordMetaInfo.getRecordCount()));
            String sUpvalue = String.valueOf(100 / upCount);
            updateSecWt(sParentId, sUpvalue, sHeaderPrimKey);
          } 
        } 
      } 
    } 
    if (oErrorList.size() == 0) {
      sSecFlag = "1";
    } else {
      sSecFlag = "0";
    } 
    return sSecFlag;
  }
  
  public String checkKpaWeightageValidation(String sHeaderPrimKey, ArrayList oErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    int count = 0;
    long lWeightage = 0L;
    String sWtg = null;
    String sKpaFlag = null;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, sHeaderPrimKey));
    oParameters.add(new DBObject(2, 2, -10));
    oParameters.add(new DBObject(3, 2, 12));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMAPRSLTMPLMST.proc_ProperWtgKPA(?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    if (oList.size() != 0) {
      Iterator iter = oList.iterator();
      while (iter.hasNext()) {
        if (count == 0)
          oList = new ArrayList(); 
        count++;
        oRow = iter.next();
        sWtg = oRow.get("totWtg").getString();
        if (EnrgiseUtil.checkString(sWtg)) {
          lWeightage = Long.parseLong(sWtg);
          if (lWeightage != 100L && lWeightage > 0L)
            oErrorList.add(new EnrgiseApplicationException("wenrgise.hrms.aprsl.kpa.wt.exact.value")); 
          if (lWeightage == 0L) {
            RecordMetaInfo oRecordMetaInfo = getAppTempSecKPADetailMetaInfo(sHeaderPrimKey);
            float upCount = Float.parseFloat(String.valueOf(oRecordMetaInfo.getRecordCount()));
            String sUpvalue = String.valueOf(100 / upCount);
            updateKPAWt(sHeaderPrimKey, sUpvalue);
          } 
        } 
      } 
    } 
    if (oErrorList.size() == 0) {
      sKpaFlag = "1";
    } else {
      sKpaFlag = "0";
    } 
    return sKpaFlag;
  }
  
  public LovVO getHrmAprslTempNameQLOV(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("hrm.HrmAppraisalTemplateKpa.templateCode");
    arylstHeaderNames.add("hrm.HrmAppraisalTemplateKpa.templateName");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, oLovQueryVO.getSearchField1()));
    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, "HRMAPRSLLOV.proc_GetAprslTempNameQLOV(?,?,?,?,?)");
    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("Code").getString());
      oLOVBean.setDetailField2(oRow.get("TempName").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getAprslTmplRatingCodeQLOV(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("Code ID");
    arylstHeaderList.add("hrm.HrmAppraisalTemplateKpa.ratingCode");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    String sID = oLovQueryVO.getProperty("TmplId");
    int count = 0;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oLovQueryVO.getSearchField1()));
    oParameters.add(new DBObject(2, 1, 12, sID));
    oParameters.add(new DBObject(3, 2, -10));
    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, "HRMAPRSLLOV.proc_GetAprslTempRatCodeQLOV(?,?,?,?,?,?)");
    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());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public void updateTemFlag(String sHdrId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sHdrId));
    arylstParam.add(new DBObject(2, 2, 12));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMAPRSLTMPLMST.upTmplFlag(?,?,?,?)");
  }
}
