package 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.HrmATDDeputChrgRptHdrBean;
import wenrgise.hrms.ejb.facade.HrmThirdFacade;
import wenrgise.hrms.ejb.facade.HrmThirdFacadeHome;
import wenrgise.hrms.vo.HrmATDDptnChrgRptQVO;

public class HrmATDDptnChrgRptBD extends HrmBaseBD {
  public boolean updateHeaderRecordImpl(BaseHeaderBean oBaseHeaderBean) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return true;
  }
  
  public String getInsertDataImpl(BaseQueryVO oQueryVO) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return "Only Implementation";
  }
  
  public ArrayList getDetailRecordImpl(String lPrimaryKey, String sScreenName, long lAbsoluteStart, long lAbsoluteEnd) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return null;
  }
  
  public RecordMetaInfo getTotalDetailRecordCountImpl(String lPrimaryKey, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    return null;
  }
  
  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 RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      return oHrmThirdFacade.getHrmDeputChargeRepHdrMetaInfo((HrmATDDptnChrgRptQVO)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.getHrmDeputChargeRepHeaderInfo((HrmATDDptnChrgRptQVO)oQueryVO, lStartPosition, lLastPosition, this.oUserInfo);
      return oHeaderList;
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  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((HrmATDDeputChrgRptHdrBean)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();
    HrmATDDeputChrgRptHdrBean oHrmATDDeputChrgRptHdrBean = (HrmATDDeputChrgRptHdrBean)oThisPageVO.getOHeaderBean();
    ArrayList oDetailList = oThisPageVO.getODetailList();
    if (!oHrmATDDeputChrgRptHdrBean.equals(null)) {
      if (oThisPageVO.getScreenMode().equalsIgnoreCase("Q") || oThisPageVO.getScreenMode().equalsIgnoreCase("N")) {
        arylstDisableList.add("butSubmit");
        arylstDisableList.add("butApprove");
        arylstDisableList.add("butReject");
      } else if (oHrmATDDeputChrgRptHdrBean.getChargeStatus().equalsIgnoreCase("A")) {
        arylstDisableList.add("butSubmit");
        arylstDisableList.add("butApprove");
        arylstDisableList.add("butReject");
      } else if (oHrmATDDeputChrgRptHdrBean.getChargeStatus().equalsIgnoreCase("P")) {
        arylstEnableList.add("butApprove");
        arylstEnableList.add("butReject");
        arylstDisableList.add("butSubmit");
      } else if (oHrmATDDeputChrgRptHdrBean.getChargeStatus().equalsIgnoreCase("R")) {
        arylstDisableList.add("butApprove");
        arylstDisableList.add("butReject");
        arylstDisableList.add("butSubmit");
      } else if (oHrmATDDeputChrgRptHdrBean.getChargeStatus().equalsIgnoreCase("N")) {
        arylstEnableList.add("butSubmit");
        arylstDisableList.add("butApprove");
        arylstDisableList.add("butReject");
      } 
      if (oThisPageVO.getScreenMode().equalsIgnoreCase("N")) {
        if (EnrgiseUtil.checkString(oHrmATDDeputChrgRptHdrBean.getChargeType()))
          arylstDisableList.add("butChargeCode"); 
      } else if (oThisPageVO.getScreenMode().equalsIgnoreCase("Q")) {
        if (EnrgiseUtil.checkString(oHrmATDDeputChrgRptHdrBean.getChargeType())) {
          arylstEnableList.add("butChargeCode");
        } else {
          arylstDisableList.add("butChargeCode");
        } 
      } else if (EnrgiseUtil.checkString(oHrmATDDeputChrgRptHdrBean.getChargeStatus())) {
        System.out.println(oHrmATDDeputChrgRptHdrBean.getChargeStatus());
        if (oHrmATDDeputChrgRptHdrBean.getChargeStatus().equalsIgnoreCase("P") || oHrmATDDeputChrgRptHdrBean.getChargeStatus().equalsIgnoreCase("A") || oHrmATDDeputChrgRptHdrBean.getChargeStatus().equalsIgnoreCase("R")) {
          arylstDisableList.add("dptOrderNo");
          arylstDisableList.add("chargeCode");
          arylstDisableList.add("chargeType");
          arylstDisableList.add("butChargeCode");
          arylstDisableList.add("noonFlag");
          arylstDisableList.add("butHandOverDate");
          arylstDisableList.add("butDptOrderNo");
          arylstDisableList.add("remarks");
        } else {
          arylstDisableList.add("butChargeCode");
        } 
      } 
    } 
    oThisPageVO.setOHeaderBean((BaseHeaderBean)oHrmATDDeputChrgRptHdrBean);
    oHashMap.put("D", arylstDisableList);
    oHashMap.put("E", arylstEnableList);
    return oHashMap;
  }
  
  public void onLoadAction(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {}
}
