package wenrgise.workflow.ejb.business;

import java.util.ArrayList;
import java.util.Iterator;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
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.workflow.bean.DocHistoryDtlBean;

public class DocHistoryDtlBO extends WorkFlowBaseBO {
  public ArrayList getDocHistDtl(String sDocID, String sDocType, String sModuleID) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sActivity = "";
    ArrayList arylstOutArray = new ArrayList();
    DocHistoryDtlBean oDocHistoryDtlBean = null;
    ArrayList oDocHistDtl = null;
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList oList = null;
    oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sDocID));
    arylstParameters.add(new DBObject(2, 1, 12, sDocType));
    arylstParameters.add(new DBObject(3, 1, 12, sModuleID));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    arylstOutArray = oBean.callProc(arylstParameters, "WFLDOCUMENTHISTORY.proc_WflDocHistDtl(?,?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)arylstOutArray.get(0)).getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (oDocHistDtl == null)
        oDocHistDtl = new ArrayList(); 
      count++;
      oRow = oIt.next();
      oDocHistoryDtlBean = new DocHistoryDtlBean();
      oDocHistoryDtlBean.setTxtSrlNo(String.valueOf(count));
      oDocHistoryDtlBean.setTxtEmpNum(oRow.get("empName").getString());
      oDocHistoryDtlBean.setTxtDocType(oRow.get("doc_type_desc").getString());
      oDocHistoryDtlBean.setTxtStartTime(oRow.get("stDate").getString());
      oDocHistoryDtlBean.setTxtDuration(oRow.get("duration").getString());
      sActivity = oRow.get("status").getString();
      if (sActivity.equalsIgnoreCase("A")) {
        oDocHistoryDtlBean.setTxtActivity("Approved");
      } else {
        oDocHistoryDtlBean.setTxtActivity("Pending");
      } 
      oDocHistDtl.add(oDocHistoryDtlBean);
    } 
    return oDocHistDtl;
  }
}
