package wenrgise.hrms.ejb.business;

import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.bean.LOVBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseMessageKeyException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.DateUtility;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.MessageKey;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.utility.UserInfo;
import wenrgise.common.utility.WorkFlowServiceLocator;
import wenrgise.common.vo.LovQueryVO;
import wenrgise.common.vo.LovVO;
import wenrgise.ejb.common.helper.DBObject;
import wenrgise.ejb.common.helper.QueryRow;
import wenrgise.ejb.common.helper.QueryValue;
import wenrgise.ejb.common.utility.DBUtilitiesBean;
import wenrgise.hrms.bean.HrmAdvSettleHdrBean;
import wenrgise.hrms.vo.HrmAdvSettleQVO;
import wenrgise.workflow.bean.WflAuthorizationBean;
import wenrgise.workflow.core.WflDocumentInfo;
import wenrgise.workflow.core.WflResource;
import wenrgise.workflow.core.WflSite;
import wenrgise.workflow.core.WflStatus;
import wenrgise.workflow.core.impl.WflDocumentInfoImpl;
import wenrgise.workflow.core.impl.WflResourceImpl;
import wenrgise.workflow.core.impl.WflSiteImpl;
import wenrgise.workflow.ejb.facade.WorkFlowFacade;
import wenrgise.workflow.ejb.facade.WorkFlowFacadeHome;

public class HrmAdvSettlementBO extends HrmBaseBO {
  public HrmAdvSettlementBO() {}
  
  public HrmAdvSettlementBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmAdvSettlementHdrMetaInfo(HrmAdvSettleQVO oHrmAdvSettleQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sEmpNo = oHrmAdvSettleQVO.getEmployeeNumber();
    String sCode = oHrmAdvSettleQVO.getAdvanceCodeId();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmAdvSettleQVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(2, 1, 12, sEmpNo));
    oParameters.add(new DBObject(3, 1, 12, sCode));
    oParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAdvSettleQVO.getFromDate())));
    oParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAdvSettleQVO.getToDate())));
    oParameters.add(new DBObject(6, 2, -5));
    oParameters.add(new DBObject(7, 2, 93));
    oParameters.add(new DBObject(8, 2, 12));
    oParameters.add(new DBObject(9, 2, 12));
    oParameters.add(new DBObject(10, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVSETTLE.proc_HrEmpAdvApplHdrCount(?,?,?,?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = oOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = oOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmAdvSettlementHeader(HrmAdvSettleQVO oHrmAdvSettleQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sEmpNo = oHrmAdvSettleQVO.getEmployeeNumber();
    String sCode = oHrmAdvSettleQVO.getAdvanceCodeId();
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList oList = null;
    Iterator oIt = null;
    ArrayList oEmpAdvAppDetail = null;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    oParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    oParameters.add(new DBObject(3, 1, 12, oHrmAdvSettleQVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(4, 1, 12, sEmpNo));
    oParameters.add(new DBObject(5, 1, 12, sCode));
    oParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAdvSettleQVO.getFromDate())));
    oParameters.add(new DBObject(7, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmAdvSettleQVO.getToDate())));
    oParameters.add(new DBObject(8, 2, -10));
    oParameters.add(new DBObject(9, 2, 12));
    oParameters.add(new DBObject(10, 2, 12));
    oParameters.add(new DBObject(11, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVSETTLE.proc_HrEmpAdvApplHdr(?,?,?,?,?,?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)oOutArray.get(0)).getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    count = 0;
    oIt = oList.iterator();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (oIt.hasNext()) {
      if (count == 0)
        oEmpAdvAppDetail = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmAdvSettleHdrBean oHrmAdvSettleHdrBean = new HrmAdvSettleHdrBean();
      oHrmAdvSettleHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmAdvSettleHdrBean.setEmployeeNumber(oRow.get("EMP_NO").getString());
      oHrmAdvSettleHdrBean.setFirstName(oRow.get("FIRST_NAME").getString());
      oHrmAdvSettleHdrBean.setMiddleName(oRow.get("MIDDLE_NAME").getString());
      oHrmAdvSettleHdrBean.setLastName(oRow.get("LAST_NAME").getString());
      oHrmAdvSettleHdrBean.setEmployeeId(oRow.get("E_PER_DTL_ID").getString());
      oHrmAdvSettleHdrBean.setAdvanceCodeId(oRow.get("ID").getString());
      oHrmAdvSettleHdrBean.setAdvanceCode(oRow.get("NAME").getString());
      oHrmAdvSettleHdrBean.setDateApplied(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oHrmAdvSettleHdrBean.setAmountApplied(oRow.get("SANCTIONED_AMT").getString());
      oHrmAdvSettleHdrBean.setSettleId(oRow.get("ID").getString());
      oHrmAdvSettleHdrBean.setReason(oRow.get("SETL_REJECTION_REMARK").getString());
      oHrmAdvSettleHdrBean.setNoOfIns(oRow.get("SETL_PERIOD").getString());
      oHrmAdvSettleHdrBean.setSettleAmount(oRow.get("SETL_AMOUNT").getString());
      oEmpAdvAppDetail.add(oHrmAdvSettleHdrBean);
    } 
    return oEmpAdvAppDetail;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_EMP_ADV_TXN";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {
    System.out.println("Save Ille!");
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    System.out.println("Update ille!");
  }
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "saveNewHeaderImpl ille!";
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  private void checkUniqueHeader(HrmAdvSettleHdrBean oHrmAdvSettleHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String payrollFlag = null;
    DateUtility d = new DateUtility();
    HrmAdvSettleHdrBean oHrmAdvSettleHdrBean = (HrmAdvSettleHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("U")) {
      oParameters = new ArrayList();
      oParameters.add(new DBObject(1, 1, 12, "U"));
      oParameters.add(new DBObject(3, 1, 12, oHrmAdvSettleHdrBean.getNoOfIns()));
      oParameters.add(new DBObject(4, 1, 12, oHrmAdvSettleHdrBean.getReason()));
      oParameters.add(new DBObject(5, 1, 12, oHrmAdvSettleHdrBean.getSettleAmount()));
      oParameters.add(new DBObject(6, 1, 12, this.oUserInfo.getUserTypeId()));
      oParameters.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
      oParameters.add(new DBObject(8, 1, 12, oHrmAdvSettleHdrBean.getHeaderPrimaryKey()));
      oParameters.add(new DBObject(9, 2, 12));
      oParameters.add(new DBObject(10, 2, 12));
      oParameters.add(new DBObject(11, 2, 12));
      oParameters.add(new DBObject(12, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVSETTLE.proc_UpsertHrAdvanceSettleHdr(?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("D")) {
      returnString = null;
    } 
    return returnString;
  }
  
  public LovVO getHrmAdvSettleAdvCdLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("ID");
    oHeaderList.add("hrm.HrmAdvSettle.advanceCode");
    oHeaderList.add("hrm.HrmAdvSettle.dateApplied");
    oHeaderList.add("hrm.HrmAdvSettle.amountApplied");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    String employeeId = null;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getProperty("employeeId") != null) {
      employeeId = oLovQueryVO.getProperty("employeeId");
      System.out.println(employeeId);
    } 
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    oParameters.add(new DBObject(2, 1, 12, employeeId));
    oParameters.add(new DBObject(3, 2, -10));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 12));
    oParameters.add(new DBObject(6, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVSETTLE.proc_GetHrmAdvSettleCdLOVdata(?,?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = oList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        oList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("NAME").getString());
      oLOVBean.setDetailField3(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oLOVBean.setDetailField4(oRow.get("SANCTIONED_AMT").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrorList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmAdvSettleHdrBean)oBaseHeaderBean);  
    reportError(oErrorList);
  }
  
  private void checkMandatoryHeader(HrmAdvSettleHdrBean oHrmAdvSettleHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmAdvSettleHdrBean.getAdvanceCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmAdvSettle.advanceCode");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  public String approveAdvSettlement(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    HrmAdvSettleHdrBean oHrmAdvSettleHdrBean = (HrmAdvSettleHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    if (!EnrgiseUtil.checkString(oBaseHeaderBean.getWorkListId())) {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", "Initiated");
    } else {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", (String)null);
    } 
    if (status.getStatus().equalsIgnoreCase("FinallyApproved")) {
      oBean = new DBUtilitiesBean();
      ArrayList arylstParameters = new ArrayList();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMADVSETTLE.procApproveAdvSettle(?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  public String rejectAdvSettlement(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    HrmAdvSettleHdrBean oHrmAdvSettleHdrBean = (HrmAdvSettleHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    if (!EnrgiseUtil.checkString(oBaseHeaderBean.getWorkListId())) {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Reject", "Initiated");
    } else {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Reject", (String)null);
    } 
    if (status.getStatus().equalsIgnoreCase("Rejected")) {
      oBean = new DBUtilitiesBean();
      ArrayList arylstParameters = new ArrayList();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMADVSETTLE.procRejectAdvSettle(?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  public String submitAdvSettlement(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    HrmAdvSettleHdrBean oHrmAdvSettleHdrBean = (HrmAdvSettleHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    if (!EnrgiseUtil.checkString(oBaseHeaderBean.getWorkListId())) {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", "Initiated");
    } else {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", (String)null);
    } 
    if (status.getStatus().equalsIgnoreCase("Pending")) {
      oBean = new DBUtilitiesBean();
      ArrayList arylstParameters = new ArrayList();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMADVSETTLE.procSubmitAdvSettle(?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    HrmAdvSettleHdrBean oHrmAdvSettleHdrBean = (HrmAdvSettleHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D")); 
    reportError(arylstErrorList);
  }
  
  public WflStatus callWorkFlow(BaseHeaderBean oBaseHeaderBean, ArrayList arylstDetailBeanArray, String activity, String initiatedFlag) throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      WorkFlowFacadeHome oHome = (WorkFlowFacadeHome)WorkFlowServiceLocator.getLocator().getService("WorkFlowFacade");
      WorkFlowFacade workFlowFacade = oHome.create();
      HrmAdvSettleHdrBean oHrmAdvSettleHdrBean = (HrmAdvSettleHdrBean)oBaseHeaderBean;
      WflResourceImpl wflResourceImpl = new WflResourceImpl();
      wflResourceImpl.setEmployeeId(this.oUserInfo.getUserTypeId());
      WflSiteImpl wflSiteImpl = new WflSiteImpl();
      wflSiteImpl.setSiteId(this.oUserInfo.getSiteId());
      wflResourceImpl.setLoginSite((WflSite)wflSiteImpl);
      WflDocumentInfoImpl wflDocumentInfoImpl = new WflDocumentInfoImpl();
      wflDocumentInfoImpl.setRequester((WflResource)wflResourceImpl);
      wflDocumentInfoImpl.setDocumentId(oHrmAdvSettleHdrBean.getHeaderPrimaryKey());
      wflDocumentInfoImpl.setDocumentType("Advance");
      wflDocumentInfoImpl.setInitiatedFlag(initiatedFlag);
      String documentTypeId = workFlowFacade.getDocumentTypeId("AdvanceSettle");
      if (documentTypeId == null)
        throw new EnrgiseSystemException(); 
      if (!EnrgiseUtil.checkString(initiatedFlag))
        wflDocumentInfoImpl.setWorkListId(oBaseHeaderBean.getWorkListId()); 
      String activityId = workFlowFacade.getActivityId(activity);
      if (activityId == null)
        throw new EnrgiseSystemException(); 
      wflDocumentInfoImpl.setDocumentTypeId(documentTypeId);
      if (!activity.equalsIgnoreCase("Reject")) {
        wflDocumentInfoImpl.setDocumentNumber(String.valueOf(String.valueOf("Advance Settlement No: ").concat(String.valueOf(oHrmAdvSettleHdrBean.getHeaderPrimaryKey()))).concat(String.valueOf("is pending for approval")));
        wflDocumentInfoImpl.setDocDesc(String.valueOf("The following document has been pending for approval:   Advance Settlement No:").concat(String.valueOf(oHrmAdvSettleHdrBean.getHeaderPrimaryKey())));
      } else if (!activity.equalsIgnoreCase("Approve")) {
        wflDocumentInfoImpl.setDocumentNumber(String.valueOf(String.valueOf("Advance Settlement No: ").concat(String.valueOf(oHrmAdvSettleHdrBean.getHeaderPrimaryKey()))).concat(String.valueOf("is pending for rejection")));
        wflDocumentInfoImpl.setDocDesc(String.valueOf("The following document has been pending for rejection:   Advance Settlement No:").concat(String.valueOf(oHrmAdvSettleHdrBean.getHeaderPrimaryKey())));
      } 
      wflDocumentInfoImpl.setModuleId("8");
      wflDocumentInfoImpl.setCreator((WflResource)wflResourceImpl);
      wflDocumentInfoImpl.setRequesterAction(activityId);
      String sAdvAmt = oHrmAdvSettleHdrBean.getAmountApplied();
      HashMap oProp = new HashMap();
      oProp.put("Advance_Amt", sAdvAmt);
      wflDocumentInfoImpl.setDocumentAttributes(oProp);
      WflAuthorizationBean wflAuthBean = workFlowFacade.canDo((WflDocumentInfo)wflDocumentInfoImpl);
      if (EnrgiseUtil.checkString(wflAuthBean.getErrorCode()))
        throw new EnrgiseApplicationException(wflAuthBean.getErrorCode()); 
      if (!wflAuthBean.isAuthStatus())
        throw new EnrgiseApplicationException("wenrgise.workflow.submit.notauthorized"); 
      WflStatus wflStatus = workFlowFacade.process((WflDocumentInfo)wflDocumentInfoImpl);
      if (wflStatus.getStatus().equals("Error"))
        throw new EnrgiseSystemException(); 
      workFlowFacade.remove();
      return wflStatus;
    } catch (RemoteException oRtEx) {
      throw new EnrgiseSystemException("wenrgise.workflow.connect", oRtEx);
    } catch (CreateException oCx) {
      throw new EnrgiseSystemException("wenrgise.workflow.connect", oCx);
    } catch (RemoveException oRx) {
      throw new EnrgiseSystemException("wenrgise.workflow.connect", oRx);
    } 
  }
}
