package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
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.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.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.HrmEmpAdvAppHdrBean;
import wenrgise.hrms.vo.HrmEmpAdvAppQueryVO;

public class HrmAdvApplnBO extends HrmBaseBO {
  public HrmAdvApplnBO() {}
  
  public HrmAdvApplnBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getEmpAdvAppHdrMetaInfo(HrmEmpAdvAppQueryVO oHrmEmpAdvAppQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sEmpId = oHrmEmpAdvAppQueryVO.getEmpId();
    String sEmpNo = oHrmEmpAdvAppQueryVO.getEmployeeId();
    String sCode = oHrmEmpAdvAppQueryVO.getAdvanceCode();
    String sStatus = oHrmEmpAdvAppQueryVO.getAdvanceStatus();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmEmpAdvAppQueryVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(2, 1, 12, sEmpNo));
    oParameters.add(new DBObject(3, 1, 12, sEmpId));
    oParameters.add(new DBObject(4, 1, 12, sCode));
    oParameters.add(new DBObject(5, 1, 12, sStatus));
    oParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppQueryVO.getFromDate())));
    oParameters.add(new DBObject(7, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppQueryVO.getToDate())));
    oParameters.add(new DBObject(8, 2, -5));
    oParameters.add(new DBObject(9, 2, 93));
    oParameters.add(new DBObject(10, 2, 12));
    oParameters.add(new DBObject(11, 2, 12));
    oParameters.add(new DBObject(12, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.proc_HrEmpAdvApplHdrCount(?,?,?,?,?,?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = oOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = oOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getEmpAdvAppHeader(HrmEmpAdvAppQueryVO oHrmEmpAdvAppQueryVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sEmpNo = oHrmEmpAdvAppQueryVO.getEmployeeId();
    String sCode = oHrmEmpAdvAppQueryVO.getAdvanceCode();
    String sStatus = oHrmEmpAdvAppQueryVO.getAdvanceStatus();
    String sEmpId = oHrmEmpAdvAppQueryVO.getEmpId();
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList oList = null;
    Iterator oIt = null;
    ArrayList oEmpAdvAppDetail = new ArrayList();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    oParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    oParameters.add(new DBObject(3, 1, 12, oHrmEmpAdvAppQueryVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(4, 1, 12, sEmpNo));
    oParameters.add(new DBObject(5, 1, 12, sEmpId));
    oParameters.add(new DBObject(6, 1, 12, sCode));
    oParameters.add(new DBObject(7, 1, 12, sStatus));
    oParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppQueryVO.getFromDate())));
    oParameters.add(new DBObject(9, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppQueryVO.getToDate())));
    oParameters.add(new DBObject(10, 2, -10));
    oParameters.add(new DBObject(11, 2, 12));
    oParameters.add(new DBObject(12, 2, 12));
    oParameters.add(new DBObject(13, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.proc_HrEmpAdvApplHdr(?,?,?,?,?,?,?,?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)oOutArray.get(0)).getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    count = 0;
    oIt = oList.iterator();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (oIt.hasNext()) {
      count++;
      oRow = oIt.next();
      HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean = new HrmEmpAdvAppHdrBean();
      oHrmEmpAdvAppHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmEmpAdvAppHdrBean.setEmployeeNumber(oRow.get("EMP_NO").getString());
      oHrmEmpAdvAppHdrBean.setFirstName(oRow.get("FIRST_NAME").getString());
      oHrmEmpAdvAppHdrBean.setMiddleName(oRow.get("MIDDLE_NAME").getString());
      oHrmEmpAdvAppHdrBean.setLastName(oRow.get("LAST_NAME").getString());
      oHrmEmpAdvAppHdrBean.setGrade(oRow.get("GRADE").getString());
      oHrmEmpAdvAppHdrBean.setDesignation(oRow.get("DESIGNATION").getString());
      oHrmEmpAdvAppHdrBean.setLocation(oRow.get("LOCATION").getString());
      oHrmEmpAdvAppHdrBean.setEmployeeId(oRow.get("E_PER_DTL_ID").getString());
      oHrmEmpAdvAppHdrBean.setAdvanceCodeId(oRow.get("ADV_CODE").getString());
      oHrmEmpAdvAppHdrBean.setAdvanceCode(oRow.get("NAME").getString());
      oHrmEmpAdvAppHdrBean.setDateApplied(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oHrmEmpAdvAppHdrBean.setAmountApplied(oRow.get("APPLIED_AMT").getString());
      oHrmEmpAdvAppHdrBean.setEligibleAmount(oRow.get("ELIG_AMOUNT").getString());
      oHrmEmpAdvAppHdrBean.setSanctionedAmount(oRow.get("SANCTIONED_AMT").getString());
      oHrmEmpAdvAppHdrBean.setSanctionDate(EnrgiseUtil.convertToString(oRow.get("SANCTION_DATE").getDate()));
      oHrmEmpAdvAppHdrBean.setReason(oRow.get("REASON").getString());
      oHrmEmpAdvAppHdrBean.setApproverNoId(oRow.get("APPROVER_ID").getString());
      oHrmEmpAdvAppHdrBean.setApproverName(oRow.get("APPROVER_NAME").getString());
      oHrmEmpAdvAppHdrBean.setRemarks(oRow.get("REMARKS").getString());
      oHrmEmpAdvAppHdrBean.setPayrollMonth(oRow.get("RECOVERY_YYYYMM").getString());
      oHrmEmpAdvAppHdrBean.setNoOfInst(oRow.get("NO_OF_INSTALLMENT").getString());
      oHrmEmpAdvAppHdrBean.setMonthlyInstallment(oRow.get("MTH_INST_AMOUNT").getString());
      oHrmEmpAdvAppHdrBean.setSettledAmount(oRow.get("SETL_AMOUNT").getString());
      oHrmEmpAdvAppHdrBean.setBalance(oRow.get("BALANCE").getString());
      oHrmEmpAdvAppHdrBean.setPaidInstallments(oRow.get("PAID_INSTALLMENTS").getString());
      oEmpAdvAppDetail.add(oHrmEmpAdvAppHdrBean);
    } 
    return oEmpAdvAppDetail;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_EMP_ADV_TXN";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) throws EnrgiseSystemException {}
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return new String();
  }
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public LovVO getHrmAdvAppAdvCdLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("ID");
    oHeaderList.add("hrm.HrmEmpAdvance.advanceName");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    String employeeId = null;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getProperty("employeeId") != null)
      employeeId = oLovQueryVO.getProperty("employeeId"); 
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    oParameters.add(new DBObject(2, 1, 12, employeeId));
    oParameters.add(new DBObject(3, 2, -10));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 12));
    oParameters.add(new DBObject(6, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.proc_GetHrmAdvAppAdvCdLOVdata(?,?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = oList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        oList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("NAME").getString());
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public LovVO getHrmAdvAppAdvCdInsLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("ID");
    oHeaderList.add("hrm.HrmEmpAdvance.advanceName");
    oHeaderList.add("hrm.HrmEmpAdvance.noOfInst");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    oParameters.add(new DBObject(2, 2, -10));
    oParameters.add(new DBObject(3, 2, 12));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.proc_GetHrmAdvAppCdInsLOVdata(?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = oList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        oList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("NAME").getString());
      oLOVBean.setDetailField3(oRow.get("SETTLEMENT_PERIOD").getString());
      oList.add(oLOVBean);
    } 
    oList = checkLOVConstraint(oList, oLovQueryVO);
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public LovVO getHrmAdvAppAdvEligLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList oHeaderList = new ArrayList();
    oHeaderList.add("ID");
    oHeaderList.add("hrm.HrmEmpAdvance.advanceName");
    oHeaderList.add("hrm.HrmEmpAdvance.effectiveFrom");
    oHeaderList.add("hrm.HrmEmpAdvance.effectiveTo");
    oLovVO.setHeaderList(oHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    oParameters.add(new DBObject(2, 2, -10));
    oParameters.add(new DBObject(3, 2, 12));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.proc_GetHrmAdvAppEligLOVdata(?,?,?,?,?)");
    DBObject oOutObject = oOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = oList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        oList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("NAME").getString());
      oLOVBean.setDetailField3(EnrgiseUtil.convertToString(oRow.get("EFFECTIVE_FROM").getDate()));
      oLOVBean.setDetailField4(EnrgiseUtil.convertToString(oRow.get("EFFECTIVE_TO").getDate()));
      oList.add(oLOVBean);
    } 
    oLovVO.setDetailList(oList);
    return oLovVO;
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DBUtilitiesBean oBean1 = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean = (HrmEmpAdvAppHdrBean)oBaseHeaderBean;
    double iMonthlyInst = 0.0D;
    double iSanctionAmt = 0.0D;
    int iNoOfInst = 0;
    iNoOfInst = Integer.parseInt(oHrmEmpAdvAppHdrBean.getNoOfInst());
    iSanctionAmt = Double.parseDouble(oHrmEmpAdvAppHdrBean.getSanctionedAmount());
    iMonthlyInst = iSanctionAmt / iNoOfInst;
    String sEligibleAmount = calculateEligibleAmount((HrmEmpAdvAppHdrBean)oBaseHeaderBean);
    if (ScreenMode.equalsIgnoreCase("N")) {
      oParameters = new ArrayList();
      oParameters.add(new DBObject(1, 1, 12, "N"));
      oParameters.add(new DBObject(2, 1, 12, oHrmEmpAdvAppHdrBean.getEmployeeId()));
      oParameters.add(new DBObject(3, 1, 12, oHrmEmpAdvAppHdrBean.getAdvanceCodeId()));
      oParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppHdrBean.getDateApplied())));
      oParameters.add(new DBObject(5, 1, 12, oHrmEmpAdvAppHdrBean.getAmountApplied()));
      oParameters.add(new DBObject(6, 1, 12, sEligibleAmount));
      oParameters.add(new DBObject(7, 1, 12, oHrmEmpAdvAppHdrBean.getSanctionedAmount()));
      oParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppHdrBean.getSanctionDate())));
      oParameters.add(new DBObject(9, 1, 12, oHrmEmpAdvAppHdrBean.getApproverNoId()));
      oParameters.add(new DBObject(10, 1, 12, oHrmEmpAdvAppHdrBean.getRemarks()));
      oParameters.add(new DBObject(11, 1, 12, oHrmEmpAdvAppHdrBean.getPayrollMonth()));
      oParameters.add(new DBObject(12, 1, 12, oHrmEmpAdvAppHdrBean.getNoOfInst()));
      oParameters.add(new DBObject(13, 1, 12, String.valueOf(iMonthlyInst)));
      oParameters.add(new DBObject(14, 1, 12, oHrmEmpAdvAppHdrBean.getReason()));
      oParameters.add(new DBObject(15, 1, 12, oHrmEmpAdvAppHdrBean.getAmountSettled()));
      oParameters.add(new DBObject(16, 1, 12, oHrmEmpAdvAppHdrBean.getBalance()));
      oParameters.add(new DBObject(17, 1, 12, this.oUserInfo.getUserTypeId()));
      oParameters.add(new DBObject(18, 1, 12, this.oUserInfo.getSiteId()));
      oParameters.add(new DBObject(19, 1, 12, oHrmEmpAdvAppHdrBean.getHeaderPrimaryKey()));
      oParameters.add(new DBObject(20, 2, 12));
      oParameters.add(new DBObject(21, 2, 12));
      oParameters.add(new DBObject(22, 2, 12));
      oParameters.add(new DBObject(23, 2, 4));
      ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.proc_UpsertHrEmpAdvAppHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = (String)oOutObject.getObject();
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getBulkSettleAmount())) {
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "U"));
        oParameters.add(new DBObject(2, 1, 12, oHrmEmpAdvAppHdrBean.getEmployeeId()));
        oParameters.add(new DBObject(3, 1, 12, oHrmEmpAdvAppHdrBean.getAdvanceCodeId()));
        oParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppHdrBean.getDateApplied())));
        oParameters.add(new DBObject(5, 1, 12, oHrmEmpAdvAppHdrBean.getAmountApplied()));
        oParameters.add(new DBObject(6, 1, 12, sEligibleAmount));
        oParameters.add(new DBObject(7, 1, 12, oHrmEmpAdvAppHdrBean.getSanctionedAmount()));
        oParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppHdrBean.getSanctionDate())));
        oParameters.add(new DBObject(9, 1, 12, oHrmEmpAdvAppHdrBean.getApproverNoId()));
        oParameters.add(new DBObject(10, 1, 12, oHrmEmpAdvAppHdrBean.getRemarks()));
        oParameters.add(new DBObject(11, 1, 12, oHrmEmpAdvAppHdrBean.getPayrollMonth()));
        oParameters.add(new DBObject(12, 1, 12, oHrmEmpAdvAppHdrBean.getNoOfInst()));
        oParameters.add(new DBObject(13, 1, 12, String.valueOf(iMonthlyInst)));
        oParameters.add(new DBObject(14, 1, 12, oHrmEmpAdvAppHdrBean.getReason()));
        oParameters.add(new DBObject(15, 1, 12, oHrmEmpAdvAppHdrBean.getAmountSettled()));
        oParameters.add(new DBObject(16, 1, 12, oHrmEmpAdvAppHdrBean.getBalance()));
        oParameters.add(new DBObject(17, 1, 12, this.oUserInfo.getUserTypeId()));
        oParameters.add(new DBObject(18, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(19, 1, 12, oHrmEmpAdvAppHdrBean.getHeaderPrimaryKey()));
        oParameters.add(new DBObject(20, 2, 12));
        oParameters.add(new DBObject(21, 2, 12));
        oParameters.add(new DBObject(22, 2, 12));
        oParameters.add(new DBObject(23, 2, 4));
        ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.proc_UpsertHrEmpAdvAppHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        DBObject oOutObject = oOutArray.get(0);
        returnString = (String)oOutObject.getObject();
      } else {
        double iAmountSettled = 0.0D;
        double iBalance = 0.0D;
        double bulk = Double.parseDouble(oHrmEmpAdvAppHdrBean.getBulkSettleAmount());
        if (bulk < Double.parseDouble(oHrmEmpAdvAppHdrBean.getBalance())) {
          iAmountSettled = Double.parseDouble(oHrmEmpAdvAppHdrBean.getSettledAmount()) + bulk;
          iBalance = Double.parseDouble(oHrmEmpAdvAppHdrBean.getBalance()) - bulk;
        } else if (bulk >= Double.parseDouble(oHrmEmpAdvAppHdrBean.getBalance())) {
          iAmountSettled = Double.parseDouble(oHrmEmpAdvAppHdrBean.getSettledAmount()) + bulk;
          iBalance = 0.0D;
        } 
        oParameters = new ArrayList();
        oParameters.add(new DBObject(1, 1, 12, "U"));
        oParameters.add(new DBObject(2, 1, 12, oHrmEmpAdvAppHdrBean.getEmployeeId()));
        oParameters.add(new DBObject(3, 1, 12, oHrmEmpAdvAppHdrBean.getAdvanceCodeId()));
        oParameters.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppHdrBean.getDateApplied())));
        oParameters.add(new DBObject(5, 1, 12, oHrmEmpAdvAppHdrBean.getAmountApplied()));
        oParameters.add(new DBObject(6, 1, 12, sEligibleAmount));
        oParameters.add(new DBObject(7, 1, 12, oHrmEmpAdvAppHdrBean.getSanctionedAmount()));
        oParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppHdrBean.getSanctionDate())));
        oParameters.add(new DBObject(9, 1, 12, oHrmEmpAdvAppHdrBean.getApproverNoId()));
        oParameters.add(new DBObject(10, 1, 12, oHrmEmpAdvAppHdrBean.getRemarks()));
        oParameters.add(new DBObject(11, 1, 12, oHrmEmpAdvAppHdrBean.getPayrollMonth()));
        oParameters.add(new DBObject(12, 1, 12, oHrmEmpAdvAppHdrBean.getNoOfInst()));
        oParameters.add(new DBObject(13, 1, 12, String.valueOf(iMonthlyInst)));
        oParameters.add(new DBObject(14, 1, 12, oHrmEmpAdvAppHdrBean.getReason()));
        oParameters.add(new DBObject(15, 1, 12, String.valueOf(iAmountSettled)));
        oParameters.add(new DBObject(16, 1, 12, String.valueOf(iBalance)));
        oParameters.add(new DBObject(17, 1, 12, this.oUserInfo.getUserTypeId()));
        oParameters.add(new DBObject(18, 1, 12, this.oUserInfo.getSiteId()));
        oParameters.add(new DBObject(19, 1, 12, oHrmEmpAdvAppHdrBean.getHeaderPrimaryKey()));
        oParameters.add(new DBObject(20, 2, 12));
        oParameters.add(new DBObject(21, 2, 12));
        oParameters.add(new DBObject(22, 2, 12));
        oParameters.add(new DBObject(23, 2, 4));
        ArrayList oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.proc_UpsertHrEmpAdvAppHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        DBObject oOutObject = oOutArray.get(0);
        returnString = (String)oOutObject.getObject();
      } 
    } else if (ScreenMode.equalsIgnoreCase("D")) {
      oParameters.add(new DBObject(1, 1, 12, oHrmEmpAdvAppHdrBean.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, "HRMADVAPPL.proc_DelHrEmpAdvApplHdr(?,?,?,?)");
      DBObject oOutObject = oOutArray.get(0);
      returnString = null;
    } 
    return returnString;
  }
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oErrorList = new ArrayList();
    HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean = (HrmEmpAdvAppHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged) {
      if (!sScreenMode.equalsIgnoreCase("D")) {
        if (EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getPayrollMonth()))
          checkRecoveryYearMonth((HrmEmpAdvAppHdrBean)oBaseHeaderBean, sScreenMode); 
        checkUniqueHeader((HrmEmpAdvAppHdrBean)oBaseHeaderBean);
      } 
      if (sScreenMode.equalsIgnoreCase("N"))
        checkSanctionedAmount((HrmEmpAdvAppHdrBean)oBaseHeaderBean); 
      if (sScreenMode.equalsIgnoreCase("U"))
        checkBulkAmount((HrmEmpAdvAppHdrBean)oBaseHeaderBean); 
    } 
    reportError(oErrorList);
  }
  
  private void checkRecoveryYearMonth(HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean, String sScreenMode) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    ArrayList arylstErrorList = new ArrayList();
    String sPayrollMonth = new String();
    String sMonth = new String();
    sPayrollMonth = oHrmEmpAdvAppHdrBean.getPayrollMonth();
    if (Integer.parseInt(sPayrollMonth.substring(4, 6)) < 1 || Integer.parseInt(sPayrollMonth.substring(4, 6)) > 12) {
      arylstParam.add("Advance Application: Year Month");
      arylstParam.add(new Integer(0));
      arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkPayrollMonth", arylstParam));
    } 
    if (Integer.parseInt(sPayrollMonth.substring(0, 1)) == 0) {
      arylstParam.add("Advance Application: Year Month");
      arylstParam.add(new Integer(0));
      arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkPayrollYear", arylstParam));
    } 
    HrmCommonBO oBO = new HrmCommonBO();
    String sysDate = oBO.getSysDate();
    String sYYYYMM = String.valueOf(sysDate.substring(6, sysDate.length())).concat(String.valueOf(sysDate.substring(3, 5)));
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstParam1 = new ArrayList();
    arylstParam1.add(new DBObject(1, 1, 12, oHrmEmpAdvAppHdrBean.getHeaderPrimaryKey()));
    arylstParam1.add(new DBObject(2, 2, 4));
    arylstParam1.add(new DBObject(3, 2, 4));
    arylstParam1.add(new DBObject(4, 2, 12));
    arylstParam1.add(new DBObject(5, 2, 12));
    arylstParam1.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParam1, "hrmadvappl.procgetpayrollinfo(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    DBObject oOutObject1 = arylstOutArray.get(1);
    int iVal = ((Integer)oOutObject.getObject()).intValue();
    int yearMonth = ((Integer)oOutObject1.getObject()).intValue();
    int year = Integer.parseInt(String.valueOf(yearMonth).substring(0, 4));
    int month = Integer.parseInt(String.valueOf(yearMonth).substring(4, 6));
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getBulkSettleAmount())) {
      if (year > Integer.parseInt(sPayrollMonth.substring(0, 4))) {
        arylstParam.add("Loan Application: Year Month");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkPayrollMonth1", arylstParam));
      } 
      if (year == Integer.parseInt(sPayrollMonth.substring(0, 4)))
        if (month > Integer.parseInt(sPayrollMonth.substring(4, 6))) {
          arylstParam.add("Loan Application: Year Month");
          arylstParam.add(new Integer(0));
          arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkPayrollMonth1", arylstParam));
        }  
    } 
    if (iVal != 1) {
      arylstParam.add("Loan Application: Year Month");
      arylstParam.add(new Integer(0));
      arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkPayrollMonth2", arylstParam));
    } 
    reportError(arylstErrorList);
  }
  
  private void checkBulkAmount(HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    ArrayList arylstErrorList = new ArrayList();
    if (EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getBulkSettleAmount()))
      if (Double.parseDouble(oHrmEmpAdvAppHdrBean.getBulkSettleAmount()) > Double.parseDouble(oHrmEmpAdvAppHdrBean.getBalance())) {
        arylstParam.add("Bulk Settlement Amount : ");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpAdvance.bulkSettleAmountError", arylstParam));
      }  
    reportError(arylstErrorList);
  }
  
  private void checkUniqueHeader(HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  private void checkSanctionedAmount(HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    double iSanctionedAmt = Double.parseDouble(oHrmEmpAdvAppHdrBean.getSanctionedAmount());
    String sEligibleAmount = calculateEligibleAmount(oHrmEmpAdvAppHdrBean);
    if (Double.parseDouble(sEligibleAmount) == 0.0D) {
      arylstParam = new ArrayList();
      arylstParam.add("");
      arylstParam.add(new Integer(0));
      arylstList.add(new EnrgiseMessageKeyException("hrm.HrmEmpAdvance.checkEligAmt", arylstParam));
    } else {
      double iEligibleAmount = Double.parseDouble(sEligibleAmount);
      if (iSanctionedAmt > iEligibleAmount) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstList.add(new EnrgiseMessageKeyException("hrm.HrmEmpAdvance.checkAmount", arylstParam));
      } 
    } 
    reportError(arylstList);
  }
  
  private void checkMandatoryHeader(HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getAdvanceCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpAdvance.advanceCode");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getDateApplied())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpAdvance.dateApplied");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getAmountApplied())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpAdvance.amountApplied");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getNoOfInst())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpAdvance.noOfInst");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getPayrollMonth())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpAdvance.payrollMonth");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getApproverNoId())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpAdvance.approverName");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getSanctionDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.sanctionDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmEmpAdvAppHdrBean.getSanctionedAmount())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.sanctionedAmount");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  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((HrmEmpAdvAppHdrBean)oBaseHeaderBean);  
    reportError(oErrorList);
  }
  
  private ArrayList checkLOVConstraint(ArrayList oList, LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LOVBean oLOVBean = null;
    ArrayList arylstNewList = new ArrayList();
    Iterator itrBean = oList.iterator();
    while (itrBean.hasNext()) {
      oLOVBean = itrBean.next();
      String sId = oLOVBean.getDetailField1();
      String sAllFlag = getAllFlagInfo(sId);
      if (sAllFlag.equalsIgnoreCase("Y")) {
        arylstNewList.add(oLOVBean);
        continue;
      } 
      String sAttrId = oLOVBean.getDetailField1();
      String sQuery = String.valueOf(" Select ELIG_SQL as ELIG_SQL from HRM_ADV_DTL where ID= ").concat(String.valueOf(sAttrId));
      DBUtilitiesBean oBean = new DBUtilitiesBean();
      ArrayList arylstList1 = oBean.executeQuery(sQuery);
      Iterator itrBean1 = arylstList1.iterator();
      if (itrBean1.hasNext()) {
        QueryRow oRow = itrBean1.next();
        String sSql = oRow.get("ELIG_SQL").getString();
        if (EnrgiseUtil.checkString(sSql)) {
          String sEmpId = oLovQueryVO.getProperty("employeeId");
          StringBuffer s = new StringBuffer(sSql);
          s.replace(s.lastIndexOf("?"), s.lastIndexOf("?") + 1, sEmpId);
          ArrayList arylstList2 = oBean.executeQuery(s.toString());
          if (arylstList2.size() != 0)
            arylstNewList.add(oLOVBean); 
        } 
      } 
    } 
    return arylstNewList;
  }
  
  public String getAllFlagInfo(String sAttrId) throws EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    String sAllFlag = null;
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, sAttrId));
    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, "HRMADVAPPL.proc_GetAllFlag(?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList oList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = oList.iterator();
    while (itrBean.hasNext()) {
      oRow = itrBean.next();
      sAllFlag = oRow.get("ALL_FLAG").getString();
    } 
    return sAllFlag;
  }
  
  private String calculateEligibleAmount(HrmEmpAdvAppHdrBean oHrmEmpAdvAppHdrBean) throws EnrgiseSystemException {
    ArrayList oList = new ArrayList();
    ArrayList oList1 = new ArrayList();
    int count = 0;
    ArrayList oParameters = new ArrayList();
    ArrayList oParameters1 = new ArrayList();
    ArrayList oOutArray = new ArrayList();
    ArrayList oOutArray1 = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DBUtilitiesBean oBean1 = new DBUtilitiesBean();
    QueryRow oRow = null;
    QueryRow oRow1 = null;
    String sEligAmount = new String();
    String sEligFactor = new String();
    String sFlatAmt = new String();
    String sNoOfMnthSal = new String();
    String sSalary = new String();
    String sBasic = new String();
    String sFA = new String();
    String sDA = new String();
    int count1 = 0;
    int count2 = 0;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmEmpAdvAppHdrBean.getAdvanceCodeId()));
    oParameters.add(new DBObject(2, 1, 12, oHrmEmpAdvAppHdrBean.getEmployeeId()));
    oParameters.add(new DBObject(3, 2, -10));
    oParameters.add(new DBObject(4, 2, 12));
    oParameters.add(new DBObject(5, 2, 12));
    oParameters.add(new DBObject(6, 2, 4));
    oOutArray = oBean.callProc(oParameters, "HRMADVAPPL.procCalculateEligibleAmount(?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)oOutArray.get(0)).getObject();
    count1 = 0;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      count1++;
      oRow = oIt.next();
      sEligFactor = oRow.get("GREATER_LESSER_FLAG").getString();
      sFlatAmt = oRow.get("FLAT_AMOUNT").getString();
      sNoOfMnthSal = oRow.get("NO_OF_MONTHS_SAL").getString();
    } 
    oParameters1 = new ArrayList();
    oParameters1.add(new DBObject(1, 1, 12, oHrmEmpAdvAppHdrBean.getEmployeeId()));
    oParameters1.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmEmpAdvAppHdrBean.getSanctionDate())));
    oParameters1.add(new DBObject(3, 2, -10));
    oParameters1.add(new DBObject(4, 2, 12));
    oParameters1.add(new DBObject(5, 2, 12));
    oParameters1.add(new DBObject(6, 2, 4));
    oOutArray1 = oBean1.callProc(oParameters1, "HRMADVAPPL.procCalculateSalary(?,?,?,?,?,?)");
    oList1 = (ArrayList)((DBObject)oOutArray1.get(0)).getObject();
    if (oList1.size() == 0)
      return "0"; 
    count2 = 0;
    Iterator oIt1 = oList1.iterator();
    while (oIt1.hasNext()) {
      count2++;
      oRow1 = oIt1.next();
      sFA = oRow1.get("FIXED_ALLOW").getString();
      sDA = oRow1.get("DA_AMOUNT").getString();
      sBasic = oRow1.get("BASIC").getString();
      if (Double.parseDouble(sDA) == 0.0D) {
        sSalary = String.valueOf(Double.parseDouble(sBasic) + Double.parseDouble(sFA));
        continue;
      } 
      sSalary = String.valueOf(Double.parseDouble(sBasic) + Double.parseDouble(sDA));
    } 
    if (String.valueOf(oRow.get("GREATER_LESSER_FLAG").getString()).equalsIgnoreCase("F"))
      sEligAmount = sFlatAmt; 
    if (String.valueOf(oRow.get("GREATER_LESSER_FLAG").getString()).equalsIgnoreCase("S")) {
      long lEligAmt = Math.round(Double.parseDouble(sNoOfMnthSal) * Double.parseDouble(sSalary));
      sEligAmount = String.valueOf(lEligAmt);
    } 
    if (String.valueOf(oRow.get("GREATER_LESSER_FLAG").getString()).equalsIgnoreCase(""))
      sEligAmount = sFlatAmt; 
    return sEligAmount;
  }
  
  public LovVO getHrmAdvAppEmpNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmEmpPersonalDetails.employeeNo");
    arylstHeaderList.add("hrm.HrmEmpPersonalDetails.firstName");
    arylstHeaderList.add("hrm.HrmEmpPersonalDetails.middleName");
    arylstHeaderList.add("hrm.HrmEmpPersonalDetails.lastName");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.grade");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.designation");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.location");
    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");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    String sEmpId = new String();
    if (oLovQueryVO.getProperty("SelUser") != null)
      sEmpId = oLovQueryVO.getProperty("SelUser"); 
    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, sEmpId));
    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, "HRMADVAPPL.procgetemplovqdata(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstParam.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstParam = new ArrayList(); 
      count++;
      oRow = (QueryRow)iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("FIRST_NAME").getString());
      oLOVBean.setDetailField4(oRow.get("MIDDLE_NAME").getString());
      oLOVBean.setDetailField5(oRow.get("LAST_NAME").getString());
      oLOVBean.setDetailField6(oRow.get("GRADE").getString());
      oLOVBean.setDetailField7(oRow.get("DESIGNATION").getString());
      oLOVBean.setDetailField8(oRow.get("LOCATION").getString());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
  
  public LovVO getHrmAdvAppInsEmpNoLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmEmpPersonalDetails.employeeNo");
    arylstHeaderList.add("hrm.HrmEmpPersonalDetails.firstName");
    arylstHeaderList.add("hrm.HrmEmpPersonalDetails.middleName");
    arylstHeaderList.add("hrm.HrmEmpPersonalDetails.lastName");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.grade");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.designation");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.location");
    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");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    String sEmpId = new String();
    if (oLovQueryVO.getProperty("SelUser") != null)
      sEmpId = oLovQueryVO.getProperty("SelUser"); 
    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, sEmpId));
    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, "HRMADVAPPL.procGetEmpInsLOVdata(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstParam.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstParam = new ArrayList(); 
      count++;
      oRow = (QueryRow)iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("EMP_NO").getString());
      oLOVBean.setDetailField3(oRow.get("FIRST_NAME").getString());
      oLOVBean.setDetailField4(oRow.get("MIDDLE_NAME").getString());
      oLOVBean.setDetailField5(oRow.get("LAST_NAME").getString());
      oLOVBean.setDetailField6(oRow.get("GRADE").getString());
      oLOVBean.setDetailField7(oRow.get("DESIGNATION").getString());
      oLOVBean.setDetailField8(oRow.get("LOCATION").getString());
      arylstParam.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstParam);
    return oLovVO;
  }
}
