package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
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.vo.BaseDetailVO;
import wenrgise.common.vo.BaseHeaderVO;
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.HrmAprslEmpDtlsBean;
import wenrgise.hrms.bean.HrmSepOrderDtlBean;
import wenrgise.hrms.bean.HrmSepOrderHdrBean;
import wenrgise.hrms.vo.HrmSepOrderQVO;

public class HrmSepOrderBO extends HrmBaseBO {
  public HrmSepOrderBO() {}
  
  public HrmSepOrderBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public LovVO getHrmSepOrderNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("Id");
    arylstHeaderNames.add("hrm.HrmSepOrder.orderNo");
    arylstHeaderNames.add("hrm.HrmSepOrder.orderDate");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    String sQuerySearch1 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 2, -10));
    arylstParameters.add(new DBObject(3, 2, 12));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPORDER.procHrmSepOrderNoLOVdata(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("ORDER_NO").getString());
      oLOVBean.setDetailField3(EnrgiseUtil.convertToString(oRow.get("ORDER_DATE").getDate()));
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmSepOrderApplnNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("ApplicationId");
    arylstHeaderNames.add("hrm.HrmSepOrder.applnNo");
    arylstHeaderNames.add("hrm.HrmSepOrder.applnDate");
    arylstHeaderNames.add("hrm.HrmSepApplication.initiatedBy");
    arylstHeaderNames.add("empId");
    arylstHeaderNames.add("hrm.HrmSepApplication.employeeNo");
    arylstHeaderNames.add("hrm.HrmSepOrder.employeeName");
    arylstHeaderNames.add("sepCatId");
    arylstHeaderNames.add("hrm.HrmSepOrder.separationCategory");
    arylstHeaderNames.add("hrm.HrmSepOrder.requestedSepDate");
    arylstHeaderNames.add("hrm.HrmSepApplication.reason");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 2, -10));
    arylstParameters.add(new DBObject(3, 2, 12));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPORDER.procHrmSepOrderApplnNoLOVdata(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("Appln_Id").getString());
      oLOVBean.setDetailField2(oRow.get("APPLICATION_NO").getString());
      oLOVBean.setDetailField3(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oLOVBean.setDetailField4(oRow.get("INITIATED_BY").getString());
      oLOVBean.setDetailField5(oRow.get("E_PER_DTL_ID").getString());
      oLOVBean.setDetailField6(oRow.get("emp_no").getString());
      oLOVBean.setDetailField7(oRow.get("EMPNAME").getString());
      oLOVBean.setDetailField8(oRow.get("sep_cat_id").getString());
      oLOVBean.setDetailField9(oRow.get("DESCRIPTION").getString());
      oLOVBean.setDetailField10(EnrgiseUtil.convertToString(oRow.get("REQUESTED_SEP_DATE").getDate()));
      oLOVBean.setDetailField11(oRow.get("REASON").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmSepOrderApplnNoQLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("ApplicationId");
    arylstHeaderNames.add("hrm.HrmSepOrder.applnNo");
    arylstHeaderNames.add("hrm.HrmSepOrder.applnDate");
    arylstHeaderNames.add("hrm.HrmSepApplication.initiatedBy");
    arylstHeaderNames.add("empId");
    arylstHeaderNames.add("hrm.HrmSepApplication.employeeNo");
    arylstHeaderNames.add("hrm.HrmSepOrder.employeeName");
    arylstHeaderNames.add("sepCatId");
    arylstHeaderNames.add("hrm.HrmSepOrder.separationCategory");
    arylstHeaderNames.add("hrm.HrmSepOrder.requestedSepDate");
    arylstHeaderNames.add("hrm.HrmSepApplication.reason");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 2, -10));
    arylstParameters.add(new DBObject(3, 2, 12));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPORDER.procHrmSepOrderApplnNoLOVQdata(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("Appln_Id").getString());
      oLOVBean.setDetailField2(oRow.get("APPLICATION_NO").getString());
      oLOVBean.setDetailField3(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oLOVBean.setDetailField4(oRow.get("INITIATED_BY").getString());
      oLOVBean.setDetailField5(oRow.get("E_PER_DTL_ID").getString());
      oLOVBean.setDetailField6(oRow.get("emp_no").getString());
      oLOVBean.setDetailField7(oRow.get("EMPNAME").getString());
      oLOVBean.setDetailField8(oRow.get("sep_cat_id").getString());
      oLOVBean.setDetailField9(oRow.get("DESCRIPTION").getString());
      oLOVBean.setDetailField10(EnrgiseUtil.convertToString(oRow.get("REQUESTED_SEP_DATE").getDate()));
      oLOVBean.setDetailField11(oRow.get("REASON").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getSepApprNameLOVData(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = "select hep.id,(hep.first_name || ' ' || hep.middle_name || ' ' || hep.last_name) as empName from hrm_emp_pers hep  ";
    sQuery = String.valueOf(sQuery).concat(String.valueOf(" where hep.id not in (select distinct hecm.E_PER_DTL_ID from hrm_emp_class_map hecm, hrm_class_dtl hcd, hrm_class_mst hcm where hecm.cls_dt_id = hcd.id and hcm.code = '20' and hcd.code in ('30', '31', '40', '41', '42')) "));
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField1()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hep.emp_no) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField1()))).concat(String.valueOf("%') ")); 
    if (EnrgiseUtil.checkString(oLovQueryVO.getSearchField2()))
      sQuery = String.valueOf(String.valueOf(String.valueOf(sQuery).concat(String.valueOf(" and upper(hep.first_name || ' ' || hep.middle_name || ' ' || hep.last_name) LIKE upper('%"))).concat(String.valueOf(oLovQueryVO.getSearchField2()))).concat(String.valueOf("%') ")); 
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList oResultList = oBean.executeQuery(sQuery);
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    ArrayList oList = new ArrayList();
    oHeaderList.add("id");
    oHeaderList.add("hrm.HrmSepApplication.employeeName");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    QueryRow oRow = null;
    Iterator oIt = oResultList.iterator();
    while (oIt.hasNext()) {
      oRow = oIt.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("id").getString());
      oLOVBean.setDetailField2(oRow.get("empName").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public RecordMetaInfo getHrmSepOrderHdrMetaInfo(HrmSepOrderQVO oHrmSepOrderQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, oHrmSepOrderQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmSepOrderQVO.getOrderNo()));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmSepOrderQVO.getApplnId()));
    arylstParameters.add(new DBObject(4, 2, -5));
    arylstParameters.add(new DBObject(5, 2, 93));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 12));
    arylstParameters.add(new DBObject(8, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPORDER.procHrSepHdrCount(?,?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmSepOrderHdr(HrmSepOrderQVO oHrmSepOrderQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    ArrayList arylstHeaderList = null;
    if (oHrmSepOrderQVO == null)
      oHrmSepOrderQVO = new HrmSepOrderQVO(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmSepOrderQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmSepOrderQVO.getOrderNo()));
    arylstParameters.add(new DBObject(5, 1, 12, oHrmSepOrderQVO.getApplnId()));
    arylstParameters.add(new DBObject(6, 2, -10));
    arylstParameters.add(new DBObject(7, 2, 12));
    arylstParameters.add(new DBObject(8, 2, 12));
    arylstParameters.add(new DBObject(9, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPORDER.procHrSepHdrInfo(?,?,?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHeaderList = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmSepOrderHdrBean oHrmSepOrder = new HrmSepOrderHdrBean();
      oHrmSepOrder.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmSepOrder.setOrderNo(oRow.get("ORDER_NO").getString());
      oHrmSepOrder.setOrderDate(EnrgiseUtil.convertToString(oRow.get("ORDER_DATE").getDate()));
      oHrmSepOrder.setRemarks(oRow.get("appr_remark").getString());
      oHrmSepOrder.setActSepDate(EnrgiseUtil.convertToString(oRow.get("ACTUAL_SEP_DATE").getDate()));
      oHrmSepOrder.setApplicationNo(oRow.get("APPLICATION_NO").getString());
      oHrmSepOrder.setDateApplied(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oHrmSepOrder.setInitiatedBy(oRow.get("INITIATED_BY").getString());
      oHrmSepOrder.setApplnId(oRow.get("appln_id").getString());
      oHrmSepOrder.setReason(oRow.get("REASON").getString());
      oHrmSepOrder.setReqSepDate(EnrgiseUtil.convertToString(oRow.get("REQUESTED_SEP_DATE").getDate()));
      oHrmSepOrder.setEmpId(oRow.get("emp_id").getString());
      oHrmSepOrder.setEmployeeNo(oRow.get("emp_no").getString());
      oHrmSepOrder.setEmployeeName(oRow.get("emp_name").getString());
      oHrmSepOrder.setSepCatId(oRow.get("sep_cat_id").getString());
      oHrmSepOrder.setSepCat(oRow.get("sep_cat").getString());
      oHrmSepOrder.setApprovedBy(oRow.get("appr_name").getString());
      arylstHeaderList.add(oHrmSepOrder);
    } 
    return arylstHeaderList;
  }
  
  public RecordMetaInfo getHrmSepOrderDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(2, 2, -5));
    arylstParameters.add(new DBObject(3, 2, 93));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPORDER.procHrSepOrderDtlCount(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmSepOrderDtl(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int iCount = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmSepOrderDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, lPrimaryKey));
    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));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPORDER.procHrSepOrderDtlInfo(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator oIt = arylstList.iterator();
    while (oIt.hasNext()) {
      if (iCount == 0)
        arylstHrmSepOrderDetail = new ArrayList(); 
      iCount++;
      oRow = oIt.next();
      HrmSepOrderDtlBean oSepOrderDetailBean = new HrmSepOrderDtlBean();
      oSepOrderDetailBean.setDetailId(oRow.get("ID").getString());
      oSepOrderDetailBean.setTxtActualSepDate(EnrgiseUtil.convertToString(oRow.get("ACTUAL_SEP_DATE").getDate()));
      oSepOrderDetailBean.setTxtApplnDate(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oSepOrderDetailBean.setTxtApplnId(oRow.get("SEP_HDR_ID").getString());
      oSepOrderDetailBean.setTxtApplnNo(oRow.get("APPLICATION_NO").getString());
      oSepOrderDetailBean.setTxtApprovedFlag(oRow.get("APPROVED_FLAG").getString());
      oSepOrderDetailBean.setTxtEmpId(oRow.get("E_PER_DTL_ID").getString());
      oSepOrderDetailBean.setTxtEmployeeName(oRow.get("EMPNAME").getString());
      oSepOrderDetailBean.setTxtReason(oRow.get("REASON").getString());
      oSepOrderDetailBean.setTxtRejectionRemarks(oRow.get("REJECTION_REMARK").getString());
      oSepOrderDetailBean.setTxtRequestedSepDate(EnrgiseUtil.convertToString(oRow.get("REQUESTED_SEP_DATE").getDate()));
      oSepOrderDetailBean.setTxtSeparationCategory(oRow.get("DESCRIPTION").getString());
      oSepOrderDetailBean.setTxtSepDtlId(oRow.get("SEP_DTL_ID").getString());
      oSepOrderDetailBean.setHdnTempFlag(oRow.get("APPROVED_FLAG").getString());
      arylstHrmSepOrderDetail.add(oSepOrderDetailBean);
    } 
    return arylstHrmSepOrderDetail;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_SEP_ORDER_HDR";
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return new String();
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmSepOrderHdrBean oHrmSepOrderHdrBean = (HrmSepOrderHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      oParameters = new ArrayList();
      oParameters.add(new DBObject(1, 1, 12, "i"));
      oParameters.add(new DBObject(2, 1, 12, oHrmSepOrderHdrBean.getOrderNo()));
      oParameters.add(new DBObject(3, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmSepOrderHdrBean.getOrderDate())));
      oParameters.add(new DBObject(4, 1, 12, oHrmSepOrderHdrBean.getApplnId()));
      oParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmSepOrderHdrBean.getActSepDate())));
      oParameters.add(new DBObject(6, 1, 12, oHrmSepOrderHdrBean.getApproverId()));
      oParameters.add(new DBObject(7, 1, 12, oHrmSepOrderHdrBean.getRemarks()));
      oParameters.add(new DBObject(8, 1, 12, this.oUserInfo.getUserTypeId()));
      oParameters.add(new DBObject(9, 1, 12, this.oUserInfo.getSiteId()));
      oParameters.add(new DBObject(10, 1, 12, null));
      oParameters.add(new DBObject(11, 2, 12));
      oParameters.add(new DBObject(12, 2, 12));
      oParameters.add(new DBObject(13, 2, 12));
      oParameters.add(new DBObject(14, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMSEPORDER.procUpsertHrSepOrderHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      updateEmpHistory(oHrmSepOrderHdrBean.getEmpId(), oHrmSepOrderHdrBean.getActSepDate());
      updateEmpWorkgroupDetail(oHrmSepOrderHdrBean.getEmpId(), oHrmSepOrderHdrBean.getActSepDate());
      updateEmpPersonalDetail(oHrmSepOrderHdrBean.getEmpId(), oHrmSepOrderHdrBean.getActSepDate(), oHrmSepOrderHdrBean.getSepCatId());
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      oParameters = new ArrayList();
      oParameters.add(new DBObject(1, 1, 12, "u"));
      oParameters.add(new DBObject(2, 1, 12, oHrmSepOrderHdrBean.getOrderNo()));
      oParameters.add(new DBObject(3, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmSepOrderHdrBean.getOrderDate())));
      oParameters.add(new DBObject(4, 1, 12, oHrmSepOrderHdrBean.getApplnId()));
      oParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmSepOrderHdrBean.getActSepDate())));
      oParameters.add(new DBObject(6, 1, 12, oHrmSepOrderHdrBean.getApproverId()));
      oParameters.add(new DBObject(7, 1, 12, oHrmSepOrderHdrBean.getRemarks()));
      oParameters.add(new DBObject(8, 1, 12, this.oUserInfo.getUserTypeId()));
      oParameters.add(new DBObject(9, 1, 12, this.oUserInfo.getSiteId()));
      oParameters.add(new DBObject(10, 1, 12, null));
      oParameters.add(new DBObject(11, 2, 12));
      oParameters.add(new DBObject(12, 2, 12));
      oParameters.add(new DBObject(13, 2, 12));
      oParameters.add(new DBObject(14, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMSEPORDER.procUpsertHrSepOrderHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      updateEmpHistory(oHrmSepOrderHdrBean.getEmpId(), oHrmSepOrderHdrBean.getActSepDate());
      updateEmpWorkgroupDetail(oHrmSepOrderHdrBean.getEmpId(), oHrmSepOrderHdrBean.getActSepDate());
      updateEmpPersonalDetail(oHrmSepOrderHdrBean.getEmpId(), oHrmSepOrderHdrBean.getActSepDate(), oHrmSepOrderHdrBean.getSepCatId());
    } else if (ScreenMode.equalsIgnoreCase("D")) {
      oParameters.add(new DBObject(1, 1, 12, oHrmSepOrderHdrBean.getHeaderPrimaryKey()));
      oParameters.add(new DBObject(2, 2, 12));
      oParameters.add(new DBObject(3, 2, 12));
      oParameters.add(new DBObject(4, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMSEPORDER.procDeleteHrSepOrderHdr(?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = null;
    } 
    return returnString;
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmSepOrder"))
      saveHrmSepOrder(sHeaderPrimaryKey, arylstDetailBeanArray); 
  }
  
  private void saveHrmSepOrder(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmSepOrderDtlBean oHrmSepOrderDtlBean = itrBean.next();
      if (oHrmSepOrderDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMSEPORDER.procUpsertHrSepOrderDtl(?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "I"));
        arylstParameters.add(new DBObject(2, 1, 12, null));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmSepOrderDtlBean.getTxtApplnId()));
        arylstParameters.add(new DBObject(5, 1, 12, oHrmSepOrderDtlBean.getTxtSepDtlId()));
        arylstParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmSepOrderDtlBean.getTxtActualSepDate())));
        arylstParameters.add(new DBObject(7, 1, 12, oHrmSepOrderDtlBean.getTxtReason()));
        arylstParameters.add(new DBObject(8, 1, 12, "N"));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmSepOrderDtlBean.getTxtRejectionRemarks()));
        arylstParameters.add(new DBObject(10, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParameters.add(new DBObject(11, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmSepOrderDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMSEPORDER.procUpsertHrSepOrderDtl(?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "U"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmSepOrderDtlBean.getDetailId()));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmSepOrderDtlBean.getTxtApplnId()));
        arylstParameters.add(new DBObject(5, 1, 12, oHrmSepOrderDtlBean.getTxtSepDtlId()));
        arylstParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmSepOrderDtlBean.getTxtActualSepDate())));
        arylstParameters.add(new DBObject(7, 1, 12, oHrmSepOrderDtlBean.getTxtReason()));
        arylstParameters.add(new DBObject(8, 1, 12, "N"));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmSepOrderDtlBean.getTxtRejectionRemarks()));
        arylstParameters.add(new DBObject(10, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParameters.add(new DBObject(11, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmSepOrderDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMSEPORDER.procDeleteHrSepOrderDtl(?)");
          bDelete = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, oHrmSepOrderDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParameters);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  private void checkApplication() throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    ArrayList oParameters = new ArrayList();
    ArrayList oOutArray = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 2, -5));
    oParameters.add(new DBObject(2, 2, 93));
    oParameters.add(new DBObject(3, 2, 12));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 4));
    oOutArray = oBean.callProc(oParameters, "HRMSEPORDER.procHrSepOrderApplnCount(?,?,?,?,?)");
    DBObject oTotalRecord = oOutArray.get(0);
    long count1 = ((Long)oTotalRecord.getObject()).longValue();
    if (count1 == 0L) {
      arylstParam = new ArrayList();
      arylstParam.add("");
      arylstParam.add(new Integer(0));
      arylstList.add(new EnrgiseMessageKeyException("hrm.HrmSepOrder.noApplication", arylstParam));
    } 
    reportError(arylstList);
  }
  
  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((HrmSepOrderHdrBean)oBaseHeaderBean);  
    reportError(oErrorList);
  }
  
  private void checkMandatoryHeader(HrmSepOrderHdrBean oHrmSepOrderHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmSepOrderHdrBean.getOrderNo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmSepOrder.orderNo");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmSepOrderHdrBean.getOrderDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmSepOrder.orderDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmSepOrderHdrBean.getApplicationNo())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmSepApplication.applicationNo");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmSepOrderHdrBean.getApprovedBy())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmSepApplication.approvedBy");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    HrmSepOrderHdrBean oHrmSepOrderHdrBean = (HrmSepOrderHdrBean)oBaseHeaderBean;
    ArrayList oList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D")) {
        checkUniqueHeader((HrmSepOrderHdrBean)oBaseHeaderBean);
        checkDates((HrmSepOrderHdrBean)oBaseHeaderBean);
      }  
    reportError(oList);
  }
  
  private void checkDates(HrmSepOrderHdrBean oHrmSepOrderHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrorList = new ArrayList();
    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    if (EnrgiseUtil.checkString(oHrmSepOrderHdrBean.getOrderDate())) {
      int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmSepOrderHdrBean.getOrderDate(), oHrmSepOrderHdrBean.getDateApplied());
      if (dateFlag == -1 && dateFlag != -2)
        oErrorList.add(new EnrgiseApplicationException("wenrgise.empSepOrderDate.dateConstraintViolated")); 
    } 
    if (EnrgiseUtil.checkString(oHrmSepOrderHdrBean.getActSepDate())) {
      int dateFlag1 = EnrgiseUtil.compareDates(dateFormat, oHrmSepOrderHdrBean.getActSepDate(), oHrmSepOrderHdrBean.getDateApplied());
      if (dateFlag1 == -1 && dateFlag1 != -2)
        oErrorList.add(new EnrgiseApplicationException("wenrgise.empSepActDate.dateConstraintViolated")); 
    } 
    reportError(oErrorList);
  }
  
  private void checkUniqueHeader(HrmSepOrderHdrBean oHrmSepOrderHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sQuery = String.valueOf(String.valueOf(" Select ID as ID from HRM_SEP_ORDER_HDR where ORDER_NO='").concat(String.valueOf(oHrmSepOrderHdrBean.getOrderNo()))).concat(String.valueOf("'"));
    System.out.println(sQuery);
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstList = oBean.executeQuery(sQuery);
    Iterator itrBean = arylstList.iterator();
    ArrayList oList = new ArrayList();
    if (itrBean.hasNext()) {
      QueryRow oRow = itrBean.next();
      if (!oRow.get("ID").getString().equalsIgnoreCase(oHrmSepOrderHdrBean.getHeaderPrimaryKey()))
        oList.add(new EnrgiseApplicationException("wenrgise.common.uniqueConstraintViolated")); 
    } 
    reportError(oList);
  }
  
  public void updateEmpHistory(String sEmpId, String sActSepDate) throws EnrgiseSystemException {
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Iterator oIt = null;
    ArrayList arylstEmpPresDtls = getEmpPresentDetail(sEmpId);
    oIt = arylstEmpPresDtls.iterator();
    while (oIt.hasNext()) {
      HrmAprslEmpDtlsBean oHrmAprslEmpDtlsBean = oIt.next();
      ArrayList arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, sEmpId));
      arylstParam.add(new DBObject(2, 1, 12, oHrmAprslEmpDtlsBean.getPresLoc()));
      arylstParam.add(new DBObject(3, 1, 12, oHrmAprslEmpDtlsBean.getDesignation()));
      arylstParam.add(new DBObject(4, 1, 12, oHrmAprslEmpDtlsBean.getGrade()));
      arylstParam.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(sActSepDate)));
      arylstParam.add(new DBObject(6, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(8, 2, 12));
      arylstParam.add(new DBObject(9, 2, 12));
      arylstParam.add(new DBObject(10, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParam, "HRMSEPORDER.procUpsertHrmEmpIncr(?,?,?,?,?,?,?,?,?,?)");
    } 
  }
  
  public ArrayList getEmpPresentDetail(String sEmpId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList arylstList = null;
    Iterator oIt = null;
    ArrayList arylstEmpPresentDetail = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sEmpId));
    arylstParam.add(new DBObject(2, 2, -10));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMSEPORDER.procEmpPresDtls(?,?,?,?,?)");
    arylstList = (ArrayList)((DBObject)arylstOutArray.get(0)).getObject();
    if (arylstList.size() == 0);
    count = 0;
    oIt = arylstList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        arylstEmpPresentDetail = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmAprslEmpDtlsBean oHrmAprslEmpDtlsBean = new HrmAprslEmpDtlsBean();
      oHrmAprslEmpDtlsBean.setGrade(oRow.get("present_grade_id").getString());
      oHrmAprslEmpDtlsBean.setDesignation(oRow.get("present_designation_id").getString());
      oHrmAprslEmpDtlsBean.setPresLoc(oRow.get("present_site_id").getString());
      arylstEmpPresentDetail.add(oHrmAprslEmpDtlsBean);
    } 
    return arylstEmpPresentDetail;
  }
  
  public void updateEmpWorkgroupDetail(String sEmpId, String sActSepDate) throws EnrgiseSystemException {
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sEmpId));
    arylstParam.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(sActSepDate)));
    arylstParam.add(new DBObject(3, 2, 12));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMSEPORDER.procUpdateHrmEmpWrkgrpDtl(?,?,?,?,?)");
  }
  
  public void updateEmpPersonalDetail(String sEmpId, String sActSepDate, String sSepCatId) throws EnrgiseSystemException {
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sEmpId));
    arylstParam.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(sActSepDate)));
    arylstParam.add(new DBObject(3, 1, 12, sSepCatId));
    arylstParam.add(new DBObject(4, 2, 12));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMSEPORDER.procUpdateHrmEmpPers(?,?,?,?,?,?)");
  }
  
  public String approveSepOrder(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    ArrayList arylstList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    HrmSepOrderHdrBean oHrmSepOrderHdrBean = (HrmSepOrderHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    oBean = new DBUtilitiesBean();
    oBean.createBatch("HRMSEPORDER.procApproveSepOrder(?)");
    Iterator itrDtlBean = arylstDetailBeanArray.iterator();
    int rowCount = 0;
    int n = arylstDetailBeanArray.size();
    while (itrDtlBean.hasNext()) {
      HrmSepOrderDtlBean oDtlBean = itrDtlBean.next();
      System.out.println(oDtlBean.getDetailId());
      System.out.println(oDtlBean.getTxtApprovedFlag());
      checkApproveReject(oDtlBean);
      if (oDtlBean.getStatus().equalsIgnoreCase("A"))
        arylstParameters.add(new DBObject(1, 1, 12, oDtlBean.getDetailId())); 
      if (!arylstParameters.isEmpty())
        oBean.addToBatch(arylstParameters); 
      if (rowCount < n)
        rowCount++; 
    } 
    oBean.executeBatch();
    reportError(arylstList);
    return sHeaderPrimaryKey;
  }
  
  public String rejectSepOrder(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    ArrayList arylstList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    HrmSepOrderHdrBean oHrmSepOrderHdrBean = (HrmSepOrderHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    oBean = new DBUtilitiesBean();
    oBean.createBatch("HRMSEPORDER.procRejectSepOrder(?)");
    Iterator itrDtlBean = arylstDetailBeanArray.iterator();
    int rowCount = 1;
    int n = arylstDetailBeanArray.size();
    while (itrDtlBean.hasNext()) {
      HrmSepOrderDtlBean oDtlBean = itrDtlBean.next();
      System.out.println(oDtlBean.getDetailId());
      checkApproveReject(oDtlBean);
      if (oDtlBean.getStatus().equalsIgnoreCase("R"))
        arylstParameters.add(new DBObject(1, 1, 12, oDtlBean.getDetailId())); 
      if (!arylstParameters.isEmpty())
        oBean.addToBatch(arylstParameters); 
      if (rowCount < n)
        rowCount++; 
    } 
    oBean.executeBatch();
    reportError(arylstList);
    return sHeaderPrimaryKey;
  }
  
  private void checkApproveReject(HrmSepOrderDtlBean oDtlBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    System.out.println(oDtlBean.getHdnTempFlag());
    if (oDtlBean.getHdnTempFlag().equalsIgnoreCase("A") || oDtlBean.getHdnTempFlag().equalsIgnoreCase("R")) {
      arylstParam = new ArrayList();
      arylstParam.add("");
      arylstParam.add(new Integer(0));
      arylstList.add(new EnrgiseMessageKeyException("hrm.common.approve", arylstParam));
    } 
    reportError(arylstList);
  }
}
