package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.bean.LOVBean;
import wenrgise.common.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.HrmTrngCalDtlBean;
import wenrgise.hrms.bean.HrmTrngCalHdrBean;
import wenrgise.hrms.vo.HrmTrngCalQVO;

public class HrmTrngCalBO extends HrmBaseBO {
  public HrmTrngCalBO() {}
  
  public HrmTrngCalBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmTrngCalHdrMetaInfo(HrmTrngCalQVO oHrmTrngCalQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    String oStr = oHrmTrngCalQVO.getStartDate();
    String oStr1 = oHrmTrngCalQVO.getEndDate();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, oHrmTrngCalQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmTrngCalQVO.getCalendarName()));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmTrngCalQVO.getSite()));
    arylstParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oStr)));
    arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oStr1)));
    arylstParameters.add(new DBObject(6, 2, -5));
    arylstParameters.add(new DBObject(7, 2, 93));
    arylstParameters.add(new DBObject(8, 2, 12));
    arylstParameters.add(new DBObject(9, 2, 12));
    arylstParameters.add(new DBObject(10, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_HrTrngCalHdrCount(?,?,?,?,?,?,?,?,?,?)");
    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 getHrmTrngCalHeaderInfo(HrmTrngCalQVO oHrmTrngCalQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    ArrayList arylstHeaderList = null;
    if (oHrmTrngCalQVO == null)
      oHrmTrngCalQVO = new HrmTrngCalQVO(); 
    String oStr = oHrmTrngCalQVO.getStartDate();
    String oStr1 = oHrmTrngCalQVO.getEndDate();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmTrngCalQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmTrngCalQVO.getCalendarName()));
    arylstParameters.add(new DBObject(5, 1, 12, oHrmTrngCalQVO.getSite()));
    arylstParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oStr)));
    arylstParameters.add(new DBObject(7, 1, 93, EnrgiseUtil.convertToSqlDate(oStr1)));
    arylstParameters.add(new DBObject(8, 2, -10));
    arylstParameters.add(new DBObject(9, 2, 12));
    arylstParameters.add(new DBObject(10, 2, 12));
    arylstParameters.add(new DBObject(11, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_GetHrTrngCal(?,?,?,?,?,?,?,?,?,?,?)");
    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 itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHeaderList = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngCalHdrBean oTrngCalHeader = new HrmTrngCalHdrBean();
      oTrngCalHeader.setHeaderPrimaryKey(oRow.get("ID").getString());
      oTrngCalHeader.setSiteId(oRow.get("SITE_ID").getString());
      oTrngCalHeader.setCalendarName(oRow.get("NAME").getString());
      oTrngCalHeader.setSite(oRow.get("CODE").getString());
      oTrngCalHeader.setSiteName(oRow.get("SITE_NAME").getString());
      oTrngCalHeader.setStartDate(EnrgiseUtil.convertToString(oRow.get("START_DATE").getDate()));
      oTrngCalHeader.setEndDate(EnrgiseUtil.convertToString(oRow.get("END_DATE").getDate()));
      arylstHeaderList.add(oTrngCalHeader);
    } 
    return arylstHeaderList;
  }
  
  public RecordMetaInfo getHrmTrngCalDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(2, 2, -5));
    arylstParameters.add(new DBObject(3, 2, 93));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_HrTrngCalDtlCount(?,?,?,?,?,?)");
    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 getHrmTrngCalDetailInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmTrngCalDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_GetHrTrngCalDtl(?,?,?,?,?,?,?)");
    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 itrBean = arylstList.iterator();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmTrngCalDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngCalDtlBean oTrngCalDetailBean = new HrmTrngCalDtlBean();
      oTrngCalDetailBean.setDetailId(oRow.get("ID").getString());
      oTrngCalDetailBean.setTxtType(oRow.get("TYPE_TYPE").getString());
      oTrngCalDetailBean.setTxtStartDate(EnrgiseUtil.convertToString(oRow.get("START_DATE").getDate()));
      oTrngCalDetailBean.setTxtEndDate(EnrgiseUtil.convertToString(oRow.get("END_DATE").getDate()));
      oTrngCalDetailBean.setTxtDuration(oRow.get("DURATION").getString());
      oTrngCalDetailBean.setTxtStrength(oRow.get("STRENGTH").getString());
      oTrngCalDetailBean.setTxtFee(oRow.get("COURSE_FEE").getString());
      oTrngCalDetailBean.setTxtStatus(oRow.get("STATUS_FLAG").getString());
      oTrngCalDetailBean.setTxtInstId(oRow.get("INST_ID").getString());
      oTrngCalDetailBean.setTxtInstituteName(oRow.get("INST_NAME").getString());
      oTrngCalDetailBean.setTxtCourseId(oRow.get("COURSE_ID").getString());
      oTrngCalDetailBean.setTxtCourseCode(oRow.get("COURSE_CODE").getString());
      oTrngCalDetailBean.setTxtCourseName(oRow.get("COURSE_NAME").getString());
      oTrngCalDetailBean.setRatingId(oRow.get("RATING_HDR_ID").getString());
      oTrngCalDetailBean.setTxtRatingScheme(oRow.get("RATING_CODE").getString());
      oTrngCalDetailBean.setTxtVenue(oRow.get("VENUE").getString());
      arylstHrmTrngCalDetail.add(oTrngCalDetailBean);
    } 
    return arylstHrmTrngCalDetail;
  }
  
  public ArrayList getHrTrngCalDetailByHdrIdCrsId(String sId, String sCrsId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmTrngCalDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sId));
    arylstParameters.add(new DBObject(2, 1, 12, sCrsId));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_GetTrngCalByCrs(?,?,?,?)");
    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 itrBean = arylstList.iterator();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmTrngCalDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngCalDtlBean oTrngCalDetailBean = new HrmTrngCalDtlBean();
      oTrngCalDetailBean.setDetailId(oRow.get("ID").getString());
      oTrngCalDetailBean.setTxtType(oRow.get("TYPE_TYPE").getString());
      String datenewformat = formatter.format(oRow.get("START_DATE").getDate());
      oTrngCalDetailBean.setTxtStartDate(datenewformat);
      String datenewformat1 = formatter.format(oRow.get("END_DATE").getDate());
      oTrngCalDetailBean.setTxtEndDate(datenewformat1);
      oTrngCalDetailBean.setTxtDuration(oRow.get("DURATION").getString());
      oTrngCalDetailBean.setTxtStrength(oRow.get("STRENGTH").getString());
      oTrngCalDetailBean.setTxtFee(oRow.get("COURSE_FEE").getString());
      oTrngCalDetailBean.setTxtStatus(oRow.get("STATUS_FLAG").getString());
      oTrngCalDetailBean.setTxtInstituteName(oRow.get("INST_NAME").getString());
      oTrngCalDetailBean.setTxtCourseCode(oRow.get("COURSE_CODE").getString());
      oTrngCalDetailBean.setTxtCourseName(oRow.get("COURSE_NAME").getString());
      oTrngCalDetailBean.setTxtRatingScheme(oRow.get("RATING_HDR_ID").getString());
      oTrngCalDetailBean.setTxtVenue(oRow.get("VENUE").getString());
      arylstHrmTrngCalDetail.add(oTrngCalDetailBean);
    } 
    return arylstHrmTrngCalDetail;
  }
  
  public ArrayList getHrTrngCalDetailByHdrIdInsId(String sId, String sInsId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmTrngCalDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sId));
    arylstParameters.add(new DBObject(2, 1, 12, sInsId));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_GetTrngCalByIns(?,?,?,?)");
    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 itrBean = arylstList.iterator();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmTrngCalDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngCalDtlBean oTrngCalDetailBean = new HrmTrngCalDtlBean();
      oTrngCalDetailBean.setDetailId(oRow.get("ID").getString());
      oTrngCalDetailBean.setTxtType(oRow.get("TYPE_TYPE").getString());
      String datenewformat = formatter.format(oRow.get("START_DATE").getDate());
      oTrngCalDetailBean.setTxtStartDate(datenewformat);
      String datenewformat1 = formatter.format(oRow.get("END_DATE").getDate());
      oTrngCalDetailBean.setTxtEndDate(datenewformat1);
      oTrngCalDetailBean.setTxtDuration(oRow.get("DURATION").getString());
      oTrngCalDetailBean.setTxtStrength(oRow.get("STRENGTH").getString());
      oTrngCalDetailBean.setTxtFee(oRow.get("COURSE_FEE").getString());
      oTrngCalDetailBean.setTxtStatus(oRow.get("STATUS_FLAG").getString());
      oTrngCalDetailBean.setTxtInstituteName(oRow.get("INST_NAME").getString());
      oTrngCalDetailBean.setTxtCourseCode(oRow.get("COURSE_CODE").getString());
      oTrngCalDetailBean.setTxtCourseName(oRow.get("COURSE_NAME").getString());
      oTrngCalDetailBean.setTxtRatingScheme(oRow.get("RATING_HDR_ID").getString());
      oTrngCalDetailBean.setTxtVenue(oRow.get("VENUE").getString());
      arylstHrmTrngCalDetail.add(oTrngCalDetailBean);
    } 
    return arylstHrmTrngCalDetail;
  }
  
  public ArrayList getHrTrngCalDetailByHdrIdInsCrsId(String sId, String sInsId, String sCrsId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmTrngCalDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sId));
    arylstParameters.add(new DBObject(2, 1, 12, sInsId));
    arylstParameters.add(new DBObject(3, 1, 12, sCrsId));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_GetTrngCalByInsCrs(?,?,?,?,?)");
    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 itrBean = arylstList.iterator();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmTrngCalDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngCalDtlBean oTrngCalDetailBean = new HrmTrngCalDtlBean();
      oTrngCalDetailBean.setDetailId(oRow.get("ID").getString());
      oTrngCalDetailBean.setTxtType(oRow.get("TYPE_TYPE").getString());
      String datenewformat = formatter.format(oRow.get("START_DATE").getDate());
      oTrngCalDetailBean.setTxtStartDate(datenewformat);
      String datenewformat1 = formatter.format(oRow.get("END_DATE").getDate());
      oTrngCalDetailBean.setTxtEndDate(datenewformat1);
      oTrngCalDetailBean.setTxtDuration(oRow.get("DURATION").getString());
      oTrngCalDetailBean.setTxtStrength(oRow.get("STRENGTH").getString());
      oTrngCalDetailBean.setTxtFee(oRow.get("COURSE_FEE").getString());
      oTrngCalDetailBean.setTxtStatus(oRow.get("STATUS_FLAG").getString());
      oTrngCalDetailBean.setTxtInstituteName(oRow.get("INST_NAME").getString());
      oTrngCalDetailBean.setTxtCourseCode(oRow.get("COURSE_CODE").getString());
      oTrngCalDetailBean.setTxtCourseName(oRow.get("COURSE_NAME").getString());
      oTrngCalDetailBean.setRatingId(oRow.get("RATING_HDR_ID").getString());
      oTrngCalDetailBean.setTxtRatingScheme(oRow.get("RATING_CODE").getString());
      oTrngCalDetailBean.setTxtVenue(oRow.get("VENUE").getString());
      arylstHrmTrngCalDetail.add(oTrngCalDetailBean);
    } 
    return arylstHrmTrngCalDetail;
  }
  
  public LovVO getHrmClsCalCrsLOV(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("Course Id");
    arylstHeaderNames.add("Course Code");
    arylstHeaderNames.add("Course Name");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null) {
      sQuerySearch1 = oLovQueryVO.getSearchField1();
      System.out.println(sQuerySearch1);
    } 
    if (oLovQueryVO.getSearchField2() != null) {
      sQuerySearch2 = oLovQueryVO.getSearchField2();
      System.out.println(sQuerySearch2);
    } 
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGLOV.proc_GetTrngCourseLOV(?,?,?,?,?,?)");
    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("COURSE").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmTrngCalInstLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmTrnCal.insCode");
    arylstHeaderList.add("hrm.HrmTrnCal.txtInstituteName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGLOV.proc_GetHrmTrngInsLOVdata(?,?,?,?,?,?)");
    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("INST_CODE").getString());
      oLOVBean.setDetailField3(oRow.get("INST_NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmTrngRatingLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmTrnCal.txtRatingScheme");
    arylstHeaderList.add("hrm.HrmTrnCal.minRating");
    arylstHeaderList.add("hrm.HrmTrnCal.maxRating");
    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 arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 2, -10));
    arylstParameters.add(new DBObject(3, 2, 12));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGLOV.proc_GetHrmRatingLOVdata(?,?,?,?,?)");
    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("min_rating").getString());
      oLOVBean.setDetailField4(oRow.get("max_rating").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmTrngCalCrsCdLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmTrnCal.txtCourseCode");
    arylstHeaderList.add("hrm.HrmTrnCal.courseName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    String instId = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null) {
      sQuerySearch1 = oLovQueryVO.getSearchField1();
      System.out.println(sQuerySearch1);
    } 
    if (oLovQueryVO.getSearchField2() != null) {
      sQuerySearch2 = oLovQueryVO.getSearchField2();
      System.out.println(sQuerySearch2);
    } 
    if (oLovQueryVO.getProperty("txtInstId") != null) {
      instId = oLovQueryVO.getProperty("txtInstId");
      System.out.println(instId);
    } 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParameters.add(new DBObject(3, 1, 12, instId));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGLOV.proc_GetHrmTrngCrsCdLOVdata(?,?,?,?,?,?,?)");
    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("COURSE").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public boolean chkHrmTrnCalHdrByRatingIdCount(String sRatingId) throws EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    boolean flag = true;
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sRatingId));
    arylstParameters.add(new DBObject(2, 2, -5));
    arylstParameters.add(new DBObject(3, 2, 93));
    arylstParameters.add(new DBObject(4, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_HrTrnCalHdrCount(?,?,?,?)");
    DBObject oTotalRecord = arylstOutArray.get(0);
    long count1 = ((Long)oTotalRecord.getObject()).longValue();
    System.out.println(count1);
    if (count1 == 0L)
      flag = false; 
    return flag;
  }
  
  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 arylstList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmTrngCalHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        if (sScreenName.equalsIgnoreCase("HrmTrngCal")) {
          Iterator itrBean1 = arylstDetailBeanArray.iterator();
          int rowCount = 1;
          while (itrBean1.hasNext()) {
            HrmTrngCalDtlBean oHrmTrngCalDtlBean = itrBean1.next();
            if (!oHrmTrngCalDtlBean.getStatus().equalsIgnoreCase("D"))
              checkMandatoryDtls(oHrmTrngCalDtlBean, rowCount); 
          } 
          rowCount++;
        }   
  }
  
  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 arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    if (bDetailDataChanged) {
      HrmTrngCalHdrBean oHrmTrngCalHdrBean = (HrmTrngCalHdrBean)oBaseHeaderBean;
      Iterator itrBean = arylstDetailBeanArray.iterator();
      while (itrBean.hasNext()) {
        HrmTrngCalDtlBean oHrmTrngCalDtlBean = itrBean.next();
        if (oHrmTrngCalDtlBean.getStatus().equals("D")) {
          String sQuery = String.valueOf("select trn_calend_id as checkExist from HRM_TRNG_REQ where trn_calend_id=").concat(String.valueOf(oHrmTrngCalDtlBean.getDetailId()));
          DBUtilitiesBean oBean3 = new DBUtilitiesBean();
          ArrayList arylstList1 = oBean3.executeQuery(sQuery);
          Iterator itrBean1 = arylstList1.iterator();
          String chExist = null;
          if (itrBean1.hasNext()) {
            QueryRow oRow = itrBean1.next();
            chExist = oRow.get("checkExist").getString();
            System.out.println();
          } 
          if (chExist != null)
            arylstErrorList.add(new EnrgiseApplicationException("wenrgise.trngCal.error.empApplied")); 
        } 
      } 
      if (bHeaderDataChanged)
        if (!sScreenMode.equalsIgnoreCase("D"))
          checkDatesConstraint((HrmTrngCalHdrBean)oBaseHeaderBean, arylstErrorList);  
      if (bDetailDataChanged)
        if (!sScreenMode.equalsIgnoreCase("D"))
          checkDatesConstraintForDtl(oHrmTrngCalHdrBean, arylstDetailBeanArray, arylstErrorList);  
    } 
    reportError(arylstErrorList);
  }
  
  private void checkDatesConstraintForDtl(HrmTrngCalHdrBean oHrmTrngCalHdrBean, ArrayList arylstDetailBeanArray, ArrayList arylstErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    int n = arylstDetailBeanArray.size();
    ArrayList arylstParam = new ArrayList();
    Iterator itrBean1 = arylstDetailBeanArray.iterator();
    int rowCount = 1;
    while (itrBean1.hasNext()) {
      HrmTrngCalDtlBean oHrmTrngCalDtlBean = itrBean1.next();
      DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
      int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngCalDtlBean.getTxtStartDate(), oHrmTrngCalHdrBean.getStartDate());
      if (dateFlag == -1 && dateFlag != -2) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.fromCourseDate.dateConstraintViolated", arylstParam));
      } 
      dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngCalDtlBean.getTxtStartDate(), oHrmTrngCalHdrBean.getEndDate());
      if (dateFlag == 1 && dateFlag != -2) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.fromCourseDate.dateConstraintViolated", arylstParam));
      } 
      dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngCalDtlBean.getTxtEndDate(), oHrmTrngCalHdrBean.getStartDate());
      if (dateFlag == -1 && dateFlag != -2) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.toCourseDate.dateConstraintViolated", arylstParam));
      } 
      dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngCalDtlBean.getTxtEndDate(), oHrmTrngCalHdrBean.getEndDate());
      if (dateFlag == 1 && dateFlag != -2) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.toCourseDate.dateConstraintViolated", arylstParam));
      } 
      dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngCalDtlBean.getTxtEndDate(), oHrmTrngCalDtlBean.getTxtStartDate());
      if (dateFlag == -1 && dateFlag != -2) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.toFromDate.dateConstraintViolated", arylstParam));
      } 
    } 
    reportError(arylstErrorList);
  }
  
  private void checkDatesConstraint(HrmTrngCalHdrBean oHrmTrngCalHdrBean, ArrayList arylstErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    if (EnrgiseUtil.checkString(oHrmTrngCalHdrBean.getEndDate())) {
      int iDateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngCalHdrBean.getEndDate(), oHrmTrngCalHdrBean.getStartDate());
      if (iDateFlag == -1 && iDateFlag != -2)
        arylstErrorList.add(new EnrgiseApplicationException("wenrgise.common.dateConstraintViolated")); 
    } 
  }
  
  private void checkMandatoryHeader(HrmTrngCalHdrBean oHrmTrngCalHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmTrngCalHdrBean.getCalendarName())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmTrnCal.calendarName");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngCalHdrBean.getSite())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmTrnCal.site");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngCalHdrBean.getStartDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmTrnCal.startDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngCalHdrBean.getEndDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmTrnCal.endDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  private void checkMandatoryDtls(HrmTrngCalDtlBean oHrmTrngCalDtlBean, int rowCount) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oParams = new ArrayList();
    ArrayList oErrorList = new ArrayList();
    rowCount++;
    if (!EnrgiseUtil.checkString(oHrmTrngCalDtlBean.getTxtCourseCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmTrnCal.txtCourseCode");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngCalDtlBean.getTxtInstituteName())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmTrnCal.txtInstituteName");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngCalDtlBean.getTxtStartDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmTrnCal.txtStartDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngCalDtlBean.getTxtEndDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmTrnCal.txtEndDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_TRNG_CAl_HDR";
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmTrngCalHdrBean oHrmTrngCalHdrBean = (HrmTrngCalHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      System.out.println(oHrmTrngCalHdrBean.getStartDate());
      System.out.println(EnrgiseUtil.convertToSqlDate(oHrmTrngCalHdrBean.getStartDate()));
      System.out.println(oHrmTrngCalHdrBean.getEndDate());
      System.out.println(EnrgiseUtil.convertToSqlDate(oHrmTrngCalHdrBean.getEndDate()));
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, "i"));
      arylstParameters.add(new DBObject(2, 1, 12, oHrmTrngCalHdrBean.getCalendarName()));
      arylstParameters.add(new DBObject(3, 1, 12, oHrmTrngCalHdrBean.getSiteId()));
      arylstParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngCalHdrBean.getStartDate())));
      arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngCalHdrBean.getEndDate())));
      arylstParameters.add(new DBObject(6, 1, 12, "100"));
      arylstParameters.add(new DBObject(7, 1, 12, "100"));
      arylstParameters.add(new DBObject(8, 1, 12, null));
      arylstParameters.add(new DBObject(9, 2, 12));
      arylstParameters.add(new DBObject(10, 2, 12));
      arylstParameters.add(new DBObject(11, 2, 12));
      arylstParameters.add(new DBObject(12, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_UpsertHrTrngCalHdr(?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, "u"));
      arylstParameters.add(new DBObject(2, 1, 12, oHrmTrngCalHdrBean.getCalendarName()));
      arylstParameters.add(new DBObject(3, 1, 12, oHrmTrngCalHdrBean.getSiteId()));
      arylstParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngCalHdrBean.getStartDate())));
      arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngCalHdrBean.getEndDate())));
      arylstParameters.add(new DBObject(6, 1, 12, "100"));
      arylstParameters.add(new DBObject(7, 1, 12, "100"));
      arylstParameters.add(new DBObject(8, 1, 12, oHrmTrngCalHdrBean.getHeaderPrimaryKey()));
      arylstParameters.add(new DBObject(9, 2, 12));
      arylstParameters.add(new DBObject(10, 2, 12));
      arylstParameters.add(new DBObject(11, 2, 12));
      arylstParameters.add(new DBObject(12, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_UpsertHrTrngCalHdr(?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } 
    return returnString;
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmTrngCal"))
      saveHrmTrngCalDetail(sHeaderPrimaryKey, arylstDetailBeanArray); 
  }
  
  private void saveHrmTrngCalDetail(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmTrngCalDtlBean oHrmTrngCalDtlBean = itrBean.next();
      if (oHrmTrngCalDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMTRNGCAL.proc_UpsertHrTrngCalDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "I"));
        arylstParameters.add(new DBObject(2, 1, 12, null));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmTrngCalDtlBean.getTxtInstId()));
        arylstParameters.add(new DBObject(5, 1, 12, oHrmTrngCalDtlBean.getTxtCourseId()));
        arylstParameters.add(new DBObject(6, 1, 12, oHrmTrngCalDtlBean.getTxtType()));
        arylstParameters.add(new DBObject(7, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngCalDtlBean.getTxtStartDate())));
        arylstParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngCalDtlBean.getTxtEndDate())));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmTrngCalDtlBean.getTxtDuration()));
        arylstParameters.add(new DBObject(10, 1, 12, oHrmTrngCalDtlBean.getTxtVenue()));
        arylstParameters.add(new DBObject(11, 1, 12, oHrmTrngCalDtlBean.getTxtStrength()));
        arylstParameters.add(new DBObject(12, 1, 12, oHrmTrngCalDtlBean.getTxtFee()));
        arylstParameters.add(new DBObject(13, 1, 12, oHrmTrngCalDtlBean.getRatingId()));
        arylstParameters.add(new DBObject(14, 1, 12, "P"));
        arylstParameters.add(new DBObject(15, 1, 12, "200"));
        arylstParameters.add(new DBObject(16, 1, 12, "200"));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmTrngCalDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMTRNGCAL.proc_UpsertHrTrngCalDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "U"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmTrngCalDtlBean.getDetailId()));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmTrngCalDtlBean.getTxtInstId()));
        arylstParameters.add(new DBObject(5, 1, 12, oHrmTrngCalDtlBean.getTxtCourseId()));
        arylstParameters.add(new DBObject(6, 1, 12, oHrmTrngCalDtlBean.getTxtType()));
        arylstParameters.add(new DBObject(7, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngCalDtlBean.getTxtStartDate())));
        arylstParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngCalDtlBean.getTxtEndDate())));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmTrngCalDtlBean.getTxtDuration()));
        arylstParameters.add(new DBObject(10, 1, 12, oHrmTrngCalDtlBean.getTxtVenue()));
        arylstParameters.add(new DBObject(11, 1, 12, oHrmTrngCalDtlBean.getTxtStrength()));
        arylstParameters.add(new DBObject(12, 1, 12, oHrmTrngCalDtlBean.getTxtFee()));
        arylstParameters.add(new DBObject(13, 1, 12, oHrmTrngCalDtlBean.getRatingId()));
        arylstParameters.add(new DBObject(14, 1, 12, "P"));
        arylstParameters.add(new DBObject(15, 1, 12, "200"));
        arylstParameters.add(new DBObject(16, 1, 12, "200"));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmTrngCalDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMTRNGCAL.proc_DeleteTrngCalDtl(?)");
          bDelete = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, oHrmTrngCalDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParameters);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  public void calendarClose(String sCalId) throws EnrgiseSystemException, EnrgiseApplicationException {
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParameters = new ArrayList();
    QueryRow oRow = null;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmTrngCalDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sCalId));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(2, 2, 12));
    arylstParameters.add(new DBObject(2, 2, 12));
    arylstParameters.add(new DBObject(4, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMTRNGCAL.proc_GetTrngCalForClose(?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    HashMap mapFacFdbk = new HashMap();
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      oRow = itrBean.next();
      mapFacFdbk.put(oRow.get("srl_no"), oRow.get("trn_facmst_srl_no"));
    } 
  }
}
