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.HrmOrgHolTypeMstHdrBean;
import wenrgise.hrms.businessdelegate.HrmBaseBD;
import wenrgise.hrms.ejb.facade.HrmFacade;
import wenrgise.hrms.ejb.facade.HrmFacadeHome;
import wenrgise.hrms.vo.HrmOrgHolTypeMstQVO;

public class HrmOrgHolTypeMstBD extends HrmBaseBD {
  public RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmFacadeHome oHome = (HrmFacadeHome)ServiceLocator.getLocator().getService("HrmFacade");
      HrmFacade oHrmFacade = oHome.create();
      return oHrmFacade.getHrmHolTypeHeaderMetaInfo((HrmOrgHolTypeMstQVO)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 {
      HrmFacadeHome oHome = (HrmFacadeHome)ServiceLocator.getLocator().getService("HrmFacade");
      HrmFacade oHrmFacade = oHome.create();
      ArrayList oHeaderList = oHrmFacade.getHrmHolTypeHeader((HrmOrgHolTypeMstQVO)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 {
    RecordMetaInfo oRecordMetaInfo = null;
    return oRecordMetaInfo;
  }
  
  public ArrayList getDetailRecordImpl(String lPrimaryKey, String sScreenName, long lAbsoluteStart, long lAbsoluteEnd) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oRet = null;
    return oRet;
  }
  
  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 {
      HrmFacadeHome oHome = (HrmFacadeHome)ServiceLocator.getLocator().getService("HrmFacade");
      HrmFacade oHrmFacade = oHome.create();
      return oHrmFacade.saveHolidayType((HrmOrgHolTypeMstHdrBean)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();
    HrmOrgHolTypeMstHdrBean oHrmOrgHolTypeMstHdrBean = (HrmOrgHolTypeMstHdrBean)oThisPageVO.getOHeaderBean();
    ArrayList oDetailList = oThisPageVO.getODetailList();
    if (!oHrmOrgHolTypeMstHdrBean.equals(null)) {
      if (oThisPageVO.getScreenMode().equalsIgnoreCase("Q"))
        oDisableList.add("butDelete"); 
      if (oThisPageVO.getScreenMode().equalsIgnoreCase("U")) {
        if (EnrgiseUtil.checkString(oHrmOrgHolTypeMstHdrBean.getMandatory()))
          if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getMandatory()).equalsIgnoreCase("Y")) {
            oEnableList.add("compensatoryLeave");
            if (EnrgiseUtil.checkString(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()))
              if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()).equalsIgnoreCase("N")) {
                oEnableList.add("rewardPercentageOfBasic");
              } else if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()).equalsIgnoreCase("Y")) {
                oDisableList.add("rewardPercentageOfBasic");
              } else if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()).equalsIgnoreCase("")) {
                oDisableList.add("rewardPercentageOfBasic");
              }  
          } else if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getMandatory()).equalsIgnoreCase("N")) {
            oDisableList.add("compensatoryLeave");
            oDisableList.add("rewardPercentageOfBasic");
          } else if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getMandatory()).equalsIgnoreCase("")) {
            oDisableList.add("compensatoryLeave");
            oDisableList.add("rewardPercentageOfBasic");
          }  
        oDisableList.add("butDelete");
      } 
      if (oThisPageVO.getScreenMode().equalsIgnoreCase("N")) {
        if (EnrgiseUtil.checkString(oHrmOrgHolTypeMstHdrBean.getMandatory()))
          if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getMandatory()).equalsIgnoreCase("Y")) {
            oEnableList.add("compensatoryLeave");
          } else if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getMandatory()).equalsIgnoreCase("N")) {
            oDisableList.add("compensatoryLeave");
          } else if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getMandatory()).equalsIgnoreCase("")) {
            oDisableList.add("compensatoryLeave");
          }  
        if (EnrgiseUtil.checkString(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()))
          if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()).equalsIgnoreCase("N")) {
            oEnableList.add("rewardPercentageOfBasic");
          } else if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()).equalsIgnoreCase("Y")) {
            oDisableList.add("rewardPercentageOfBasic");
          } else if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()).equalsIgnoreCase("")) {
            oDisableList.add("rewardPercentageOfBasic");
          }  
        oDisableList.add("butDelete");
      } 
    } 
    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")) {
      HrmOrgHolTypeMstHdrBean oHrmOrgHolTypeMstHdrBean = (HrmOrgHolTypeMstHdrBean)oThisPageVO.getOHeaderBean();
      if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getMandatory()).equalsIgnoreCase("N")) {
        oHrmOrgHolTypeMstHdrBean.setCompensatoryLeave("N");
        oHrmOrgHolTypeMstHdrBean.setRewardPercentageOfBasic("");
      } 
      if (String.valueOf(oHrmOrgHolTypeMstHdrBean.getCompensatoryLeave()).equalsIgnoreCase("Y"))
        oHrmOrgHolTypeMstHdrBean.setRewardPercentageOfBasic(""); 
    } 
  }
  
  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("");
  }
}
