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.Iterator;
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.HrmMyWorkflowDtlBean;
import wenrgise.hrms.bean.HrmMyWorkflowHdrBean;
import wenrgise.hrms.businessdelegate.HrmBaseBD;
import wenrgise.hrms.ejb.facade.HrmFacade;
import wenrgise.hrms.ejb.facade.HrmFacadeHome;
import wenrgise.hrms.vo.HrmMyWorkflowQVO;

public class HrmMyWorkflowBD extends HrmBaseBD {
  public RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmFacadeHome oHome = (HrmFacadeHome)ServiceLocator.getLocator().getService("HrmFacade");
      HrmFacade oHrmFacade = oHome.create();
      return oHrmFacade.getHrmMyWorkflowHdrMetaInfo((HrmMyWorkflowQVO)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.getHrmMyWorkflowHdrInfo((HrmMyWorkflowQVO)oQueryVO, lStartPosition, lLastPosition);
      return oHeaderList;
    } 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 getInsertDataImpl(BaseQueryVO oQueryVO) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return "Only Implementation";
  }
  
  public ArrayList getDetailRecordImpl(BaseQueryVO oBaseQueryVO, String sScreenName, long lAbsoluteStart, long lAbsoluteEnd) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmFacadeHome oHome = (HrmFacadeHome)ServiceLocator.getLocator().getService("HrmFacade");
      HrmFacade oHrmFacade = oHome.create();
      if (sScreenName.equalsIgnoreCase("HrmMyWorkflow"))
        return oHrmFacade.getHrmMyWorkflowDetailInfo(oBaseQueryVO, lAbsoluteStart, lAbsoluteEnd); 
      return null;
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public RecordMetaInfo getTotalDetailRecordCountImpl(BaseQueryVO oBaseQueryVO, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmFacadeHome oHome = (HrmFacadeHome)ServiceLocator.getLocator().getService("HrmFacade");
      HrmFacade oHrmFacade = oHome.create();
      if (sScreenName.equalsIgnoreCase("HrmMyWorkflow"))
        return oHrmFacade.getHrmMyWorkflowDetailMetaInfo(oBaseQueryVO); 
      return null;
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public Map getDisabledFieldsImpl(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    HashMap oHashMap = new HashMap();
    ArrayList arylstEnab = new ArrayList();
    ArrayList arylstDisab = new ArrayList();
    HrmMyWorkflowHdrBean oHrmMyWorkflowHdrBean = (HrmMyWorkflowHdrBean)oThisPageVO.getOHeaderBean();
    ArrayList oDetailList = oThisPageVO.getODetailList();
    arylstDisab.add("butDelete");
    arylstDisab.add("butAddRow");
    arylstDisab.add("butDelRow");
    arylstDisab.add("butAct");
    if (oThisPageVO.getScreenMode().equalsIgnoreCase("Q") || oThisPageVO.getScreenMode().equalsIgnoreCase("U"))
      if (EnrgiseUtil.checkString(oHrmMyWorkflowHdrBean.getWorkflowType()))
        if (oHrmMyWorkflowHdrBean.getWorkflowType().equalsIgnoreCase("W") && oHrmMyWorkflowHdrBean.getTxtStatus().equalsIgnoreCase("P")) {
          if (oDetailList != null)
            if (oThisPageVO.getScreenName().equalsIgnoreCase("HrmMyWorkflow")) {
              Iterator oIt = oDetailList.iterator();
              while (oIt.hasNext()) {
                HrmMyWorkflowDtlBean oHrmMyWorkflowDtlBean = oIt.next();
                if (!oHrmMyWorkflowDtlBean.getStatus().equalsIgnoreCase("N"))
                  arylstEnab.add("butAct"); 
              } 
            }  
        } else {
          arylstDisab.add("butAct");
        }   
    if (!oHrmMyWorkflowHdrBean.equals(null))
      if (oThisPageVO.getScreenMode().equalsIgnoreCase("U")) {
        arylstDisab.add("butSave");
        arylstDisab.add("butId");
      }  
    oHashMap.put("E", arylstEnab);
    oHashMap.put("D", arylstDisab);
    return oHashMap;
  }
  
  public String saveImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws RemoteException, 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 getTotalDetailRecordCountImpl(String lPrimaryKey, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    return null;
  }
  
  public ArrayList getDetailRecordImpl(String lPrimaryKey, String sScreenName, long lAbsoluteStart, long lAbsoluteEnd) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return null;
  }
}
