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.HrmDeputationApplicationHdrBean;
import wenrgise.hrms.businessdelegate.HrmBaseBD;
import wenrgise.hrms.ejb.facade.HrmThirdFacade;
import wenrgise.hrms.ejb.facade.HrmThirdFacadeHome;
import wenrgise.hrms.vo.HrmATDDptnApplQVO;

public class HrmATDDptnApplBD extends HrmBaseBD {
  public RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      return oHrmThirdFacade.getHrmEmpDeputAppHdrMetaInfo((HrmATDDptnApplQVO)oQueryVO, this.oUserInfo);
    } 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 {
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      ArrayList oHeaderList = oHrmThirdFacade.getHrmEmpDeputAppHeaderInfo((HrmATDDptnApplQVO)oQueryVO, lStartPosition, lLastPosition, this.oUserInfo);
      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 getInsertDataImpl(BaseQueryVO oQueryVO) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return "Only Implementation";
  }
  
  public String saveImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      return oHrmThirdFacade.saveData((HrmDeputationApplicationHdrBean)oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, oDetailBeanArray, bDetailDataChanged, oDetailPicked, this.oUserInfo);
    } catch (CreateException oCrtExcep) {
      throw new EnrgiseSystemException(oCrtExcep);
    } 
  }
  
  public Map getDisabledFieldsImpl(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    HashMap oHashMap = new HashMap();
    ArrayList arylstEnableList = new ArrayList();
    ArrayList arylstDisableList = new ArrayList();
    HrmDeputationApplicationHdrBean oHrmDeputationApplicationHdrBean = (HrmDeputationApplicationHdrBean)oThisPageVO.getOHeaderBean();
    ArrayList oDetailList = oThisPageVO.getODetailList();
    if (!oHrmDeputationApplicationHdrBean.equals(null)) {
      if (oThisPageVO.getScreenMode().equalsIgnoreCase("Q") || oThisPageVO.getScreenMode().equalsIgnoreCase("N")) {
        arylstDisableList.add("butSubmit");
        arylstDisableList.add("butApprove");
        arylstDisableList.add("butReject");
      } else if (oHrmDeputationApplicationHdrBean.getDeputStatus().equalsIgnoreCase("A")) {
        arylstDisableList.add("butSubmit");
        arylstDisableList.add("butApprove");
        arylstDisableList.add("butReject");
      } else if (oHrmDeputationApplicationHdrBean.getDeputStatus().equalsIgnoreCase("P")) {
        arylstEnableList.add("butApprove");
        arylstEnableList.add("butReject");
        arylstDisableList.add("butSubmit");
      } else if (oHrmDeputationApplicationHdrBean.getDeputStatus().equalsIgnoreCase("R")) {
        arylstDisableList.add("butApprove");
        arylstDisableList.add("butReject");
        arylstDisableList.add("butSubmit");
      } else if (oHrmDeputationApplicationHdrBean.getDeputStatus().equalsIgnoreCase("N")) {
        arylstEnableList.add("butSubmit");
        arylstDisableList.add("butApprove");
        arylstDisableList.add("butReject");
      } 
      if (oThisPageVO.getScreenMode().equalsIgnoreCase("N")) {
        arylstEnableList.add("butEmployeeNo");
        if (EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getDeputType()))
          if (oHrmDeputationApplicationHdrBean.getDeputType().equalsIgnoreCase("W")) {
            arylstDisableList.add("postCode");
            arylstDisableList.add("postName");
            arylstDisableList.add("orgName");
            arylstEnableList.add("butPostName");
          } else if (oHrmDeputationApplicationHdrBean.getDeputType().equalsIgnoreCase("F")) {
            arylstDisableList.add("postCode");
            arylstEnableList.add("postName");
            arylstEnableList.add("orgName");
            arylstDisableList.add("butPostName");
          } else if (oHrmDeputationApplicationHdrBean.getDeputType().equalsIgnoreCase("O")) {
            arylstDisableList.add("postCode");
            arylstEnableList.add("postName");
            arylstEnableList.add("orgName");
            arylstDisableList.add("butPostName");
          }  
        if (EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getAdvtNo()))
          if (oHrmDeputationApplicationHdrBean.getAdvtNo().equalsIgnoreCase("null")) {
            arylstDisableList.add("advtDate");
            arylstDisableList.add("butAdvtDate");
          } else if (!oHrmDeputationApplicationHdrBean.getAdvtNo().equalsIgnoreCase("null")) {
            arylstEnableList.add("advtDate");
            arylstEnableList.add("butAdvtDate");
          }  
      } else if (EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getDeputStatus())) {
        if (oHrmDeputationApplicationHdrBean.getDeputStatus().equalsIgnoreCase("P") || oHrmDeputationApplicationHdrBean.getDeputStatus().equalsIgnoreCase("A") || oHrmDeputationApplicationHdrBean.getDeputStatus().equalsIgnoreCase("R")) {
          arylstDisableList.add("applnNo");
          arylstDisableList.add("applnDate");
          arylstDisableList.add("deputType");
          arylstDisableList.add("butEmployeeNo");
          arylstDisableList.add("employeeNo");
          arylstDisableList.add("empName");
          arylstDisableList.add("deputStatus");
          arylstDisableList.add("butApplnNo");
          arylstDisableList.add("butApplnDate");
          arylstDisableList.add("butApplnDate");
          arylstDisableList.add("advtNo");
          arylstDisableList.add("advtDate");
          arylstDisableList.add("orgName");
          arylstDisableList.add("postCode");
          arylstDisableList.add("postName");
          arylstDisableList.add("reason");
          arylstDisableList.add("butPostName");
          arylstDisableList.add("butAdvtDate");
          arylstDisableList.add("butAdvtNo");
        } else {
          if (EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getDeputType()))
            if (oHrmDeputationApplicationHdrBean.getDeputType().equalsIgnoreCase("W")) {
              arylstDisableList.add("postCode");
              arylstDisableList.add("postName");
              arylstDisableList.add("orgName");
              arylstEnableList.add("butPostName");
            } else if (oHrmDeputationApplicationHdrBean.getDeputType().equalsIgnoreCase("F")) {
              arylstDisableList.add("postCode");
              arylstEnableList.add("postName");
              arylstEnableList.add("orgName");
              arylstDisableList.add("butPostName");
            } else if (oHrmDeputationApplicationHdrBean.getDeputType().equalsIgnoreCase("O")) {
              arylstDisableList.add("postCode");
              arylstEnableList.add("postName");
              arylstEnableList.add("orgName");
              arylstDisableList.add("butPostName");
            }  
          if (EnrgiseUtil.checkString(oHrmDeputationApplicationHdrBean.getAdvtNo()))
            if (oHrmDeputationApplicationHdrBean.getAdvtNo().equalsIgnoreCase("null")) {
              arylstDisableList.add("advtDate");
              arylstDisableList.add("butAdvtDate");
            } else if (!oHrmDeputationApplicationHdrBean.getAdvtNo().equalsIgnoreCase("null")) {
              arylstEnableList.add("advtDate");
              arylstEnableList.add("butAdvtDate");
            }  
        } 
      } 
    } 
    oHashMap.put("D", arylstDisableList);
    oHashMap.put("E", arylstEnableList);
    return oHashMap;
  }
  
  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();
  }
  
  public void onLoadAction(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {}
}
