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.HrmLvLedgerHdrBean;
import wenrgise.hrms.ejb.facade.HrmSecondFacade;
import wenrgise.hrms.ejb.facade.HrmSecondFacadeHome;
import wenrgise.hrms.vo.HrmLvLedgerQVO;

public class HrmLvLedgerBD extends HrmBaseBD {
  public RecordMetaInfo getTotalDetailRecordCountImpl(BaseQueryVO oBaseQueryVO, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      if (sScreenName.equalsIgnoreCase("HrmEmployeeLeaveLedger"))
        return oHrmSecondFacade.getHrmLeaveLedgerDtlMetaInfo((HrmLvLedgerQVO)oBaseQueryVO); 
      return oHrmSecondFacade.getHrmLeaveLedgerTxnDtlMetaInfo((HrmLvLedgerQVO)oBaseQueryVO);
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public ArrayList getDetailRecordImpl(BaseQueryVO oBaseQueryVO, String sScreenName, long lAbsoluteStart, long lAbsoluteEnd) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      if (sScreenName.equalsIgnoreCase("HrmEmployeeLeaveLedger"))
        return oHrmSecondFacade.getHrmLeaveLedgerDetailInfo((HrmLvLedgerQVO)oBaseQueryVO, lAbsoluteStart, lAbsoluteEnd); 
      return oHrmSecondFacade.getHrmLeaveLedgerTxnDetailInfo((HrmLvLedgerQVO)oBaseQueryVO, lAbsoluteStart, lAbsoluteEnd);
    } 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 RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    RecordMetaInfo oRecordMetaInfo = null;
    return oRecordMetaInfo;
  }
  
  public ArrayList getHeaderRecordImpl(BaseQueryVO oQueryVO, long lStartPosition, long lLastPosition) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oRet = null;
    return oRet;
  }
  
  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.saveLeaveLedger((HrmLvLedgerHdrBean)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 {
    String groupStatus;
    HashMap oHashMap = new HashMap();
    ArrayList oEnableList = new ArrayList();
    ArrayList oDisableList = new ArrayList();
    oDisableList.add("butInsert");
    oDisableList.add("butSave");
    oDisableList.add("butDelete");
    oDisableList.add("butPrint");
    oDisableList.add("butHelp");
    HrmLvLedgerHdrBean oHrmLvLedgerHdrBean = (HrmLvLedgerHdrBean)oThisPageVO.getOHeaderBean();
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      groupStatus = oHrmSecondFacade.getGroupInfo(this.oUserInfo.getUserTypeId());
    } catch (CreateException oCrtExcep) {
      throw new EnrgiseSystemException(oCrtExcep);
    } catch (RemoteException oRmtExcep) {
      throw new EnrgiseSystemException(oRmtExcep);
    } 
    if (EnrgiseUtil.checkString(groupStatus))
      if (groupStatus.equalsIgnoreCase("S")) {
        oEnableList.add("butEmpCode");
      } else {
        oDisableList.add("butEmpCode");
      }  
    if (oThisPageVO.getScreenMode().equalsIgnoreCase("Q"))
      oDisableList.add("butGetDtl2"); 
    if (oThisPageVO.getScreenMode().equalsIgnoreCase("U")) {
      oEnableList.add("butQuery");
      oDisableList.add("butExecute");
      oEnableList.add("butGetDtl2");
    } 
    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 {
    return new String("");
  }
  
  public void onLoadAction(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    HrmLvLedgerHdrBean oHrmLvLedgerHdrBean = (HrmLvLedgerHdrBean)oThisPageVO.getOHeaderBean();
    if (oThisPageVO.getActionName() == 10) {
      oHrmLvLedgerHdrBean.setEmployeeNoId(this.oUserInfo.getUserTypeId());
      oHrmLvLedgerHdrBean.setEmployeeNo(this.oUserInfo.getUserId());
      oHrmLvLedgerHdrBean.setEmployeeName(this.oUserInfo.getUserName());
    } else if (oThisPageVO.getActionName() == 13) {
      oHrmLvLedgerHdrBean.setEmployeeNoId(this.oUserInfo.getUserTypeId());
      oHrmLvLedgerHdrBean.setEmployeeNo(this.oUserInfo.getUserId());
      oHrmLvLedgerHdrBean.setEmployeeName(this.oUserInfo.getUserName());
    } else if (oThisPageVO.getActionName() == 19) {
      oHrmLvLedgerHdrBean.setEmployeeNoId(this.oUserInfo.getUserTypeId());
      oHrmLvLedgerHdrBean.setEmployeeNo(this.oUserInfo.getUserId());
      oHrmLvLedgerHdrBean.setEmployeeName(this.oUserInfo.getUserName());
    } 
  }
}
