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.RecordMetaInfo;
import wenrgise.common.vo.BaseQueryVO;
import wenrgise.common.vo.ThisPageVO;
import wenrgise.ejb.common.utility.ServiceLocator;
import wenrgise.hrms.bean.HrmAprslSpcTmplHdrBean;
import wenrgise.hrms.businessdelegate.HrmBaseBD;
import wenrgise.hrms.ejb.facade.HrmThirdFacade;
import wenrgise.hrms.ejb.facade.HrmThirdFacadeHome;
import wenrgise.hrms.vo.HrmAprslSpcTmplQVO;

public class HrmAprslSpcTmplBD extends HrmBaseBD {
  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 {
      HrmThirdFacade oHrmThirdFacade = (HrmThirdFacade)getModuleFacade("ThirdHRMS");
      return oHrmThirdFacade.saveHrmAprslSpcTmp((HrmAprslSpcTmplHdrBean)oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, oDetailBeanArray, bDetailDataChanged, oDetailPicked, this.oUserInfo);
    } catch (CreateException oCrtExcep) {
      throw new EnrgiseSystemException(oCrtExcep);
    } 
  }
  
  public RecordMetaInfo getTotalDetailRecordCountImpl(String lPrimaryKey, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    try {
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      if (sScreenName.equals("HrmAprslSpcTmpl"))
        oRecordMetaInfo = oHrmThirdFacade.getHrmAprslSpcTmpKPADtlMetaInfo(lPrimaryKey); 
      if (sScreenName.equals("HrmAprslSpcTmplGoals"))
        oRecordMetaInfo = oHrmThirdFacade.getHrmAprslSpcTmpGoalsDtlMetaInfo(lPrimaryKey); 
      if (sScreenName.equals("HrmAprslSpcTmplEmpElig"))
        oRecordMetaInfo = oHrmThirdFacade.getHrmAprslSpcTmpEligDtlMetaInfo(lPrimaryKey); 
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
    return oRecordMetaInfo;
  }
  
  public ArrayList getDetailRecordImpl(String lPrimaryKey, String sScreenName, long lAbsoluteStart, long lAbsoluteEnd) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstRet = new ArrayList();
    try {
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      if (sScreenName.equals("HrmAprslSpcTmpl"))
        arylstRet = oHrmThirdFacade.getHrmAprslSpcTmpKPADetailInfo(lPrimaryKey, lAbsoluteStart, lAbsoluteEnd); 
      if (sScreenName.equals("HrmAprslSpcTmplGoals"))
        arylstRet = oHrmThirdFacade.getHrmAprslSpcTmpGoalsDetailInfo(lPrimaryKey, lAbsoluteStart, lAbsoluteEnd); 
      if (sScreenName.equals("HrmAprslSpcTmplEmpElig"))
        arylstRet = oHrmThirdFacade.getHrmAprslSpcTmpEligDetailInfo(lPrimaryKey, lAbsoluteStart, lAbsoluteEnd); 
      return arylstRet;
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      return oHrmThirdFacade.getHrmAprslSpcTmpHdrMetaInfo((HrmAprslSpcTmplQVO)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 {
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      ArrayList oHeaderList = oHrmThirdFacade.getHrmAprslSpcTmpHeaderInfo((HrmAprslSpcTmplQVO)oQueryVO, lStartPosition, lLastPosition);
      return oHeaderList;
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public String getInsertDataImpl(BaseQueryVO oQueryVO) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return null;
  }
  
  public Map getDisabledFieldsImpl(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    HashMap oHashMap = new HashMap();
    ArrayList oEnableList = new ArrayList();
    ArrayList oDisableList = new ArrayList();
    if (oThisPageVO.getScreenMode().equalsIgnoreCase("U")) {
      oDisableList.add("butTemplateName");
      oDisableList.add("butClassHdr");
      oDisableList.add("butClassDtl");
      oDisableList.add("butSiteCode");
      oDisableList.add("butDeptCode");
      oDisableList.add("butEmpNo");
      oDisableList.add("butStOrderNo");
      oDisableList.add("butFromDate");
      oDisableList.add("butToDate");
      oDisableList.add("splTemplateName");
      oDisableList.add("butSplTemplateName");
      oEnableList.add("butGetDetail");
    } 
    if (oThisPageVO.getScreenMode().equalsIgnoreCase("Q")) {
      oDisableList.add("butClassHdr");
      oDisableList.add("butClassDtl");
      oDisableList.add("butSiteCode");
      oDisableList.add("butDeptCode");
      oDisableList.add("butEmpNo");
      oDisableList.add("butStOrderNo");
      oDisableList.add("butTemplateName");
    } 
    if (oThisPageVO.getScreenMode().equalsIgnoreCase("N")) {
      oDisableList.add("butSplTemplateName");
      oDisableList.add("butFromDate");
      oDisableList.add("butToDate");
    } 
    oHashMap.put("D", oDisableList);
    oHashMap.put("E", oEnableList);
    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 {
    try {
      String sHeaderPrimaryKey = null;
      HrmThirdFacadeHome oHome = (HrmThirdFacadeHome)ServiceLocator.getLocator().getService("HrmThirdFacade");
      HrmThirdFacade oHrmThirdFacade = oHome.create();
      if (sButtonName.equalsIgnoreCase("butApprove"))
        sHeaderPrimaryKey = oHrmThirdFacade.approveHrmAprslSpcTmp((HrmAprslSpcTmplHdrBean)oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, oDetailBeanArray, bDetailDataChanged, oDetailPicked, this.oUserInfo); 
      if (sButtonName.equalsIgnoreCase("butReject"))
        sHeaderPrimaryKey = oHrmThirdFacade.rejectHrmAprslSpcTmp((HrmAprslSpcTmplHdrBean)oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, oDetailBeanArray, bDetailDataChanged, oDetailPicked, this.oUserInfo); 
      return sHeaderPrimaryKey;
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public void onLoadAction(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    if (oThisPageVO.getActionName() == 13 || oThisPageVO.getActionName() == 10) {
      HrmAprslSpcTmplHdrBean oHrmAprslSpcTmplHdrBean = (HrmAprslSpcTmplHdrBean)oThisPageVO.getOHeaderBean();
      oHrmAprslSpcTmplHdrBean.setEmployeeId(this.oUserInfo.getUserTypeId());
      oHrmAprslSpcTmplHdrBean.setEmpLoyeeNumber(this.oUserInfo.getUserId());
      oHrmAprslSpcTmplHdrBean.setEmployeeName(this.oUserInfo.getUserName());
    } 
  }
}
