package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.text.DateFormat;
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.HrmPrmNoticeDtlDtlBean;
import wenrgise.hrms.bean.HrmPrmNoticeDtlHdrBean;
import wenrgise.hrms.vo.HrmPrmNoticeDtlQVO;

public class HrmPrmNoticeDtlBO extends HrmBaseBO {
  public HrmPrmNoticeDtlBO() {}
  
  public HrmPrmNoticeDtlBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public LovVO getNoticeNoLOVData(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("");
    arylstHeaderList.add("hrm.HrmPrmNotice.noticeNo");
    arylstHeaderList.add("hrm.HrmPrmNotice.noticeDate");
    arylstHeaderList.add("hrm.HrmPrmNotice.desc");
    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, "HRMPRMNOTICEDTL.proc_GetNoticeNoLOVQuery(?,?,?,?,?)");
    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("NOTICE_NO").getString());
      oLOVBean.setDetailField3(EnrgiseUtil.convertToString(oRow.get("NOTICE_DATE").getDate()));
      oLOVBean.setDetailField4(oRow.get("DESCRIPTION").getString());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
  
  public LovVO getPositionNoLOVData(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("");
    arylstHeaderList.add("hrm.HrmPrmNotice.txtPositionCode");
    arylstHeaderList.add("hrm.HrmPrmNotice.txtDesignation");
    arylstHeaderList.add("hrm.HrmPrmNotice.txtScale");
    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, "HRMPRMNOTICEDTL.proc_GetPosNoLOV(?,?,?,?,?)");
    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("desig_name").getString());
      oLOVBean.setDetailField4(oRow.get("scale_name").getString());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
  
  public RecordMetaInfo getHrmPrmNoticeDtlMetaInfo(HrmPrmNoticeDtlQVO oHrmPrmNoticeDtlQVO) 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, oHrmPrmNoticeDtlQVO.getHeaderPrimaryKey()));
    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, "HRMPRMNOTICEDTL.proc_PromNoticeHdrCount(?,?,?,?,?,?)");
    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 getHrmPrmNoticeDtlHdrInfo(HrmPrmNoticeDtlQVO oHrmPrmNoticeDtlQVO, 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 (oHrmPrmNoticeDtlQVO == null)
      oHrmPrmNoticeDtlQVO = new HrmPrmNoticeDtlQVO(); 
    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, oHrmPrmNoticeDtlQVO.getHeaderPrimaryKey()));
    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, "HRMPRMNOTICEDTL.proc_PromNoticeHdrInfo(?,?,?,?,?,?,?)");
    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();
      HrmPrmNoticeDtlHdrBean oHrmPrmNoticeDtlHdrBean = new HrmPrmNoticeDtlHdrBean();
      oHrmPrmNoticeDtlHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmPrmNoticeDtlHdrBean.setNoticeId(oRow.get("ID").getString());
      oHrmPrmNoticeDtlHdrBean.setNoticeNo(oRow.get("NOTICE_NO").getString());
      oHrmPrmNoticeDtlHdrBean.setNoticeDate(EnrgiseUtil.convertToString(oRow.get("NOTICE_DATE").getDate()));
      oHrmPrmNoticeDtlHdrBean.setDesc(oRow.get("DESCRIPTION").getString());
      oHeaderList.add(oHrmPrmNoticeDtlHdrBean);
    } 
    return oHeaderList;
  }
  
  public RecordMetaInfo getPrmNoticeDtlMetaInfo(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, "HRMPRMNOTICEDTL.proc_PromNoticeDtlCount(?,?,?,?,?,?)");
    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 getPrmNoticeDtlInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmPrmNoticeDtl = 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, "HRMPRMNOTICEDTL.proc_PromNoticeDtlInfo(?,?,?,?,?,?,?)");
    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)
        arylstHrmPrmNoticeDtl = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmPrmNoticeDtlDtlBean oHrmPrmNoticeDtlDtlBean = new HrmPrmNoticeDtlDtlBean();
      oHrmPrmNoticeDtlDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmPrmNoticeDtlDtlBean.setTxtGradeId(oRow.get("grade_id").getString());
      oHrmPrmNoticeDtlDtlBean.setTxtGrade(oRow.get("gradeDesc").getString());
      oHrmPrmNoticeDtlDtlBean.setTxtDesigId(oRow.get("designation_id").getString());
      oHrmPrmNoticeDtlDtlBean.setTxtDesignation(oRow.get("desigDesc").getString());
      oHrmPrmNoticeDtlDtlBean.setTxtVacancies(oRow.get("no_of_vacancies").getString());
      oHrmPrmNoticeDtlDtlBean.setTxtExamDate(EnrgiseUtil.convertToString(oRow.get("interview_date").getDate()));
      arylstHrmPrmNoticeDtl.add(oHrmPrmNoticeDtlDtlBean);
    } 
    return arylstHrmPrmNoticeDtl;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "hrm_advt_hdr";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    saveNoticeDtl(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();
    HrmPrmNoticeDtlHdrBean oHrmPrmNoticeDtlHdrBean = (HrmPrmNoticeDtlHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      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, oHrmPrmNoticeDtlHdrBean.getNoticeNo()));
      oParameters.add(new DBObject(4, 1, 12, oHrmPrmNoticeDtlHdrBean.getNoticeDate()));
      oParameters.add(new DBObject(5, 1, 12, oHrmPrmNoticeDtlHdrBean.getDesc()));
      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()));
      oParameters.add(new DBObject(9, 2, 12));
      oParameters.add(new DBObject(10, 2, 12));
      oParameters.add(new DBObject(11, 2, 12));
      oParameters.add(new DBObject(12, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMNOTICEDTL.proc_UpsertPromNoticeHdr(?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      oParameters = new ArrayList();
      oParameters.add(new DBObject(1, 1, 12, "U"));
      oParameters.add(new DBObject(2, 1, 12, oHrmPrmNoticeDtlHdrBean.getHeaderPrimaryKey()));
      oParameters.add(new DBObject(3, 1, 12, oHrmPrmNoticeDtlHdrBean.getNoticeNo()));
      oParameters.add(new DBObject(4, 1, 12, oHrmPrmNoticeDtlHdrBean.getNoticeDate()));
      oParameters.add(new DBObject(5, 1, 12, oHrmPrmNoticeDtlHdrBean.getDesc()));
      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()));
      oParameters.add(new DBObject(9, 2, 12));
      oParameters.add(new DBObject(10, 2, 12));
      oParameters.add(new DBObject(11, 2, 12));
      oParameters.add(new DBObject(12, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMNOTICEDTL.proc_UpsertPromNoticeHdr(?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
    } else if (ScreenMode.equalsIgnoreCase("D")) {
      oParameters = new ArrayList();
      oParameters.add(new DBObject(1, 1, 12, oHrmPrmNoticeDtlHdrBean.getHeaderPrimaryKey()));
      oParameters.add(new DBObject(2, 2, 12));
      oParameters.add(new DBObject(3, 2, 12));
      oParameters.add(new DBObject(4, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMPRMNOTICEDTL.proc_DeletePromNoticeHdr(?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = null;
    } 
    return returnString;
  }
  
  private void saveNoticeDtl(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()) {
      HrmPrmNoticeDtlDtlBean oHrmPrmNoticeDtlDtlBean = oIt.next();
      if (oHrmPrmNoticeDtlDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMNOTICEDTL.proc_UpsertPromNoticeDtl(?,?,?,?,?,?,?,?,?,?)");
          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, oHrmPrmNoticeDtlDtlBean.getTxtGradeId()));
        oParameters.add(new DBObject(4, 1, 12, oHrmPrmNoticeDtlDtlBean.getTxtDesigId()));
        oParameters.add(new DBObject(5, 1, 12, oHrmPrmNoticeDtlDtlBean.getTxtVacancies()));
        oParameters.add(new DBObject(6, 1, 12, oHrmPrmNoticeDtlDtlBean.getTxtExamDate()));
        oParameters.add(new DBObject(7, 1, 12, sHeaderPrimaryKey));
        oParameters.add(new DBObject(8, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(9, 1, 12, this.oUserInfo.getUserId()));
        oParameters.add(new DBObject(10, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(oParameters);
        continue;
      } 
      if (oHrmPrmNoticeDtlDtlBean.getStatus().equals("U")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMPRMNOTICEDTL.proc_UpsertPromNoticeDtl(?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "U"));
        oParameters.add(new DBObject(2, 1, 12, oHrmPrmNoticeDtlDtlBean.getDetailId()));
        oParameters.add(new DBObject(3, 1, 12, oHrmPrmNoticeDtlDtlBean.getTxtGradeId()));
        oParameters.add(new DBObject(4, 1, 12, oHrmPrmNoticeDtlDtlBean.getTxtDesigId()));
        oParameters.add(new DBObject(5, 1, 12, oHrmPrmNoticeDtlDtlBean.getTxtVacancies()));
        oParameters.add(new DBObject(6, 1, 12, oHrmPrmNoticeDtlDtlBean.getTxtExamDate()));
        oParameters.add(new DBObject(7, 1, 12, sHeaderPrimaryKey));
        oParameters.add(new DBObject(8, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(9, 1, 12, this.oUserInfo.getUserId()));
        oParameters.add(new DBObject(10, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(oParameters);
        continue;
      } 
      if (oHrmPrmNoticeDtlDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMPRMNOTICEDTL.proc_DeletePromNoticeDtl(?)");
          bDelete = true;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, oHrmPrmNoticeDtlDtlBean.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((HrmPrmNoticeDtlHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmPrmNoticeDtl")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int rowCount = 1;
        while (oIt1.hasNext()) {
          HrmPrmNoticeDtlDtlBean oHrmPrmNoticeDtlDtlBean = oIt1.next();
          if (!oHrmPrmNoticeDtlDtlBean.getStatus().equalsIgnoreCase("D")) {
            checkMandatoryDtls(oHrmPrmNoticeDtlDtlBean, rowCount);
            rowCount++;
          } 
        } 
      }  
  }
  
  private void checkMandatoryHeader(HrmPrmNoticeDtlHdrBean oHrmPrmNoticeDtlHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oList = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmPrmNoticeDtlHdrBean.getNoticeNo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmNotice.noticeNo");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParam, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmPrmNoticeDtlHdrBean.getNoticeDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmNotice.noticeDate");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParam, "E"));
    } 
    reportError(oList);
  }
  
  private void checkUniquePoswiseDtl(String sHeaderPrimaryKey, ArrayList oDetailBeanArray, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  private void checkUniqueDtl(String sHeaderPrimaryKey, ArrayList oDetailBeanArray, ArrayList oErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    int count = 1;
    Iterator oIt1 = oDetailBeanArray.iterator();
    while (oIt1.hasNext()) {
      HrmPrmNoticeDtlDtlBean oHrmPrmNoticeDtlDtlBean = oIt1.next();
      String sQuery = String.valueOf(String.valueOf(String.valueOf(String.valueOf(String.valueOf(String.valueOf(" Select ID from HRM_PROM_NTC_DTL where prom_ntchd_id='").concat(String.valueOf(sHeaderPrimaryKey))).concat(String.valueOf("' and grade_id='"))).concat(String.valueOf(oHrmPrmNoticeDtlDtlBean.getTxtGradeId()))).concat(String.valueOf("' and designation_id='"))).concat(String.valueOf(oHrmPrmNoticeDtlDtlBean.getTxtDesigId()))).concat(String.valueOf("'"));
      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(oHrmPrmNoticeDtlDtlBean.getDetailId())) {
          ArrayList oParams = new ArrayList();
          MessageKey oMessageKey1 = new MessageKey("hrm.HrmPrmNotice.txtGrade");
          MessageKey oMessageKey2 = new MessageKey("hrm.HrmPrmNotice.txtDesignation");
          oParams.add(oMessageKey1);
          oParams.add(oMessageKey2);
          oParams.add(new Integer(count));
          oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.prmnotdetail.uniqueKeyViolated", oParams, "E"));
        } 
      } 
      count++;
    } 
    reportError(oErrorList);
  }
  
  private void checkMandatoryDtls(HrmPrmNoticeDtlDtlBean oHrmPrmNoticeDtlDtlBean, int rowCount) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmPrmNoticeDtlDtlBean.getTxtGrade())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmNotice.txtGrade");
      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(oHrmPrmNoticeDtlDtlBean.getTxtVacancies())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmNotice.txtVacancies");
      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(oHrmPrmNoticeDtlDtlBean.getTxtExamDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmPrmNotice.txtExamDate");
      ArrayList oParam = new ArrayList();
      oParam.add(oMessageKey);
      oParam.add(new Integer(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParam, "E"));
    } 
    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 {
    HrmPrmNoticeDtlHdrBean oHrmPrmNoticeDtlHdrBean = (HrmPrmNoticeDtlHdrBean)oBaseHeaderBean;
    ArrayList oErrorList = new ArrayList();
    if (bDetailDataChanged) {
      if (sScreenName.equalsIgnoreCase("HrmPrmNoticeDtl")) {
        Iterator oIt1 = oDetailBeanArray.iterator();
        int rowcount = 1;
        while (oIt1.hasNext()) {
          HrmPrmNoticeDtlDtlBean oHrmPrmNoticeDtlDtlBean = oIt1.next();
          if (!oHrmPrmNoticeDtlDtlBean.getStatus().equalsIgnoreCase("D")) {
            checkDates(oHrmPrmNoticeDtlHdrBean, oDetailBeanArray);
            checkUniqueDtl(oHrmPrmNoticeDtlHdrBean.getHeaderPrimaryKey(), oDetailBeanArray, oErrorList);
          } 
        } 
      } 
      reportError(oErrorList);
    } 
  }
  
  private void checkDates(HrmPrmNoticeDtlHdrBean oHrmPrmNoticeDtlHdrBean, ArrayList oDetailBeanArray) throws EnrgiseApplicationException, EnrgiseSystemException {
    int rowCount = 1;
    Iterator oIt = oDetailBeanArray.iterator();
    if (oIt.hasNext()) {
      HrmPrmNoticeDtlDtlBean oHrmPrmNoticeDtlDtlBean = oIt.next();
      DateFormat oDateFormat = null;
      int i = EnrgiseUtil.compareDates(oDateFormat, oHrmPrmNoticeDtlDtlBean.getTxtExamDate(), oHrmPrmNoticeDtlHdrBean.getNoticeDate());
      System.out.println(i);
      if (i < 0) {
        ArrayList oParams = new ArrayList();
        oParams.add(new Integer(rowCount));
        throw new EnrgiseApplicationException("hrm.HrmPrmNotice.detail.date", oParams, "E");
      } 
      rowCount++;
    } 
  }
  
  public LovVO getPromNotGradeNLOVData(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.gradeName");
    oHeaderList.add("hrm.HrmPrmOrder.gradeCode");
    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("name").getString());
      oLOVBean.setDetailField3(oRow.get("code").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public LovVO getPromNotDesignationNLOVData(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.desigName");
    oHeaderList.add("hrm.HrmPrmOrder.desigCode");
    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("name").getString());
      oLOVBean.setDetailField3(oRow.get("code").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
}
