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.HrmLvMstDtlBean;
import wenrgise.hrms.bean.HrmLvMstHdrBean;
import wenrgise.hrms.vo.HrmLvMstQVO;

public class HrmLvMstBO extends HrmBaseBO {
  public HrmLvMstBO() {}
  
  public HrmLvMstBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmLeaveMasterHdrMetaInfo(HrmLvMstQVO oHrmLvMstQVO) 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, oHrmLvMstQVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(2, 1, 12, oHrmLvMstQVO.getLeaveCode()));
    arylstParam.add(new DBObject(3, 1, 12, oHrmLvMstQVO.getCalendar()));
    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, "HRMLVMST.proc_HrLeaveMstHdrCount(?,?,?,?,?,?,?,?)");
    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 getHrmLeaveMasterHeaderInfo(HrmLvMstQVO oHrmLvMstQVO, 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 (oHrmLvMstQVO == null)
      oHrmLvMstQVO = new HrmLvMstQVO(); 
    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, oHrmLvMstQVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(4, 1, 12, oHrmLvMstQVO.getLeaveCode()));
    arylstParam.add(new DBObject(5, 1, 12, oHrmLvMstQVO.getCalendar()));
    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, "HRMLVMST.proc_GetHrLeaveMstHdr(?,?,?,?,?,?,?,?,?)");
    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()) {
      String Eve, EnFlg, PreSufFlg, sufFlg, IntrHolFlg, LvObsFlg;
      if (count == 0)
        arylstHeaderList = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmLvMstHdrBean oLeaveHeader = new HrmLvMstHdrBean();
      oLeaveHeader.setHeaderPrimaryKey(oRow.get("ID").getString());
      oLeaveHeader.setLeaveCode(oRow.get("CODE").getString());
      oLeaveHeader.setDescription(oRow.get("NAME").getString());
      oLeaveHeader.setEvidenceDescription(oRow.get("EVIDENCE_DESCRIPTION").getString());
      oLeaveHeader.setPeriodicity(oRow.get("PERIODICITY").getString());
      oLeaveHeader.setEncashableLimit(oRow.get("ENCASHABLE_LIMIT").getString());
      oLeaveHeader.setCalendar(oRow.get("CALENDAR_TYPE").getString());
      oLeaveHeader.setApplicableTo(oRow.get("SEX").getString());
      String EveReq = oRow.get("EVIDENCE_REQUIRED").getString();
      if (EveReq.equalsIgnoreCase("Y")) {
        Eve = "on";
      } else {
        Eve = "off";
      } 
      oLeaveHeader.setEvidenceRequired(Eve);
      String Encash = oRow.get("ENCASHABLE_FLAG").getString();
      if (Encash.equalsIgnoreCase("Y")) {
        EnFlg = "on";
      } else {
        EnFlg = "off";
      } 
      oLeaveHeader.setEncashable(EnFlg);
      String PreSuf = oRow.get("PREFIX_FLAG").getString();
      if (PreSuf.equalsIgnoreCase("Y")) {
        PreSufFlg = "on";
      } else {
        PreSufFlg = "off";
      } 
      oLeaveHeader.setPrefixSuffix(PreSufFlg);
      String suf = oRow.get("SUFFIX_FLAG").getString();
      if (suf.equalsIgnoreCase("Y")) {
        sufFlg = "on";
      } else {
        sufFlg = "off";
      } 
      oLeaveHeader.setSuffix(sufFlg);
      String IntrHol = oRow.get("INTRMDT_HLDY_ALLWD").getString();
      if (IntrHol.equalsIgnoreCase("Y")) {
        IntrHolFlg = "on";
      } else {
        IntrHolFlg = "off";
      } 
      oLeaveHeader.setIntermediateHoliday(IntrHolFlg);
      String LvObs = oRow.get("LEAVE_OBSOLETE").getString();
      if (LvObs.equalsIgnoreCase("Y")) {
        LvObsFlg = "on";
      } else {
        LvObsFlg = "off";
      } 
      oLeaveHeader.setLeaveObsolete(LvObsFlg);
      arylstHeaderList.add(oLeaveHeader);
    } 
    return arylstHeaderList;
  }
  
  public RecordMetaInfo getHrmLeaveMasterDtlMetaInfo(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, "HRMLVMST.proc_HrLeaveMstDtlCount(?,?,?,?,?,?)");
    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 getHrmLeaveMasterDetailInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmLeaveMasterDetail = 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, "HRMLVMST.proc_GetHrLeaveMstDtl(?,?,?,?,?,?,?)");
    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();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmLeaveMasterDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmLvMstDtlBean oLeaveMasterDetailBean = new HrmLvMstDtlBean();
      oLeaveMasterDetailBean.setDetailId(oRow.get("ID").getString());
      oLeaveMasterDetailBean.setTxtLeaveDescription(oRow.get("LEAVE_DESCRIPTION").getString());
      oLeaveMasterDetailBean.setTxtApplicableFor(oRow.get("APPLICABLE_FOR").getString());
      oLeaveMasterDetailBean.setTxtStateCode(oRow.get("STATE_CODE").getString());
      oLeaveMasterDetailBean.setTxtState(oRow.get("GLOBAL_CODE_DESC").getString());
      oLeaveMasterDetailBean.setTxtMinimumServicePeriod(oRow.get("YEARS_OF_SERVICE").getString());
      oLeaveMasterDetailBean.setTxtMaximumAccumulationLimit(oRow.get("ACCUMULATION_LIMIT").getString());
      oLeaveMasterDetailBean.setTxtTotalAvailableLimit(oRow.get("MAX_AVAIL_SVC_PRD").getString());
      oLeaveMasterDetailBean.setTxtAdvanceLimit(oRow.get("ADVANCE_LIMIT").getString());
      oLeaveMasterDetailBean.setTxtCreditFrequency(oRow.get("CREDIT_FREQUENCY").getString());
      oLeaveMasterDetailBean.setTxtLeavesCredited(oRow.get("MIN_CREDIT_LIMIT").getString());
      oLeaveMasterDetailBean.setTxtMaxCreditLimit(oRow.get("MAX_CREDIT_LIMIT").getString());
      String wrkFlag = oRow.get("WORKING_DAYS_FLAG").getString();
      if (wrkFlag.equalsIgnoreCase("null")) {
        wrkFlag = "off";
      } else {
        if (wrkFlag.equalsIgnoreCase("Y"))
          wrkFlag = "on"; 
        if (wrkFlag.equalsIgnoreCase("N"))
          wrkFlag = "off"; 
      } 
      oLeaveMasterDetailBean.setTxtDependantOnWorkingDays(wrkFlag);
      oLeaveMasterDetailBean.setTxtUnit(oRow.get("DAYS_WORKED").getString());
      String allFlag = oRow.get("ALL_FLAG").getString();
      if (allFlag.equalsIgnoreCase("null")) {
        allFlag = "off";
      } else {
        if (allFlag.equalsIgnoreCase("Y"))
          allFlag = "on"; 
        if (allFlag.equalsIgnoreCase("N"))
          allFlag = "off"; 
      } 
      oLeaveMasterDetailBean.setTxtApplicableToAll(allFlag);
      oLeaveMasterDetailBean.setTxtEffectiveFrom(oRow.get("EFFECT_FROM").getString());
      oLeaveMasterDetailBean.setTxtEffectiveTo(oRow.get("EFFECT_TO").getString());
      oLeaveMasterDetailBean.setTxtMaxTxn(oRow.get("TXN_PER_SRV_PRD").getString());
      oLeaveMasterDetailBean.setTxtMinLeavePerTxn(oRow.get("MIN_LEAVE_PER_TXN").getString());
      String lapseFlag = oRow.get("LAPSE_FLAG").getString();
      if (lapseFlag.equalsIgnoreCase("null")) {
        lapseFlag = "";
      } else {
        if (lapseFlag.equalsIgnoreCase("Y"))
          lapseFlag = "on"; 
        if (lapseFlag.equalsIgnoreCase("N"))
          lapseFlag = ""; 
      } 
      oLeaveMasterDetailBean.setTxtLapsable(lapseFlag);
      arylstHrmLeaveMasterDetail.add(oLeaveMasterDetailBean);
    } 
    return arylstHrmLeaveMasterDetail;
  }
  
  public ArrayList getHrmCurLeaveMasterDetailInfo() throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmCurLeaveMasterDetail = null;
    DateUtility d = new DateUtility();
    String str = d.getSysDate();
    String monOfSysDate = str.substring(3, 5);
    String yearOfSysDate = str.substring(6, 10);
    String yyyymm = String.valueOf(yearOfSysDate).concat(String.valueOf(monOfSysDate));
    System.out.println(yyyymm);
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, yyyymm));
    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, "HRMLVMST.proc_GetHrCurLeaveInfo(?,?,?,?,?)");
    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();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmCurLeaveMasterDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmLvMstDtlBean oLeaveMasterDetailBean = new HrmLvMstDtlBean();
      oLeaveMasterDetailBean.setDetailId(oRow.get("ID").getString());
      oLeaveMasterDetailBean.setTxtLeaveDescription(oRow.get("LEAVE_DESCRIPTION").getString());
      arylstHrmCurLeaveMasterDetail.add(oLeaveMasterDetailBean);
    } 
    return arylstHrmCurLeaveMasterDetail;
  }
  
  public LovVO getHrmLeaveDetailLOVInfo(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("ID");
    arylstHeaderNames.add("hrm.HrmLeaveMaster.leaveDescription");
    arylstHeaderNames.add("hrm.HrmLeaveMaster.effectiveFrom");
    arylstHeaderNames.add("hrm.HrmLeaveMaster.effectiveTo");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    DateUtility d = new DateUtility();
    String str = d.getSysDate();
    String monOfSysDate = str.substring(3, 5);
    String yearOfSysDate = str.substring(6, 10);
    String yyyymm = String.valueOf(yearOfSysDate).concat(String.valueOf(monOfSysDate));
    System.out.println(yyyymm);
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, yyyymm));
    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, "HRMLVMST.proc_GetHrCurLeaveInfo(?,?,?,?,?)");
    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("LEAVE_DESCRIPTION").getString());
      oLOVBean.setDetailField3(oRow.get("EFFECT_FROM").getString());
      oLOVBean.setDetailField4(oRow.get("EFFECT_TO").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public void updateLeaveMst(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, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVMST.proc_UpdateHrLvAttrDtl(?,?,?,?,?,?,?)");
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_LEAVE_MST";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmLeaveMaster"))
      saveHrmLeaveDetail(sHeaderPrimaryKey, arylstDetailBeanArray); 
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmLvMstHdrBean oHrmLvMstHdrBean = (HrmLvMstHdrBean)oBaseHeaderBean;
    String encashable = null;
    String leaveObsolete = null;
    String intermediateHoliday = null;
    String prefixSuffix = null;
    String suffix = null;
    String eviReq = null;
    String calId = getCalIdByType(oHrmLvMstHdrBean.getCalendar());
    if (String.valueOf(oHrmLvMstHdrBean.getEncashable()).equalsIgnoreCase("on")) {
      encashable = "Y";
    } else {
      encashable = "N";
    } 
    if (String.valueOf(oHrmLvMstHdrBean.getLeaveObsolete()).equalsIgnoreCase("on")) {
      leaveObsolete = "Y";
    } else {
      leaveObsolete = "N";
    } 
    if (String.valueOf(oHrmLvMstHdrBean.getIntermediateHoliday()).equalsIgnoreCase("on")) {
      intermediateHoliday = "Y";
    } else {
      intermediateHoliday = "N";
    } 
    if (String.valueOf(oHrmLvMstHdrBean.getPrefixSuffix()).equalsIgnoreCase("on")) {
      prefixSuffix = "Y";
    } else {
      prefixSuffix = "N";
    } 
    if (String.valueOf(oHrmLvMstHdrBean.getSuffix()).equalsIgnoreCase("on")) {
      suffix = "Y";
    } else {
      suffix = "N";
    } 
    if (String.valueOf(oHrmLvMstHdrBean.getEvidenceRequired()).equalsIgnoreCase("on")) {
      eviReq = "Y";
    } else {
      eviReq = "N";
    } 
    if (ScreenMode.equalsIgnoreCase("N")) {
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "i"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmLvMstHdrBean.getApplicableTo()));
      arylstParam.add(new DBObject(3, 1, 12, calId));
      arylstParam.add(new DBObject(4, 1, 12, oHrmLvMstHdrBean.getDescription()));
      arylstParam.add(new DBObject(5, 1, 12, encashable));
      arylstParam.add(new DBObject(6, 1, 12, oHrmLvMstHdrBean.getEncashableLimit()));
      arylstParam.add(new DBObject(7, 1, 12, oHrmLvMstHdrBean.getEvidenceDescription()));
      arylstParam.add(new DBObject(8, 1, 12, eviReq));
      arylstParam.add(new DBObject(9, 1, 12, intermediateHoliday));
      arylstParam.add(new DBObject(10, 1, 12, oHrmLvMstHdrBean.getLeaveCode()));
      arylstParam.add(new DBObject(11, 1, 12, leaveObsolete));
      arylstParam.add(new DBObject(12, 1, 12, oHrmLvMstHdrBean.getPeriodicity()));
      arylstParam.add(new DBObject(13, 1, 12, prefixSuffix));
      arylstParam.add(new DBObject(14, 1, 12, suffix));
      arylstParam.add(new DBObject(15, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParam.add(new DBObject(16, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(17, 1, 12, null));
      arylstParam.add(new DBObject(18, 2, 12));
      arylstParam.add(new DBObject(19, 2, 12));
      arylstParam.add(new DBObject(20, 2, 12));
      arylstParam.add(new DBObject(21, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVMST.proc_UpsertHrLeaveMstHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "u"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmLvMstHdrBean.getApplicableTo()));
      arylstParam.add(new DBObject(3, 1, 12, calId));
      arylstParam.add(new DBObject(4, 1, 12, oHrmLvMstHdrBean.getDescription()));
      arylstParam.add(new DBObject(5, 1, 12, encashable));
      arylstParam.add(new DBObject(6, 1, 12, oHrmLvMstHdrBean.getEncashableLimit()));
      arylstParam.add(new DBObject(7, 1, 12, oHrmLvMstHdrBean.getEvidenceDescription()));
      arylstParam.add(new DBObject(8, 1, 12, eviReq));
      arylstParam.add(new DBObject(9, 1, 12, intermediateHoliday));
      arylstParam.add(new DBObject(10, 1, 12, oHrmLvMstHdrBean.getLeaveCode()));
      arylstParam.add(new DBObject(11, 1, 12, leaveObsolete));
      arylstParam.add(new DBObject(12, 1, 12, oHrmLvMstHdrBean.getPeriodicity()));
      arylstParam.add(new DBObject(13, 1, 12, prefixSuffix));
      arylstParam.add(new DBObject(14, 1, 12, suffix));
      arylstParam.add(new DBObject(15, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParam.add(new DBObject(16, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(17, 1, 12, oHrmLvMstHdrBean.getHeaderPrimaryKey()));
      arylstParam.add(new DBObject(18, 2, 12));
      arylstParam.add(new DBObject(19, 2, 12));
      arylstParam.add(new DBObject(20, 2, 12));
      arylstParam.add(new DBObject(21, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVMST.proc_UpsertHrLeaveMstHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("D")) {
      arylstParam.add(new DBObject(1, 1, 12, oHrmLvMstHdrBean.getHeaderPrimaryKey()));
      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, "HRMLVMST.proc_DelHrLeaveMstHdr(?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = null;
    } 
    return returnString;
  }
  
  private void saveHrmLeaveDetail(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmLvMstDtlBean oHrmLvMstDtlBean = itrBean.next();
      if (oHrmLvMstDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMLVMST.proc_UpsertHrLeaveMstDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "I"));
        arylstParam.add(new DBObject(2, 1, 12, null));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmLvMstDtlBean.getTxtLeaveDescription()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmLvMstDtlBean.getTxtApplicableFor()));
        arylstParam.add(new DBObject(6, 1, 12, oHrmLvMstDtlBean.getTxtStateCode()));
        arylstParam.add(new DBObject(7, 1, 12, oHrmLvMstDtlBean.getTxtEffectiveFrom()));
        arylstParam.add(new DBObject(8, 1, 12, oHrmLvMstDtlBean.getTxtEffectiveTo()));
        arylstParam.add(new DBObject(9, 1, 12, oHrmLvMstDtlBean.getTxtMinimumServicePeriod()));
        arylstParam.add(new DBObject(10, 1, 12, oHrmLvMstDtlBean.getTxtMaximumAccumulationLimit()));
        arylstParam.add(new DBObject(11, 1, 12, oHrmLvMstDtlBean.getTxtTotalAvailableLimit()));
        arylstParam.add(new DBObject(12, 1, 12, oHrmLvMstDtlBean.getTxtAdvanceLimit()));
        arylstParam.add(new DBObject(13, 1, 12, oHrmLvMstDtlBean.getTxtMaxTxn()));
        arylstParam.add(new DBObject(14, 1, 12, oHrmLvMstDtlBean.getTxtMinLeavePerTxn()));
        String depWrkDays = String.valueOf(oHrmLvMstDtlBean.getTxtDependantOnWorkingDays());
        if (depWrkDays.equalsIgnoreCase("on")) {
          depWrkDays = "Y";
        } else {
          depWrkDays = "N";
        } 
        arylstParam.add(new DBObject(15, 1, 12, depWrkDays));
        arylstParam.add(new DBObject(16, 1, 12, oHrmLvMstDtlBean.getTxtUnit()));
        arylstParam.add(new DBObject(17, 1, 12, oHrmLvMstDtlBean.getTxtCreditFrequency()));
        arylstParam.add(new DBObject(18, 1, 12, oHrmLvMstDtlBean.getTxtMaxCreditLimit()));
        arylstParam.add(new DBObject(19, 1, 12, oHrmLvMstDtlBean.getTxtLeavesCredited()));
        String applicable = String.valueOf(oHrmLvMstDtlBean.getTxtApplicableToAll());
        if (applicable.equalsIgnoreCase("on")) {
          applicable = "Y";
        } else {
          applicable = "N";
        } 
        arylstParam.add(new DBObject(20, 1, 12, applicable));
        String lapsable = String.valueOf(oHrmLvMstDtlBean.getTxtLapsable());
        if (lapsable.equalsIgnoreCase("on")) {
          lapsable = "Y";
        } else {
          lapsable = "N";
        } 
        arylstParam.add(new DBObject(21, 1, 12, lapsable));
        arylstParam.add(new DBObject(22, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParam.add(new DBObject(23, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmLvMstDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMLVMST.proc_UpsertHrLeaveMstDtl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "U"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmLvMstDtlBean.getDetailId()));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmLvMstDtlBean.getTxtLeaveDescription()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmLvMstDtlBean.getTxtApplicableFor()));
        arylstParam.add(new DBObject(6, 1, 12, oHrmLvMstDtlBean.getTxtStateCode()));
        arylstParam.add(new DBObject(7, 1, 12, oHrmLvMstDtlBean.getTxtEffectiveFrom()));
        arylstParam.add(new DBObject(8, 1, 12, oHrmLvMstDtlBean.getTxtEffectiveTo()));
        arylstParam.add(new DBObject(9, 1, 12, oHrmLvMstDtlBean.getTxtMinimumServicePeriod()));
        arylstParam.add(new DBObject(10, 1, 12, oHrmLvMstDtlBean.getTxtMaximumAccumulationLimit()));
        arylstParam.add(new DBObject(11, 1, 12, oHrmLvMstDtlBean.getTxtTotalAvailableLimit()));
        arylstParam.add(new DBObject(12, 1, 12, oHrmLvMstDtlBean.getTxtAdvanceLimit()));
        arylstParam.add(new DBObject(13, 1, 12, oHrmLvMstDtlBean.getTxtMaxTxn()));
        arylstParam.add(new DBObject(14, 1, 12, oHrmLvMstDtlBean.getTxtMinLeavePerTxn()));
        String depWrkDays = String.valueOf(oHrmLvMstDtlBean.getTxtDependantOnWorkingDays());
        if (depWrkDays.equalsIgnoreCase("on")) {
          depWrkDays = "Y";
        } else {
          depWrkDays = "N";
        } 
        arylstParam.add(new DBObject(15, 1, 12, depWrkDays));
        arylstParam.add(new DBObject(16, 1, 12, oHrmLvMstDtlBean.getTxtUnit()));
        arylstParam.add(new DBObject(17, 1, 12, oHrmLvMstDtlBean.getTxtCreditFrequency()));
        arylstParam.add(new DBObject(18, 1, 12, oHrmLvMstDtlBean.getTxtMaxCreditLimit()));
        arylstParam.add(new DBObject(19, 1, 12, oHrmLvMstDtlBean.getTxtLeavesCredited()));
        String applicable = String.valueOf(oHrmLvMstDtlBean.getTxtApplicableToAll());
        if (applicable.equalsIgnoreCase("on")) {
          applicable = "Y";
        } else {
          applicable = "N";
        } 
        arylstParam.add(new DBObject(20, 1, 12, applicable));
        String lapsable = String.valueOf(oHrmLvMstDtlBean.getTxtLapsable());
        if (lapsable.equalsIgnoreCase("on")) {
          lapsable = "Y";
        } else {
          lapsable = "N";
        } 
        arylstParam.add(new DBObject(21, 1, 12, lapsable));
        arylstParam.add(new DBObject(22, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParam.add(new DBObject(23, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmLvMstDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMLVMST.proc_DeleteHrLeaveMstDtl(?)");
          bDelete = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, oHrmLvMstDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParam);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  public String getCalIdByType(String calType) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    String calId = null;
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, calType));
    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, "HRMLVMST.proc_GetCalIdByType(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      oRow = itrBean.next();
      calId = oRow.get("ID").getString();
    } 
    return calId;
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    System.out.println("Update ille!");
  }
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "saveNewHeaderImpl ille!";
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public LovVO getHrmLeaveMasterLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmLeaveMaster.leaveCode");
    arylstHeaderList.add("hrm.HrmLeaveMaster.description");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    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, "HRMLVLOV.proc_GetLeaveCodeLOV(?,?,?,?,?,?)");
    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("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmLvMstStateLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmLeaveMaster.stateCode");
    arylstHeaderList.add("hrm.HrmLeaveMaster.state");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    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, "HRMLVLOV.proc_GetLvMstStateLOVdata(?,?,?,?,?,?)");
    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("GLOBAL_CODE_TYPE").getString());
      oLOVBean.setDetailField2(oRow.get("GLOBAL_CODE").getString());
      oLOVBean.setDetailField3(oRow.get("GLOBAL_CODE_DESC").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmLeaveCodeInsertLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmLeaveMaster.leaveCode");
    arylstHeaderList.add("hrm.HrmLeaveMaster.description");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    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, "HRMLVLOV.proc_GetLeaveCodeInsertLOV(?,?,?,?,?,?)");
    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("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmLeaveMasterCalLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmLeaveMaster.calendarType");
    arylstHeaderList.add("hrm.HrmLeaveMaster.beginMonth");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    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, "HRMLVLOV.proc_GetLeaveCalendarTypeLOV(?,?,?,?,?)");
    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("CALENDAR_TYPE").getString());
      oLOVBean.setDetailField3(oRow.get("BEGIN_MONTH").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  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();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmLvMstHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmLeaveMaster")) {
        Iterator itrBean1 = arylstDetailBeanArray.iterator();
        int iCount = 1;
        while (itrBean1.hasNext()) {
          HrmLvMstDtlBean oHrmLvMstDtlBean = itrBean1.next();
          if (!oHrmLvMstDtlBean.getStatus().equalsIgnoreCase("D")) {
            checkMandatory(oHrmLvMstDtlBean, iCount, arylstErrorList);
            EnrgiseUtil.checkDuplicate(arylstDetailBeanArray, "txtLeaveDescription", "hrm.HrmLeaveMaster.leaveDescription", arylstErrorList, true);
          } 
          iCount++;
        } 
      }  
    reportError(arylstErrorList);
  }
  
  private void checkMandatoryHeader(HrmLvMstHdrBean oHrmLvMstHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmLvMstHdrBean.getLeaveCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.leaveCode");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLvMstHdrBean.getCalendar())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.calendar");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLvMstHdrBean.getApplicableTo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.applicableTo");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (oHrmLvMstHdrBean.getEncashable().equalsIgnoreCase("on")) {
      if (!EnrgiseUtil.checkString(oHrmLvMstHdrBean.getEncashableLimit())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.encashableLimit");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
      } 
      if (!EnrgiseUtil.checkString(oHrmLvMstHdrBean.getPeriodicity())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.periodicity");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
      } 
    } 
    if (oHrmLvMstHdrBean.getEvidenceRequired().equalsIgnoreCase("on"))
      if (!EnrgiseUtil.checkString(oHrmLvMstHdrBean.getEvidenceDescription())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.evbidenceDescription");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
      }  
    reportError(oErrorList);
  }
  
  private void checkMandatory(HrmLvMstDtlBean oHrmLvMstDtlBean, int iCount, ArrayList arylstErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {
    if (!EnrgiseUtil.checkString(oHrmLvMstDtlBean.getTxtLeaveDescription())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.leaveDescription");
      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(oHrmLvMstDtlBean.getTxtEffectiveFrom())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.effectiveFrom");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLvMstDtlBean.getTxtEffectiveTo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.effectiveTo");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLvMstDtlBean.getTxtApplicableFor())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.applicableFor");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(iCount));
      arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (oHrmLvMstDtlBean.getTxtApplicableFor().equalsIgnoreCase("S"))
      if (!EnrgiseUtil.checkString(oHrmLvMstDtlBean.getTxtState())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveMaster.state");
        ArrayList oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(String.valueOf(iCount));
        arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
      }  
    reportError(arylstErrorList);
  }
  
  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();
    HrmLvMstHdrBean oHrmLvMstHdrBean = (HrmLvMstHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkUniqueHeader((HrmLvMstHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmLeaveMaster"))
        getyyyymmDateFormat(arylstDetailBeanArray);  
    reportError(arylstErrorList);
  }
  
  private void checkUniqueHeader(HrmLvMstHdrBean oHrmLvMstHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = String.valueOf(String.valueOf(" Select ID as ID from HRM_LEAVE_MST where CODE='").concat(String.valueOf(oHrmLvMstHdrBean.getLeaveCode()))).concat(String.valueOf("'"));
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstList = oBean.executeQuery(sQuery);
    Iterator itrBean = arylstList.iterator();
    if (itrBean.hasNext()) {
      QueryRow oRow = itrBean.next();
      if (!oRow.get("ID").getString().equalsIgnoreCase(oHrmLvMstHdrBean.getHeaderPrimaryKey()))
        throw new EnrgiseApplicationException("wenrgise.common.uniqueConstraintViolated", "M"); 
    } 
  }
  
  private void checkUniqueDtl(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseApplicationException, EnrgiseSystemException {
    int count = 0;
    Iterator itrBean1 = arylstDetailBeanArray.iterator();
    while (itrBean1.hasNext()) {
      HrmLvMstDtlBean oHrmLvMstDtlBean = itrBean1.next();
      String sQuery = String.valueOf(String.valueOf(String.valueOf(" Select ID as ID from HRM_LEAVE_ATTR_DTL where LEAVE_DESCRIPTION= ").concat(String.valueOf(oHrmLvMstDtlBean.getTxtLeaveDescription()))).concat(String.valueOf(" and LEAVE_MST_ID="))).concat(String.valueOf(sHeaderPrimaryKey));
      System.out.println(sQuery);
      DBUtilitiesBean oBean = new DBUtilitiesBean();
      ArrayList arylstList = oBean.executeQuery(sQuery);
      Iterator itrBean = arylstList.iterator();
      if (itrBean.hasNext()) {
        QueryRow oRow = itrBean.next();
        if (!oRow.get("ID").getString().equalsIgnoreCase(oHrmLvMstDtlBean.getDetailId()))
          throw new EnrgiseApplicationException("wenrgise.common.uniqueConstraintViolated", "M"); 
      } 
    } 
  }
  
  private void getyyyymmDateFormat(ArrayList arylstDetailBeanArray) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    Iterator itrBean1 = arylstDetailBeanArray.iterator();
    int iCount = 1;
    while (itrBean1.hasNext()) {
      HrmLvMstDtlBean oHrmLvMstDtlBean = itrBean1.next();
      if (!oHrmLvMstDtlBean.getStatus().equalsIgnoreCase("D")) {
        String sEffectFrom = oHrmLvMstDtlBean.getTxtEffectiveFrom();
        String sEffectTo = oHrmLvMstDtlBean.getTxtEffectiveTo();
        if (sEffectFrom.length() < 6) {
          arylstParam = new ArrayList();
          arylstParam.add("");
          arylstParam.add(new Integer(0));
          arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.dateValidation.fromLength", arylstParam));
        } 
        if (sEffectFrom.length() == 6) {
          if (Integer.parseInt(sEffectFrom.substring(0, 4)) < 1900 || Integer.parseInt(sEffectFrom.substring(0, 4)) > 2100) {
            arylstParam = new ArrayList();
            arylstParam.add("");
            arylstParam.add(new Integer(0));
            arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.dateValidation.year", arylstParam));
          } 
          if (Integer.parseInt(sEffectFrom.substring(4, 6)) < 1 || Integer.parseInt(sEffectFrom.substring(4, 6)) > 12) {
            arylstParam = new ArrayList();
            arylstParam.add("");
            arylstParam.add(new Integer(0));
            arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.dateValidation.month", arylstParam));
          } 
        } 
        if (sEffectTo.length() < 6) {
          arylstParam = new ArrayList();
          arylstParam.add("");
          arylstParam.add(new Integer(0));
          arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.dateValidation.toLength", arylstParam));
        } 
        if (sEffectTo.length() == 6) {
          if (Integer.parseInt(sEffectTo.substring(0, 4)) < 1900 || Integer.parseInt(sEffectTo.substring(0, 4)) > 2100) {
            arylstParam = new ArrayList();
            arylstParam.add("");
            arylstParam.add(new Integer(0));
            arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.dateValidation.year", arylstParam));
          } 
          if (Integer.parseInt(sEffectTo.substring(4, 6)) < 1 || Integer.parseInt(sEffectTo.substring(4, 6)) > 12) {
            arylstParam = new ArrayList();
            arylstParam.add("");
            arylstParam.add(new Integer(0));
            arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.dateValidation.month", arylstParam));
          } 
        } 
        if (sEffectTo.length() == 6 && sEffectFrom.length() == 6)
          if (Integer.parseInt(sEffectTo) < Integer.parseInt(sEffectFrom)) {
            arylstParam = new ArrayList();
            arylstParam.add("");
            arylstParam.add(new Integer(0));
            arylstErrorList.add(new EnrgiseMessageKeyException("wenrgise.dateValidation.new", arylstParam));
          }  
      } 
    } 
    reportError(arylstErrorList);
  }
}
