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.BaseDetailInfo;
import wenrgise.common.vo.BaseDetailVO;
import wenrgise.common.vo.BaseQueryVO;
import wenrgise.common.vo.DetailSizeValues;
import wenrgise.common.vo.ThisPageVO;
import wenrgise.ejb.common.session.UserSession;
import wenrgise.ejb.common.utility.ServiceLocator;
import wenrgise.hrms.bean.HrmAttEmpAttInHdrBean;
import wenrgise.hrms.businessdelegate.HrmBaseBD;
import wenrgise.hrms.ejb.facade.HrmSecondFacade;
import wenrgise.hrms.ejb.facade.HrmSecondFacadeHome;
import wenrgise.hrms.vo.HrmAttEmpAttInQVO;

public class HrmAttEmpInBD extends HrmBaseBD {
  public RecordMetaInfo getTotalDetailRecordCountImpl(String sPrimaryKey, HrmAttEmpAttInQVO objHrmAttEmpAttInQVO, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    RecordMetaInfo oRecordMetaInfo = null;
    return oRecordMetaInfo;
  }
  
  public BaseDetailVO getDetailRecord(String sFormName, String sScreenName, String sPrimaryKey, long lPageRequested, DetailSizeValues oDetailSizeValues, BaseDetailVO oBaseDetailVO, UserSession oUser, BaseDetailInfo oBaseDetailInfo, boolean bForce) throws EnrgiseApplicationException, EnrgiseSystemException {
    return null;
  }
  
  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 void onLoadAction(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      if (oThisPageVO.getActionName() == 10 || oThisPageVO.getActionName() == 10 || oThisPageVO.getActionName() == 21 || oThisPageVO.getActionName() == 13) {
        HrmAttEmpAttInHdrBean hrmAttEmpAttInHdrBean = (HrmAttEmpAttInHdrBean)oThisPageVO.getOHeaderBean();
        hrmAttEmpAttInHdrBean.setEmpId(this.oUserInfo.getUserTypeId());
        hrmAttEmpAttInHdrBean.setEmployeeNo(this.oUserInfo.getUserId());
        String[] oName = this.oUserInfo.getUserName().split(" ");
        hrmAttEmpAttInHdrBean.setFirstName(oName[0]);
        hrmAttEmpAttInHdrBean.setMiddleName(oName[1]);
        hrmAttEmpAttInHdrBean.setLastName(oName[2]);
      } 
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmAttEmpAttInHdrBean oHrmAttEmpAttInHdrBean1 = (HrmAttEmpAttInHdrBean)oThisPageVO.getOHeaderBean();
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      HrmAttEmpAttInHdrBean oHrmAttEmpAttInHdrBean = oHrmSecondFacade.getOnLoadSysDtTime(oHrmAttEmpAttInHdrBean1);
      oThisPageVO.setOHeaderBean((BaseHeaderBean)oHrmAttEmpAttInHdrBean);
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      return oHrmSecondFacade.getHrmAttHdrMetaInfo((HrmAttEmpAttInQVO)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 {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      ArrayList oHeaderList = oHrmSecondFacade.getHrmAttHeaderInfo((HrmAttEmpAttInQVO)oQueryVO, lStartPosition, lLastPosition);
      System.out.println(oHeaderList.size());
      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 saveImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      return oHrmSecondFacade.saveHrmAttEmpIn((HrmAttEmpAttInHdrBean)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 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 Map getDisabledFieldsImpl(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    HashMap oHashMap = new HashMap();
    ArrayList oEnableList = new ArrayList();
    ArrayList oDisableList = new ArrayList();
    HrmAttEmpAttInHdrBean oHrmAttEmpAttInHdrBean = (HrmAttEmpAttInHdrBean)oThisPageVO.getOHeaderBean();
    oDisableList.add("butExecute");
    oDisableList.add("butInsert");
    oEnableList.add("butSave");
    if (!oHrmAttEmpAttInHdrBean.equals(null))
      if (EnrgiseUtil.checkString(oHrmAttEmpAttInHdrBean.getAttndStatus())) {
        String sAttStatus = oHrmAttEmpAttInHdrBean.getAttndStatus();
        if (String.valueOf(sAttStatus).equalsIgnoreCase("L")) {
          oEnableList.add("reasons");
        } else if (String.valueOf(sAttStatus).equalsIgnoreCase("T")) {
          oDisableList.add("reasons");
        } 
      }  
    oHashMap.put("D", oDisableList);
    oHashMap.put("E", oEnableList);
    return oHashMap;
  }
}
