package WEB-INF.classes.wenrgise.hrms.businessdelegate;

import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.CreateException;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.vo.BaseQueryVO;
import wenrgise.common.vo.ThisPageVO;
import wenrgise.ejb.common.utility.ServiceLocator;
import wenrgise.hrms.bean.HrmLvMstHdrBean;
import wenrgise.hrms.businessdelegate.HrmBaseBD;
import wenrgise.hrms.ejb.facade.HrmSecondFacade;
import wenrgise.hrms.ejb.facade.HrmSecondFacadeHome;
import wenrgise.hrms.vo.HrmLvMstQVO;

public class HrmLvMstBD extends HrmBaseBD {
  public RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      return oHrmSecondFacade.getHrmLeaveMasterHdrMetaInfo((HrmLvMstQVO)oQueryVO);
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public ArrayList getHeaderRecordImpl(BaseQueryVO oQueryVO, long lStartPosition, long lLastPosition) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      ArrayList oHeaderList = oHrmSecondFacade.getHrmLeaveMasterHeaderInfo((HrmLvMstQVO)oQueryVO, lStartPosition, lLastPosition);
      return oHeaderList;
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public RecordMetaInfo getTotalDetailRecordCountImpl(String lPrimaryKey, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      return oHrmSecondFacade.getHrmLeaveMasterDtlMetaInfo(lPrimaryKey);
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public ArrayList getDetailRecordImpl(String lPrimaryKey, String sScreenName, long lAbsoluteStart, long lAbsoluteEnd) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      return oHrmSecondFacade.getHrmLeaveMasterDetailInfo(lPrimaryKey, lAbsoluteStart, lAbsoluteEnd);
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public boolean updateHeaderRecordImpl(BaseHeaderBean oBaseHeaderBean) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return true;
  }
  
  public String saveImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      return oHrmSecondFacade.saveHrmLeaveMst((HrmLvMstHdrBean)oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, oDetailBeanArray, bDetailDataChanged, oDetailPicked, this.oUserInfo);
    } catch (CreateException oCrtExcep) {
      throw new EnrgiseSystemException(oCrtExcep);
    } 
  }
  
  public String getInsertDataImpl(BaseQueryVO oQueryVO) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return "Only Implementation";
  }
  
  public Map getDisabledFieldsImpl(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    HashMap oHashMap = new HashMap();
    ArrayList oEnableList = new ArrayList();
    ArrayList oDisableList = new ArrayList();
    HrmLvMstHdrBean oHrmLvMstHdrBean = (HrmLvMstHdrBean)oThisPageVO.getOHeaderBean();
    ArrayList oDetailList = oThisPageVO.getODetailList();
    if (oThisPageVO.getScreenMode().equalsIgnoreCase("N"))
      oDisableList.add("butLeaveCode"); 
    if (!oHrmLvMstHdrBean.equals(null)) {
      if (EnrgiseUtil.checkString(oHrmLvMstHdrBean.getEvidenceRequired()))
        if (String.valueOf(oHrmLvMstHdrBean.getEvidenceRequired()).equalsIgnoreCase("on")) {
          oEnableList.add("evidenceDescription");
        } else if (String.valueOf(oHrmLvMstHdrBean.getEvidenceRequired()).equalsIgnoreCase("off")) {
          oDisableList.add("evidenceDescription");
        } else if (String.valueOf(oHrmLvMstHdrBean.getEvidenceRequired()).equalsIgnoreCase("")) {
          oDisableList.add("evidenceDescription");
        }  
      if (EnrgiseUtil.checkString(oHrmLvMstHdrBean.getEncashable()))
        if (String.valueOf(oHrmLvMstHdrBean.getEncashable()).equalsIgnoreCase("on")) {
          oEnableList.add("encashableLimit");
          oEnableList.add("periodicity");
        } else if (String.valueOf(oHrmLvMstHdrBean.getEncashable()).equalsIgnoreCase("off")) {
          oDisableList.add("encashableLimit");
          oDisableList.add("periodicity");
        } else if (String.valueOf(oHrmLvMstHdrBean.getEncashable()).equalsIgnoreCase("")) {
          oDisableList.add("encashableLimit");
          oDisableList.add("periodicity");
        }  
    } 
    oHashMap.put("D", oDisableList);
    oHashMap.put("E", oEnableList);
    return oHashMap;
  }
  
  public void onLoadAction(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    if (oThisPageVO.getScreenMode().equalsIgnoreCase("N") || oThisPageVO.getScreenMode().equalsIgnoreCase("U")) {
      HrmLvMstHdrBean oHrmLvMstHdrBean = (HrmLvMstHdrBean)oThisPageVO.getOHeaderBean();
      if (String.valueOf(oHrmLvMstHdrBean.getEvidenceRequired()).equalsIgnoreCase("off"))
        oHrmLvMstHdrBean.setEvidenceDescription(""); 
      if (String.valueOf(oHrmLvMstHdrBean.getEncashable()).equalsIgnoreCase("off")) {
        oHrmLvMstHdrBean.setEncashableLimit("");
        oHrmLvMstHdrBean.setPeriodicity("");
      } 
    } 
  }
  
  public String submitImpl(String sButtonName, BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return new String("");
  }
}
