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.ejb.business.HrmCommonBO;
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.HrmLvCancHdrBean;
import wenrgise.hrms.bean.HrmLvCancQueryDtlBean;
import wenrgise.hrms.vo.HrmLvCancQVO;
import wenrgise.hrms.vo.HrmLvCancQueryQVO;
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 HrmLvCancQueryBO extends HrmBaseBO {
  public HrmLvCancQueryBO() {}
  
  public HrmLvCancQueryBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getLeaveCanQueryDetailMetaInfo(HrmLvCancQueryQVO oHrmLvCancQueryQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String lvType = oHrmLvCancQueryQVO.getLeaveType();
    String empNo = oHrmLvCancQueryQVO.getEmployeeNumber();
    String status = oHrmLvCancQueryQVO.getCancellationStatus();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, empNo));
    arylstParam.add(new DBObject(2, 1, 12, lvType));
    arylstParam.add(new DBObject(3, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancQueryQVO.getCancelFromDate())));
    arylstParam.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancQueryQVO.getCancelToDate())));
    arylstParam.add(new DBObject(5, 1, 12, status));
    arylstParam.add(new DBObject(6, 2, -5));
    arylstParam.add(new DBObject(7, 2, 93));
    arylstParam.add(new DBObject(8, 2, 12));
    arylstParam.add(new DBObject(9, 2, 12));
    arylstParam.add(new DBObject(10, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_HrLeaveCanQueryDtlCount(?,?,?,?,?,?,?,?,?,?)");
    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 getHrLeaveCanQueryDetail(HrmLvCancQueryQVO oHrmLvCancQueryQVO, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String lvType = oHrmLvCancQueryQVO.getLeaveType();
    String empNo = oHrmLvCancQueryQVO.getEmployeeNumber();
    String status = oHrmLvCancQueryQVO.getCancellationStatus();
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList arylstList = null;
    Iterator itrBean = null;
    ArrayList arylstLeaveCanQueryDetail = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    arylstParam.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    arylstParam.add(new DBObject(3, 1, 12, empNo));
    arylstParam.add(new DBObject(4, 1, 12, lvType));
    arylstParam.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancQueryQVO.getCancelFromDate())));
    arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancQueryQVO.getCancelToDate())));
    arylstParam.add(new DBObject(7, 1, 12, status));
    arylstParam.add(new DBObject(8, 2, -10));
    arylstParam.add(new DBObject(9, 2, 12));
    arylstParam.add(new DBObject(10, 2, 12));
    arylstParam.add(new DBObject(11, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_HrLeaveCanQueryDtl(?,?,?,?,?,?,?,?,?,?,?)");
    arylstList = (ArrayList)((DBObject)arylstOutArray.get(0)).getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    count = 0;
    itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstLeaveCanQueryDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmLvCancQueryDtlBean oHrmLvCancQueryDtlBean = new HrmLvCancQueryDtlBean();
      oHrmLvCancQueryDtlBean.setTxtTransId(oRow.get("ID").getString());
      oHrmLvCancQueryDtlBean.setTxtLeaveCodes(oRow.get("LEAVE_DESCRIPTION").getString());
      oHrmLvCancQueryDtlBean.setTxtAppliedLeaveDate(EnrgiseUtil.convertToString(oRow.get("APPLEAVEDATE").getDate()));
      oHrmLvCancQueryDtlBean.setTxtCancellationDate(EnrgiseUtil.convertToString(oRow.get("DATE_APPLIED").getDate()));
      oHrmLvCancQueryDtlBean.setTxtCancellationType(oRow.get("FULL_CNCL_FLAG").getString());
      oHrmLvCancQueryDtlBean.setTxtCancelStatus(oRow.get("APPROVAL_FLAG").getString());
      arylstLeaveCanQueryDetail.add(oHrmLvCancQueryDtlBean);
    } 
    return arylstLeaveCanQueryDetail;
  }
  
  public RecordMetaInfo getEmpLeaveCancellationQueryScreenDetailMetaInfo(HrmLvCancQVO oHrmLvCancQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sTransId = oHrmLvCancQVO.getTransId();
    System.out.println(sTransId);
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sTransId));
    arylstParam.add(new DBObject(2, 1, 12, oHrmLvCancQVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(3, 1, 12, oHrmLvCancQVO.getEmployeeNo()));
    arylstParam.add(new DBObject(4, 1, 12, oHrmLvCancQVO.getLeaveCodeId()));
    arylstParam.add(new DBObject(5, 2, -5));
    arylstParam.add(new DBObject(6, 2, 93));
    arylstParam.add(new DBObject(7, 2, 12));
    arylstParam.add(new DBObject(8, 2, 12));
    arylstParam.add(new DBObject(9, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_HrLeaveCanQryScreenDtlCnt(?,?,?,?,?,?,?,?,?)");
    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 getHrEmpLeaveCancellationQueryScreenDetail(HrmLvCancQVO oHrmLvCancQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sTransId = oHrmLvCancQVO.getTransId();
    System.out.println(sTransId);
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList arylstList = null;
    Iterator itrBean = null;
    ArrayList arylstEmpLeaveCanQueryScreenDetail = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    arylstParam.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    arylstParam.add(new DBObject(3, 1, 12, sTransId));
    arylstParam.add(new DBObject(4, 1, 12, oHrmLvCancQVO.getEmployeeNo()));
    arylstParam.add(new DBObject(5, 1, 12, oHrmLvCancQVO.getHeaderPrimaryKey()));
    arylstParam.add(new DBObject(6, 1, 12, oHrmLvCancQVO.getLeaveCodeId()));
    arylstParam.add(new DBObject(7, 2, -10));
    arylstParam.add(new DBObject(8, 2, 12));
    arylstParam.add(new DBObject(9, 2, 12));
    arylstParam.add(new DBObject(10, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_HrLeaveCanQueryScreenDtl(?,?,?,?,?,?,?,?,?,?)");
    arylstList = (ArrayList)((DBObject)arylstOutArray.get(0)).getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    count = 0;
    itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstEmpLeaveCanQueryScreenDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmLvCancHdrBean oHrmLvCancHdrBean = new HrmLvCancHdrBean();
      oHrmLvCancHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmLvCancHdrBean.setEmployeeNo(oRow.get("EMP_NO").getString());
      oHrmLvCancHdrBean.setFirstName(oRow.get("FIRST_NAME").getString());
      oHrmLvCancHdrBean.setMiddleName(oRow.get("MIDDLE_NAME").getString());
      oHrmLvCancHdrBean.setLastName(oRow.get("LAST_NAME").getString());
      oHrmLvCancHdrBean.setLeaveCode(oRow.get("LEAVE_DESCRIPTION").getString());
      oHrmLvCancHdrBean.setLeaveDescription(oRow.get("NAME").getString());
      oHrmLvCancHdrBean.setLeaveCodeId(oRow.get("LEAVE_CODE_ID").getString());
      oHrmLvCancHdrBean.setDateApplied(EnrgiseUtil.convertToString(oRow.get("DATE_APPLIED").getDate()));
      oHrmLvCancHdrBean.setFromDate(EnrgiseUtil.convertToString(oRow.get("FROM_DATE").getDate()));
      oHrmLvCancHdrBean.setToDate(EnrgiseUtil.convertToString(oRow.get("TO_DATE").getDate()));
      oHrmLvCancHdrBean.setDays(oRow.get("NO_OF_DAYS").getString());
      oHrmLvCancHdrBean.setAddress(oRow.get("ADDRESS_FOR_COMM").getString());
      oHrmLvCancHdrBean.setPhoneNo(oRow.get("PHONE").getString());
      oHrmLvCancHdrBean.setCancelStatus(oRow.get("APPROVAL_FLAG").getString());
      oHrmLvCancHdrBean.setStatusOfLeave(oRow.get("LV_CNCL_FLAG").getString());
      System.out.println(oRow.get("LV_CNCL_FLAG").getString());
      oHrmLvCancHdrBean.setPurpose(oRow.get("PURPOSE").getString());
      oHrmLvCancHdrBean.setFromCancelDate(EnrgiseUtil.convertToString(oRow.get("CANFROMDATE").getDate()));
      oHrmLvCancHdrBean.setToCancelDate(EnrgiseUtil.convertToString(oRow.get("CANTODATE").getDate()));
      oHrmLvCancHdrBean.setCancelDays(oRow.get("CANNOOFDAYS").getString());
      oHrmLvCancHdrBean.setCancelDateApplied(EnrgiseUtil.convertToString(oRow.get("CANDATEAPP").getDate()));
      oHrmLvCancHdrBean.setCancellationType(oRow.get("FULL_CNCL_FLAG").getString());
      oHrmLvCancHdrBean.setCancelRemarks(oRow.get("REMARKS").getString());
      arylstEmpLeaveCanQueryScreenDetail.add(oHrmLvCancHdrBean);
    } 
    return arylstEmpLeaveCanQueryScreenDetail;
  }
  
  public LovVO getHrmCnclLeaveEmpLOV(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("empId");
    arylstHeaderList.add("hrm.HrmLeaveCancellationQuery.employeeNumber");
    arylstHeaderList.add("hrm.HrmLeaveCancellationQuery.empName");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null) {
      sQuerySearch1 = oLovQueryVO.getSearchField1();
      System.out.println(sQuerySearch1);
    } 
    if (oLovQueryVO.getSearchField2() != null) {
      sQuerySearch2 = oLovQueryVO.getSearchField2();
      System.out.println(sQuerySearch2);
    } 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParam.add(new DBObject(3, 2, -10));
    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, "HRMLVLOV.proc_GetHrmCnclLeaveEmpLOVdata(?,?,?,?,?,?)");
    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("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("EMPNAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmCnclLeaveTypeLOV(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("leaveTypeId");
    arylstHeaderList.add("hrm.HrmLeaveCancellationQuery.leaveType");
    arylstHeaderList.add("hrm.HrmLeaveCancellationQuery.leaveDescription");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null) {
      sQuerySearch1 = oLovQueryVO.getSearchField1();
      System.out.println(sQuerySearch1);
    } 
    if (oLovQueryVO.getSearchField2() != null) {
      sQuerySearch2 = oLovQueryVO.getSearchField2();
      System.out.println(sQuerySearch2);
    } 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParam.add(new DBObject(3, 2, -10));
    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, "HRMLVLOV.proc_GetHrmCnclLeaveTypeLOV(?,?,?,?,?,?)");
    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("LEAVE_DESCRIPTION").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "hrm_emp_leave_txn";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {}
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "saveNewHeaderImpl";
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public LovVO getHrmEmpLvCanLvCdLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.leaveCode");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.leaveDescription");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.dateApplied");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.fromDate");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.toDate");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.days");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.purpose");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.statusOfLeave");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("H");
    arylstVisibility.add("H");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    String sEmpNo = null;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getProperty("employeeNo") != null)
      sEmpNo = oLovQueryVO.getProperty("employeeNo"); 
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParam.add(new DBObject(3, 1, 12, sEmpNo));
    arylstParam.add(new DBObject(4, 2, -10));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_GetEmpLvCanLeaveCdLOV(?,?,?,?,?,?,?)");
    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("leave_description").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      oLOVBean.setDetailField4(EnrgiseUtil.convertToString(oRow.get("date_applied").getDate()));
      oLOVBean.setDetailField5(EnrgiseUtil.convertToString(oRow.get("from_date").getDate()));
      oLOVBean.setDetailField6(EnrgiseUtil.convertToString(oRow.get("to_date").getDate()));
      oLOVBean.setDetailField7(oRow.get("no_of_days").getString());
      oLOVBean.setDetailField8(oRow.get("purpose").getString());
      String sFullCancel = oRow.get("FULL_CNCL_FLAG").getString();
      String sPartCancel = oRow.get("lv_cncl_flag").getString();
      if (sPartCancel.equals("N") && sFullCancel.equals("N"))
        oLOVBean.setDetailField9("NC"); 
      if (sPartCancel.equals("Y") && sFullCancel.equals("N"))
        oLOVBean.setDetailField9("N"); 
      if (sFullCancel.equals("Y"))
        oLOVBean.setDetailField9("Y"); 
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmEmpLvCanLvCdInsertLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.leaveCode");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.leaveDescription");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.dateApplied");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.fromDate");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.toDate");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.days");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.purpose");
    arylstHeaderList.add("hrm.HrmLeaveCancellation.statusOfLeave");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("H");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    String sEmpNo = null;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getProperty("employeeNo") != null)
      sEmpNo = oLovQueryVO.getProperty("employeeNo"); 
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParam.add(new DBObject(2, 1, 12, sQuerySearch2));
    arylstParam.add(new DBObject(3, 1, 12, sEmpNo));
    arylstParam.add(new DBObject(4, 2, -10));
    arylstParam.add(new DBObject(5, 2, 12));
    arylstParam.add(new DBObject(6, 2, 12));
    arylstParam.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_GetLvCodeLOV(?,?,?,?,?,?,?)");
    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("leave_description").getString());
      oLOVBean.setDetailField3(oRow.get("NAME").getString());
      oLOVBean.setDetailField4(EnrgiseUtil.convertToString(oRow.get("date_applied").getDate()));
      oLOVBean.setDetailField5(EnrgiseUtil.convertToString(oRow.get("from_date").getDate()));
      oLOVBean.setDetailField6(EnrgiseUtil.convertToString(oRow.get("to_date").getDate()));
      oLOVBean.setDetailField7(oRow.get("no_of_days").getString());
      oLOVBean.setDetailField8(oRow.get("purpose").getString());
      String sFullCancel = oRow.get("FULL_CNCL_FLAG").getString();
      String sPartCancel = oRow.get("lv_cncl_flag").getString();
      if (sPartCancel.equals("N") && sFullCancel.equals("N"))
        oLOVBean.setDetailField9("NC"); 
      if (sPartCancel.equals("Y") && sFullCancel.equals("N"))
        oLOVBean.setDetailField9("N"); 
      if (sFullCancel.equals("Y"))
        oLOVBean.setDetailField9("Y"); 
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public String getChngStatusInfo(String sTxnId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sStatus = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sTxnId));
    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, "HRMLVLOV.proc_GetLvTxnIdInChng(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      oRow = itrBean.next();
      sStatus = oRow.get("APPROVAL_FLAG").getString();
    } 
    return sStatus;
  }
  
  public String getCnclStatusInfo(String sTxnId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sStatus = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sTxnId));
    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, "HRMLVLOV.proc_GetLvTxnIdInCncl(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      oRow = itrBean.next();
      sStatus = oRow.get("APPROVAL_FLAG").getString();
    } 
    return sStatus;
  }
  
  private ArrayList checkLOVConstraint(ArrayList arylstList) throws EnrgiseSystemException {
    LOVBean def = null;
    ArrayList arylstNewList = new ArrayList();
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      def = itrBean.next();
      String sTxnId = def.getDetailField1();
      String sChngFlag = getChngStatusInfo(sTxnId);
      if (sChngFlag != null) {
        if (sChngFlag.equalsIgnoreCase("R"))
          arylstNewList.add(def); 
        continue;
      } 
      String sCnclFlag = getCnclStatusInfo(sTxnId);
      if (sCnclFlag == null) {
        arylstNewList.add(def);
        continue;
      } 
      if (sCnclFlag.equalsIgnoreCase("R") || sCnclFlag.equalsIgnoreCase("A"))
        arylstNewList.add(def); 
    } 
    return arylstNewList;
  }
  
  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();
    HrmLvCancHdrBean oHrmLvCancHdrBean = (HrmLvCancHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged) {
      if (!sScreenMode.equalsIgnoreCase("D")) {
        if (sScreenMode.equalsIgnoreCase("N"))
          checkHeaderConstraint((HrmLvCancHdrBean)oBaseHeaderBean); 
        if (sScreenMode.equalsIgnoreCase("U"))
          if (oHrmLvCancHdrBean.getCancelStatus() == null) {
            checkHeaderConstraint((HrmLvCancHdrBean)oBaseHeaderBean);
          } else if (oHrmLvCancHdrBean.getCancelStatus().equalsIgnoreCase("N")) {
            checkHeaderConstraint((HrmLvCancHdrBean)oBaseHeaderBean);
          } else {
            arylstErrorList.add(new EnrgiseApplicationException("wenrgise.common.updation.mode"));
          }  
      } 
      if (sScreenMode.equalsIgnoreCase("D"))
        if (!oHrmLvCancHdrBean.getCancelStatus().equalsIgnoreCase("N")) {
          if (arylstErrorList.isEmpty())
            arylstErrorList.add(new EnrgiseApplicationException("wenrgise.common.deletion.rejected")); 
        } else if (oHrmLvCancHdrBean.getStatusOfLeave().equalsIgnoreCase("Y")) {
          updateTxnCnclStatus(oHrmLvCancHdrBean.getLeaveCodeId(), "N");
        }  
    } 
    reportError(arylstErrorList);
  }
  
  private void checkHeaderConstraint(HrmLvCancHdrBean oHrmLvCancHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    String sTxnId = oHrmLvCancHdrBean.getLeaveCodeId();
    HrmCommonBO oBO = new HrmCommonBO();
    String sCnclId = oBO.getRefList("hrm_emp_leave_cncl_txn", "lv_txn_id", sTxnId, "ID");
    if (!EnrgiseUtil.checkString(sCnclId)) {
      if (!oHrmLvCancHdrBean.getFromCancelDate().equals(oHrmLvCancHdrBean.getFromDate()) && !oHrmLvCancHdrBean.getToCancelDate().equals(oHrmLvCancHdrBean.getToDate()))
        arylstErrorList.add(new EnrgiseApplicationException("wenrgise.lvCncl.value")); 
    } else {
      ArrayList arylstFromTarylstList = getCancelFromDateTarylstDateDetail(sTxnId);
      HrmLvCancHdrBean oHdrBean = null;
      Iterator itrBean = arylstFromTarylstList.iterator();
      while (itrBean.hasNext()) {
        oHdrBean = itrBean.next();
        String sCnclfromDate = oHdrBean.getFromCancelDate();
        System.out.println(sCnclfromDate);
        String sCnclToDate = oHdrBean.getToCancelDate();
        System.out.println(sCnclToDate);
        HrmCommonBO b = new HrmCommonBO();
        if (EnrgiseUtil.compareDates(new SimpleDateFormat("dd-MMM-yyyy"), oHdrBean.getFromCancelDate(), sCnclfromDate) > 0)
          arylstErrorList.add(new EnrgiseApplicationException("wenrgise.lvCncl.value")); 
        if (EnrgiseUtil.compareDates(new SimpleDateFormat("dd-MMM-yyyy"), oHdrBean.getToCancelDate(), sCnclToDate) > 0)
          arylstErrorList.add(new EnrgiseApplicationException("wenrgise.lvCncl.value")); 
        if (!oHrmLvCancHdrBean.getFromCancelDate().equals(sCnclfromDate) && !oHrmLvCancHdrBean.getToCancelDate().equals(sCnclToDate))
          arylstErrorList.add(new EnrgiseApplicationException("wenrgise.lvCncl.value")); 
        if (oHrmLvCancHdrBean.getFromCancelDate().equals(sCnclfromDate) && oHrmLvCancHdrBean.getToCancelDate().equals(sCnclToDate))
          updateTxnCnclStatus(oHrmLvCancHdrBean.getLeaveCodeId(), "Y"); 
      } 
    } 
    reportError(arylstErrorList);
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmLvCancHdrBean)oBaseHeaderBean);  
    reportError(arylstErrorList);
  }
  
  private void checkMandatoryHeader(HrmLvCancHdrBean oHrmLvCancHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmLvCancHdrBean.getFromCancelDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveCancellation.fromCancelDate");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLvCancHdrBean.getToCancelDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveCancellation.toCancelDate");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLvCancHdrBean.getCancelDateApplied())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmLeaveCancellation.cancelDateApplied");
      ArrayList oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    String sCancelDays = null;
    HrmLvCancHdrBean oHrmLvCancHdrBean = (HrmLvCancHdrBean)oBaseHeaderBean;
    try {
      sCancelDays = getCancelDayCount(oHrmLvCancHdrBean.getLeaveCodeId(), oHrmLvCancHdrBean.getToCancelDate());
    } catch (EnrgiseApplicationException oEx) {
      throw new EnrgiseSystemException(oEx);
    } 
    if (ScreenMode.equalsIgnoreCase("N")) {
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "N"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmLvCancHdrBean.getLeaveCodeId()));
      arylstParam.add(new DBObject(3, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancHdrBean.getFromCancelDate())));
      arylstParam.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancHdrBean.getToCancelDate())));
      arylstParam.add(new DBObject(5, 1, 12, sCancelDays));
      arylstParam.add(new DBObject(6, 1, 12, oHrmLvCancHdrBean.getCancellationType()));
      arylstParam.add(new DBObject(7, 1, 12, "P"));
      arylstParam.add(new DBObject(8, 1, 12, oHrmLvCancHdrBean.getCancelRemarks()));
      arylstParam.add(new DBObject(9, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancHdrBean.getCancelDateApplied())));
      arylstParam.add(new DBObject(10, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParam.add(new DBObject(11, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(12, 1, 12, null));
      arylstParam.add(new DBObject(13, 2, 12));
      arylstParam.add(new DBObject(14, 2, 12));
      arylstParam.add(new DBObject(15, 2, 12));
      arylstParam.add(new DBObject(16, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_UpsertLeaveCncl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      oBaseHeaderBean.setHeaderPrimaryKey(returnString);
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      if (oHrmLvCancHdrBean.getCancelStatus() != null)
        if (oHrmLvCancHdrBean.getCancelStatus().equalsIgnoreCase("R"))
          if (oHrmLvCancHdrBean.getStatusOfLeave().equalsIgnoreCase("Y"))
            updateTxnCnclStatus(oHrmLvCancHdrBean.getLeaveCodeId(), "N");   
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "u"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmLvCancHdrBean.getLeaveCodeId()));
      arylstParam.add(new DBObject(3, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancHdrBean.getFromCancelDate())));
      arylstParam.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancHdrBean.getToCancelDate())));
      arylstParam.add(new DBObject(5, 1, 12, sCancelDays));
      arylstParam.add(new DBObject(6, 1, 12, oHrmLvCancHdrBean.getCancellationType()));
      arylstParam.add(new DBObject(7, 1, 12, oHrmLvCancHdrBean.getCancelStatus()));
      arylstParam.add(new DBObject(8, 1, 12, oHrmLvCancHdrBean.getCancelRemarks()));
      arylstParam.add(new DBObject(9, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLvCancHdrBean.getCancelDateApplied())));
      arylstParam.add(new DBObject(10, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParam.add(new DBObject(11, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(12, 1, 12, oHrmLvCancHdrBean.getHeaderPrimaryKey()));
      arylstParam.add(new DBObject(13, 2, 12));
      arylstParam.add(new DBObject(14, 2, 12));
      arylstParam.add(new DBObject(15, 2, 12));
      arylstParam.add(new DBObject(16, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_UpsertLeaveCncl(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("D")) {
      arylstParam.add(new DBObject(1, 1, 12, oHrmLvCancHdrBean.getHeaderPrimaryKey()));
      arylstParam.add(new DBObject(2, 2, 12));
      arylstParam.add(new DBObject(3, 2, 12));
      arylstParam.add(new DBObject(4, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLVCANCQUERY.proc_DeleteHrLvCnclDtl(?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = null;
    } 
    return returnString;
  }
  
  public String getNextCnclDtlToDate(String sDate, String sTxnId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sNextDate = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 93, EnrgiseUtil.convertToSqlDate(sDate)));
    arylstParam.add(new DBObject(2, 1, 12, sTxnId));
    arylstParam.add(new DBObject(3, 2, -10));
    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, "HRMLVCANCQUERY.proc_GetNextCnclDtlToDate(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      oRow = itrBean.next();
      sNextDate = EnrgiseUtil.convertToString(oRow.get("NEXTCNCLDTLTODATE").getDate());
      System.out.println(sNextDate);
    } 
    return sNextDate;
  }
  
  public String getPrevCnclDtlFromDate(String sDate, String sTxnId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sPrevDate = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 93, EnrgiseUtil.convertToSqlDate(sDate)));
    arylstParam.add(new DBObject(2, 1, 12, sTxnId));
    arylstParam.add(new DBObject(3, 2, -10));
    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, "HRMLVCANCQUERY.proc_GetPrevCnclDtlFromDate(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      oRow = itrBean.next();
      sPrevDate = EnrgiseUtil.convertToString(oRow.get("PREVCNCLDTLTODATE").getDate());
      System.out.println(sPrevDate);
    } 
    return sPrevDate;
  }
  
  public void updateTxnCnclStatus(String sTxnId, String sValue) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sTxnId));
    arylstParam.add(new DBObject(2, 1, 12, sValue));
    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, "HRMLVCANCQUERY.proc_updateTxnStatus(?,?,?,?,?)");
  }
  
  public ArrayList getCancelFromDateTarylstDateDetail(String sTxnId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList arylstList = null;
    Iterator itrBean = null;
    ArrayList arylstDateDetail = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sTxnId));
    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, "HRMLVLOV.proc_GetCnclFromToDateInCncl(?,?,?,?,?)");
    arylstList = (ArrayList)((DBObject)arylstOutArray.get(0)).getObject();
    count = 0;
    itrBean = arylstList.iterator();
    String cnclToDate = null;
    String cnclFromDate = null;
    String txnFromDate = null;
    String txnToDate = null;
    HrmLvCancHdrBean oHrmLvCancHdrBean = new HrmLvCancHdrBean();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstDateDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      if (count == 1) {
        txnFromDate = EnrgiseUtil.convertToString(oRow.get("FROM_DATE").getDate());
        txnToDate = EnrgiseUtil.convertToString(oRow.get("TO_DATE").getDate());
      } 
      String cnclDtlFromDate = EnrgiseUtil.convertToString(oRow.get("CANFROM").getDate());
      String cnclDtlToDate = EnrgiseUtil.convertToString(oRow.get("CANTO").getDate());
      System.out.println(cnclDtlToDate);
      if (txnFromDate.equals(cnclDtlFromDate)) {
        cnclFromDate = getNextCnclDtlToDate(cnclDtlToDate, sTxnId);
        System.out.println(cnclFromDate);
        cnclToDate = txnToDate;
        System.out.println(cnclToDate);
        txnFromDate = cnclFromDate;
        txnToDate = cnclToDate;
        continue;
      } 
      cnclFromDate = txnFromDate;
      System.out.println(cnclFromDate);
      cnclToDate = getPrevCnclDtlFromDate(cnclDtlFromDate, sTxnId);
      txnFromDate = cnclFromDate;
      txnToDate = cnclToDate;
    } 
    System.out.println(cnclFromDate);
    System.out.println(cnclToDate);
    oHrmLvCancHdrBean.setFromCancelDate(cnclFromDate);
    oHrmLvCancHdrBean.setToCancelDate(cnclToDate);
    arylstDateDetail.add(oHrmLvCancHdrBean);
    return arylstDateDetail;
  }
  
  public String approveLeaveCanc(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    String sLeaveCanc = null;
    String sStatus = null;
    HrmLvCancHdrBean oHdrBean = (HrmLvCancHdrBean)oBaseHeaderBean;
    if (oHdrBean.getButtonName().equalsIgnoreCase("A")) {
      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")) {
        sLeaveCanc = approveLeaveCancHdr(oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, arylstDetailBeanArray, bDetailDataChanged, oDetailPicked);
        approveLeaveCancTxn(oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, arylstDetailBeanArray, bDetailDataChanged, oDetailPicked);
      } 
    } else {
      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")) {
        sLeaveCanc = approveLeaveCancHdr(oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, arylstDetailBeanArray, bDetailDataChanged, oDetailPicked);
        approveLeaveCancTxn(oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, arylstDetailBeanArray, bDetailDataChanged, oDetailPicked);
      } 
    } 
    return sLeaveCanc;
  }
  
  private String approveLeaveCancHdr(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    HrmLvCancHdrBean oHrmLvCancHdrBean = (HrmLvCancHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    oBean = new DBUtilitiesBean();
    ArrayList arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmLvCancHdrBean.getEmployeeId()));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmLvCancHdrBean.getLeaveCodeId()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmLvCancHdrBean.getCancelDays()));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    if (oHrmLvCancHdrBean.getButtonName().equalsIgnoreCase("A"))
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMLVCANCQUERY.proc_UpsertApproveLvCancHdr(?,?,?,?,?,?,?)"); 
    return sHeaderPrimaryKey;
  }
  
  private void approveLeaveCancTxn(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    HrmLvCancHdrBean oHrmLvCancHdrBean = (HrmLvCancHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    oBean = new DBUtilitiesBean();
    ArrayList arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmLvCancHdrBean.getEmployeeId()));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmLvCancHdrBean.getLeaveCodeId()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmLvCancHdrBean.getButtonName()));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstPK = oBean.callProc(arylstParameters, "HRMLVCANCQUERY.proc_UpsertApproveLvCancTxn(?,?,?,?,?,?,?)");
  }
  
  private String getCancelDayCount(String sTxnId, String sToDate) throws EnrgiseApplicationException, EnrgiseSystemException {
    DBUtilitiesBean oBean = null;
    oBean = new DBUtilitiesBean();
    ArrayList arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sTxnId));
    arylstParameters.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(sToDate)));
    arylstParameters.add(new DBObject(3, 2, -10));
    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, "HRMLVCANCQUERY.proc_GetCancelLeaveCount(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    double dFlag = 0.0D;
    while (itrBean.hasNext()) {
      oRow = itrBean.next();
      int iFlag = Integer.parseInt(oRow.get("part_flag").getString());
      dFlag += (iFlag == 3) ? 1.0D : 0.5D;
    } 
    String sCount = String.valueOf(dFlag);
    return sCount;
  }
  
  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();
      HrmLvCancHdrBean oHdrBean = (HrmLvCancHdrBean)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(oHdrBean.getHeaderPrimaryKey());
      wflDocumentInfoImpl.setDocumentType("Leave");
      wflDocumentInfoImpl.setInitiatedFlag(initiatedFlag);
      String documentTypeId = workFlowFacade.getDocumentTypeId("LvCncl");
      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("Leave Cancellation No:  ").concat(String.valueOf(oHdrBean.getHeaderPrimaryKey()))).concat(String.valueOf("is pending for approval")));
        wflDocumentInfoImpl.setDocDesc(String.valueOf("The following document has been pending for approval:   Leave Cancellation No:").concat(String.valueOf(oHdrBean.getHeaderPrimaryKey())));
      } else if (!activity.equalsIgnoreCase("Approve")) {
        wflDocumentInfoImpl.setDocumentNumber(String.valueOf(String.valueOf("Leave Cancellation No:  ").concat(String.valueOf(oHdrBean.getHeaderPrimaryKey()))).concat(String.valueOf("is pending for rejection")));
        wflDocumentInfoImpl.setDocDesc(String.valueOf("The following document has been pending for rejection:   Leave Cancellation No:").concat(String.valueOf(oHdrBean.getHeaderPrimaryKey())));
      } 
      wflDocumentInfoImpl.setModuleId("8");
      wflDocumentInfoImpl.setCreator((WflResource)wflResourceImpl);
      wflDocumentInfoImpl.setRequesterAction(activityId);
      HashMap oProp = new HashMap();
      oProp.put("1", "1");
      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);
    } 
  }
}
