package wenrgise.hrms.ejb.business;

import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import 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.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.BaseDetailVO;
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.HrmLnAppDtlBean;
import wenrgise.hrms.bean.HrmLnAppHdrBean;
import wenrgise.hrms.bean.HrmLnDisDtlBean;
import wenrgise.hrms.bean.HrmLnHblIntDtlBean;
import wenrgise.hrms.vo.HrmLnAppQVO;
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 HrmLnAppBO extends HrmBaseBO {
  public HrmLnAppBO() {}
  
  public HrmLnAppBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrEmpLoanAppHdrMetaInfo(HrmLnAppQVO oHrmLnAppQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmLnAppQVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(2, 1, 12, oHrmLnAppQVO.getEmployeeNumber()));
    oParameters.add(new DBObject(3, 1, 12, oHrmLnAppQVO.getLoanCode()));
    oParameters.add(new DBObject(4, 2, -5));
    oParameters.add(new DBObject(5, 2, 93));
    oParameters.add(new DBObject(6, 2, 12));
    oParameters.add(new DBObject(7, 2, 12));
    oParameters.add(new DBObject(8, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMLNAPPL.procHrmLnAppHdrCount(?,?,?,?,?,?,?,?)");
    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 getHrEmpLoanAppHeader(HrmLnAppQVO oHrmLnAppQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList oList = null;
    Iterator oIt = null;
    ArrayList oEmpLoanAppDetail = null;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    oParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    oParameters.add(new DBObject(3, 1, 12, oHrmLnAppQVO.getHeaderPrimaryKey()));
    oParameters.add(new DBObject(4, 1, 12, oHrmLnAppQVO.getEmployeeNumber()));
    oParameters.add(new DBObject(5, 1, 12, oHrmLnAppQVO.getLoanCode()));
    oParameters.add(new DBObject(6, 2, -10));
    oParameters.add(new DBObject(7, 2, 12));
    oParameters.add(new DBObject(8, 2, 12));
    oParameters.add(new DBObject(9, 2, 4));
    ArrayList oOutArray = oBean.callProc(oParameters, "HRMLNAPPL.procHrmLnAppHdr(?,?,?,?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)oOutArray.get(0)).getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    count = 0;
    oIt = oList.iterator();
    while (oIt.hasNext()) {
      if (count == 0)
        oEmpLoanAppDetail = new ArrayList(); 
      count++;
      oRow = oIt.next();
      HrmLnAppHdrBean oHrmLnAppHdrBean = new HrmLnAppHdrBean();
      oHrmLnAppHdrBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHrmLnAppHdrBean.setEmpId(oRow.get("EMP_ID").getString());
      oHrmLnAppHdrBean.setEmployeeNumber(oRow.get("EMP_NO").getString());
      oHrmLnAppHdrBean.setFirstName(oRow.get("FIRST_NAME").getString());
      oHrmLnAppHdrBean.setMiddleName(oRow.get("MIDDLE_NAME").getString());
      oHrmLnAppHdrBean.setLastName(oRow.get("LAST_NAME").getString());
      oHrmLnAppHdrBean.setGrade(oRow.get("GRADE").getString());
      oHrmLnAppHdrBean.setDesignation(oRow.get("DESIGNATION").getString());
      oHrmLnAppHdrBean.setLocation(oRow.get("LOCATION").getString());
      oHrmLnAppHdrBean.setLoanCode(oRow.get("LOAN_CODE").getString());
      oHrmLnAppHdrBean.setLoanDesc(oRow.get("LOAN_NAME").getString());
      oHrmLnAppHdrBean.setLoanCodeId(oRow.get("LOAN_ID").getString());
      oHrmLnAppHdrBean.setAppliedAmount(oRow.get("APPLIED_AMOUNT").getString());
      oHrmLnAppHdrBean.setApplnDate(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oHrmLnAppHdrBean.setEligibleAmount(oRow.get("ELIG_LOAN_AMT").getString());
      oHrmLnAppHdrBean.setFullyRepaid(String.valueOf(oRow.get("FULLY_REPAID_FLAG").getString()).equalsIgnoreCase("Y") ? "on" : "off");
      oHrmLnAppHdrBean.setLoanDetails(oRow.get("LOAN_DETAILS").getString());
      oHrmLnAppHdrBean.setApproverNoId(oRow.get("APPROVER_ID").getString());
      oHrmLnAppHdrBean.setApproverName(oRow.get("APPROVER_NAME").getString());
      oHrmLnAppHdrBean.setSanctionedAmount(oRow.get("LOAN_AMOUNT").getString());
      oHrmLnAppHdrBean.setSanctionDate(EnrgiseUtil.convertToString(oRow.get("SANCTION_DATE").getDate()));
      oHrmLnAppHdrBean.setRemarks(oRow.get("APPROVER_REMARKS").getString());
      oHrmLnAppHdrBean.setTotalInst(oRow.get("NO_OF_INSTALMENTS").getString());
      oHrmLnAppHdrBean.setTotalPrincipalInst(oRow.get("NO_OF_INST_PRINCIPAL").getString());
      oHrmLnAppHdrBean.setTotalInterestInst(oRow.get("NO_OF_INST_INTEREST").getString());
      oHrmLnAppHdrBean.setInstAmount(oRow.get("INSTALLMENT_AMOUNT").getString());
      oHrmLnAppHdrBean.setPayrollMonth(oRow.get("RECOVERY_YYYYMM").getString());
      oHrmLnAppHdrBean.setNoOfInstPaid(oRow.get("NO_OF_INST_PAID").getString());
      oHrmLnAppHdrBean.setNoOfInstPrincipalPaid(oRow.get("NO_OF_INST_PAID_PRINCIPAL").getString());
      oHrmLnAppHdrBean.setNoOfInstInterestPaid(oRow.get("NO_OF_INST_PAID_INTEREST").getString());
      oHrmLnAppHdrBean.setTotalAmountPaid(oRow.get("TOTAL_AMOUNT_PAID").getString());
      oHrmLnAppHdrBean.setPrincipalPaid(oRow.get("TOTAL_PRINCIPAL_PAID").getString());
      oHrmLnAppHdrBean.setInterestPaid(oRow.get("TOTAL_INTEREST_PAID").getString());
      oHrmLnAppHdrBean.setTotalBalance(oRow.get("TOTAL_OUTSTG_BAL").getString());
      oHrmLnAppHdrBean.setPrincipalBalance(oRow.get("OUTSTG_BAL_PRINCIPAL").getString());
      oHrmLnAppHdrBean.setInterestBalance(oRow.get("OUTSTG_BAL_INTEREST").getString());
      oHrmLnAppHdrBean.setHblAppliedFor(oRow.get("HBL_APPLIED_FOR").getString());
      oHrmLnAppHdrBean.setHblBookNo(oRow.get("HBL_BOOK_NO").getString());
      oHrmLnAppHdrBean.setHblBranhConst(oRow.get("HBL_NEAREST_BRANCH").getString());
      oHrmLnAppHdrBean.setHblCity(oRow.get("HBL_CITY").getString());
      oHrmLnAppHdrBean.setHblDag(oRow.get("HBL_DAG_CSPLOT").getString());
      oHrmLnAppHdrBean.setHblDistrict(oRow.get("HBL_DIST").getString());
      oHrmLnAppHdrBean.setHblDocSubmitted(String.valueOf(oRow.get("HBL_DOC_FLAG").getString()).equalsIgnoreCase("Y") ? "on" : "off");
      oHrmLnAppHdrBean.setHblKhatian(oRow.get("HBL_KHATIAN").getString());
      oHrmLnAppHdrBean.setHblMouza(oRow.get("HBL_MOUZA").getString());
      oHrmLnAppHdrBean.setHblNoOfDeed(oRow.get("HBL_DEED_NO").getString());
      oHrmLnAppHdrBean.setHblPageNo(oRow.get("HBL_PAGE_NO").getString());
      oHrmLnAppHdrBean.setHblParentDeed(oRow.get("HBL_PARENT_DEED_NO").getString());
      oHrmLnAppHdrBean.setHblPO(oRow.get("HBL_PO").getString());
      oHrmLnAppHdrBean.setHblRegisteredAt(oRow.get("HBL_REGISTER_ADD").getString());
      oHrmLnAppHdrBean.setHblVolOfDeed(oRow.get("HBL_DEED_VOL").getString());
      oEmpLoanAppDetail.add(oHrmLnAppHdrBean);
    } 
    return oEmpLoanAppDetail;
  }
  
  public RecordMetaInfo getHrmLnAppDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParam.add(new DBObject(2, 2, -5));
    arylstParam.add(new DBObject(3, 2, 93));
    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, "HRMLNAPPL.procHrLnAppDtlCount(?,?,?,?,?,?)");
    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 getHrmLnAppDtl(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arrLoanApp = 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, lPrimaryKey));
    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, "HRMLNAPPL.procHrLnAppDtl(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    if (arylstParam.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstParam.iterator();
    HrmLnAppDtlBean oHrmLnAppDtlBean = new HrmLnAppDtlBean();
    while (itrBean.hasNext()) {
      if (count == 0)
        arrLoanApp = new ArrayList(); 
      count++;
      oRow = (QueryRow)itrBean.next();
      oHrmLnAppDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmLnAppDtlBean.setAppliedAmount(oRow.get("APPLIED_AMOUNT").getString());
      oHrmLnAppDtlBean.setApplnDate(EnrgiseUtil.convertToString(oRow.get("APPLICATION_DATE").getDate()));
      oHrmLnAppDtlBean.setApprovedFlag(oRow.get("APPROVED_FLAG").getString());
      oHrmLnAppDtlBean.setEligibleAmount(oRow.get("ELIG_LOAN_AMT").getString());
      oHrmLnAppDtlBean.setFirstInstDate(EnrgiseUtil.convertToString(oRow.get("FIRST_INSTAL_PAY_DATE").getDate()));
      oHrmLnAppDtlBean.setFullyRepaid(String.valueOf(oRow.get("FULLY_REPAID_FLAG").getString()).equalsIgnoreCase("Y") ? "on" : "off");
      oHrmLnAppDtlBean.setNoOfInstallment(oRow.get("NO_OF_INSTALMENTS").getString());
      oHrmLnAppDtlBean.setPercProperty(oRow.get("PERC_PROPERTY").getString());
      oHrmLnAppDtlBean.setPropertyPrice(oRow.get("PROPERTY_PRICE").getString());
      oHrmLnAppDtlBean.setReason(oRow.get("REASON").getString());
      oHrmLnAppDtlBean.setRemarks(oRow.get("REJECTION_REMARK").getString());
      oHrmLnAppDtlBean.setSanctionedAmount(oRow.get("LOAN_AMOUNT").getString());
      oHrmLnAppDtlBean.setSanctionDate(EnrgiseUtil.convertToString(oRow.get("SANCTION_DATE").getDate()));
      arrLoanApp.add(oHrmLnAppDtlBean);
    } 
    return arrLoanApp;
  }
  
  public RecordMetaInfo getHrmLnDisDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParam.add(new DBObject(2, 2, -5));
    arylstParam.add(new DBObject(3, 2, 93));
    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, "HRMLNAPPL.procHrLnDisDtlCount(?,?,?,?,?,?)");
    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 getHrmLnDisDtl(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arrLoanDisburse = 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, lPrimaryKey));
    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, "HRMLNAPPL.procHrLnDisDtl(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    if (arylstParam.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstParam.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arrLoanDisburse = new ArrayList(); 
      count++;
      oRow = (QueryRow)itrBean.next();
      HrmLnDisDtlBean oHrmLnDisDtlBean = new HrmLnDisDtlBean();
      oHrmLnDisDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmLnDisDtlBean.setTentativeDisDate(EnrgiseUtil.convertToString(oRow.get("TENTATIVE_DATE").getDate()));
      oHrmLnDisDtlBean.setTentativeAmt(oRow.get("TENTATIVE_AMOUNT").getString());
      oHrmLnDisDtlBean.setActDisDate(EnrgiseUtil.convertToString(oRow.get("ACTUAL_DATE").getDate()));
      oHrmLnDisDtlBean.setActDisAmt(oRow.get("ACTUAL_AMOUNT").getString());
      arrLoanDisburse.add(oHrmLnDisDtlBean);
    } 
    return arrLoanDisburse;
  }
  
  public RecordMetaInfo getHrmLnHblIntRateMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParam = new ArrayList();
    arylstParam.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParam.add(new DBObject(2, 2, -5));
    arylstParam.add(new DBObject(3, 2, 93));
    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, "HRMLNAPPL.prochrlnHblIntcount(?,?,?,?,?,?)");
    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 getHrmLnHblIntRateDtl(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arrHblIntRate = 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, lPrimaryKey));
    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, "HRMLNAPPL.prochrlnHblInt(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    arylstParam = (ArrayList)oOutObject.getObject();
    if (arylstParam.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstParam.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arrHblIntRate = new ArrayList(); 
      count++;
      oRow = (QueryRow)itrBean.next();
      HrmLnHblIntDtlBean oHrmLnHblIntDtlBean = new HrmLnHblIntDtlBean();
      oHrmLnHblIntDtlBean.setDetailId(oRow.get("ID").getString());
      oHrmLnHblIntDtlBean.setTxtFromAmount(oRow.get("amount_from").getString());
      oHrmLnHblIntDtlBean.setTxtToAmount(oRow.get("amount_to").getString());
      oHrmLnHblIntDtlBean.setTxtPercentage(oRow.get("int_perc").getString());
      arrHblIntRate.add(oHrmLnHblIntDtlBean);
    } 
    return arrHblIntRate;
  }
  
  public LovVO getHrmLnAppEmpNoQLOVdata(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();
    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, 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, "HRMLNAPPL.procGetEmpQLOVdata(?,?,?,?,?,?)");
    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 getHrmLnAppEmpNoLOVdata(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();
    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, 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, "HRMLNAPPL.procGetEmpLOVdata(?,?,?,?,?,?)");
    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 getHrmLnAppLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("Code ID");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.loanCode");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.loanDesc");
    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();
    String sEmpId = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    if (oLovQueryVO.getProperty("empId") != null)
      sEmpId = oLovQueryVO.getProperty("empId"); 
    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, "HRMLNAPPL.procGetHrmLnAppLOVdata(?,?,?,?,?,?,?)");
    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("LOAN_ID").getString());
      oLOVBean.setDetailField2(oRow.get("LOAN_CODE").getString());
      oLOVBean.setDetailField3(oRow.get("LOAN_NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmLnAppInsLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    String sEmpId = oLovQueryVO.getProperty("empId");
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("Code ID");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.loanCode");
    arylstHeaderList.add("hrm.HrmEmpLoanAppln.loanDesc");
    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(); 
    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, "HRMLNAPPL.procGetHrmLnAppInsLOVdata(?,?,?,?,?,?,?)");
    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("LOAN_ID").getString());
      oLOVBean.setDetailField2(oRow.get("LOAN_CODE").getString());
      oLOVBean.setDetailField3(oRow.get("LOAN_NAME").getString());
      arylstList.add(oLOVBean);
    } 
    arylstList = checkLOVConstraint(arylstList, oLovQueryVO);
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  private ArrayList checkLOVConstraint(ArrayList arylstList, LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LOVBean oLOVBean = null;
    ArrayList arylstNewList = new ArrayList();
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      oLOVBean = itrBean.next();
      String sId = oLOVBean.getDetailField1();
      String sAllFlag = getAllFlagInfo(sId);
      System.out.println(sAllFlag);
      if (sAllFlag.equalsIgnoreCase("Y")) {
        arylstNewList.add(oLOVBean);
        continue;
      } 
      String sLoanId = oLOVBean.getDetailField1();
      String sQuery = String.valueOf(" Select ELIG_SQL as ELIG_SQL from HRM_LOAN_DTL where ID= ").concat(String.valueOf(sLoanId));
      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("empId");
          StringBuffer s = new StringBuffer(sSql);
          s.replace(s.lastIndexOf("?"), s.lastIndexOf("?") + 1, sEmpId);
          System.out.println(s);
          ArrayList arylstList2 = oBean.executeQuery(s.toString());
          if (arylstList2.size() != 0)
            arylstNewList.add(oLOVBean); 
        } 
      } 
    } 
    return arylstNewList;
  }
  
  public String getAllFlagInfo(String sLoanId) 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, sLoanId));
    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, "HRMLNAPPL.procGetAllFlag(?,?,?,?,?)");
    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();
      sAllFlag = oRow.get("ALL_FLAG").getString();
    } 
    return sAllFlag;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_EMP_LOAN";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmLnApp"))
      saveHrmLnDisDtl(sHeaderPrimaryKey, arylstDetailBeanArray); 
    if (sScreenName.equalsIgnoreCase("HrmLnAppHblIntRate"))
      saveHrmLnHblIntRate(sHeaderPrimaryKey, arylstDetailBeanArray); 
  }
  
  private void saveHrmLnDisDtl(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmLnDisDtlBean oHrmLnDisDtlBean = itrBean.next();
      if (oHrmLnDisDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMLNAPPL.procUpsertHrmLnDisDtl(?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "I"));
        arylstParam.add(new DBObject(2, 1, 12, null));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnDisDtlBean.getTentativeDisDate())));
        arylstParam.add(new DBObject(5, 1, 12, oHrmLnDisDtlBean.getTentativeAmt()));
        arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnDisDtlBean.getActDisDate())));
        arylstParam.add(new DBObject(7, 1, 12, oHrmLnDisDtlBean.getActDisAmt()));
        arylstParam.add(new DBObject(8, 1, 12, this.oUserInfo.getUserId()));
        arylstParam.add(new DBObject(9, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmLnDisDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMLNAPPL.procUpsertHrmLnDisDtl(?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "U"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmLnDisDtlBean.getDetailId()));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnDisDtlBean.getTentativeDisDate())));
        arylstParam.add(new DBObject(5, 1, 12, oHrmLnDisDtlBean.getTentativeAmt()));
        arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnDisDtlBean.getActDisDate())));
        arylstParam.add(new DBObject(7, 1, 12, oHrmLnDisDtlBean.getActDisAmt()));
        arylstParam.add(new DBObject(8, 1, 12, this.oUserInfo.getUserId()));
        arylstParam.add(new DBObject(9, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmLnDisDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMLNAPPL.procDeleteHrmLnDisDtl(?)");
          bDelete = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, oHrmLnDisDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParam);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  private void saveHrmLnHblIntRate(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    DBUtilitiesBean oBean2 = null;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmLnHblIntDtlBean oHrmLnHblIntDtlBean = itrBean.next();
      if (oHrmLnHblIntDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMLNAPPL.procupserthrmHblInt(?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "I"));
        arylstParam.add(new DBObject(2, 1, 12, null));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmLnHblIntDtlBean.getTxtFromAmount()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmLnHblIntDtlBean.getTxtToAmount()));
        arylstParam.add(new DBObject(6, 1, 12, oHrmLnHblIntDtlBean.getTxtPercentage()));
        arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getUserId()));
        arylstParam.add(new DBObject(8, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmLnHblIntDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean2 = new DBUtilitiesBean();
          oBean2.createBatch("HRMLNAPPL.procupserthrmHblInt(?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "U"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmLnHblIntDtlBean.getDetailId()));
        arylstParam.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParam.add(new DBObject(4, 1, 12, oHrmLnHblIntDtlBean.getTxtFromAmount()));
        arylstParam.add(new DBObject(5, 1, 12, oHrmLnHblIntDtlBean.getTxtToAmount()));
        arylstParam.add(new DBObject(6, 1, 12, oHrmLnHblIntDtlBean.getTxtPercentage()));
        arylstParam.add(new DBObject(7, 1, 12, this.oUserInfo.getUserId()));
        arylstParam.add(new DBObject(8, 1, 12, this.oUserInfo.getSiteId()));
        oBean2.addToBatch(arylstParam);
        continue;
      } 
      if (oHrmLnHblIntDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMLNAPPL.procdeleteLoanIntRate(?)");
          bDelete = true;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, oHrmLnHblIntDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParam);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean2.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParam = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sEligAmount = calculateEligibleAmount((HrmLnAppHdrBean)oBaseHeaderBean);
    HrmLnAppHdrBean oHrmLnAppHdrBean = (HrmLnAppHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      arylstParam = new ArrayList();
      arylstParam.add(new DBObject(1, 1, 12, "i"));
      arylstParam.add(new DBObject(2, 1, 12, oHrmLnAppHdrBean.getEmpId()));
      arylstParam.add(new DBObject(3, 1, 12, oHrmLnAppHdrBean.getLoanCodeId()));
      arylstParam.add(new DBObject(4, 1, 12, sEligAmount));
      arylstParam.add(new DBObject(5, 1, 12, oHrmLnAppHdrBean.getAppliedAmount()));
      arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getApplnDate())));
      arylstParam.add(new DBObject(7, 1, 12, oHrmLnAppHdrBean.getLoanDetails()));
      arylstParam.add(new DBObject(8, 1, 12, String.valueOf(oHrmLnAppHdrBean.getFullyRepaid()).equalsIgnoreCase("on") ? "Y" : "N"));
      arylstParam.add(new DBObject(9, 1, 12, oHrmLnAppHdrBean.getSanctionedAmount()));
      arylstParam.add(new DBObject(10, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getSanctionDate())));
      arylstParam.add(new DBObject(11, 1, 12, oHrmLnAppHdrBean.getPayrollMonth()));
      arylstParam.add(new DBObject(12, 1, 12, oHrmLnAppHdrBean.getTotalInst()));
      arylstParam.add(new DBObject(13, 1, 12, oHrmLnAppHdrBean.getTotalPrincipalInst()));
      arylstParam.add(new DBObject(14, 1, 12, oHrmLnAppHdrBean.getTotalInterestInst()));
      arylstParam.add(new DBObject(15, 1, 12, oHrmLnAppHdrBean.getInstAmount()));
      arylstParam.add(new DBObject(16, 1, 12, oHrmLnAppHdrBean.getApproverNoId()));
      arylstParam.add(new DBObject(17, 1, 12, oHrmLnAppHdrBean.getRemarks()));
      arylstParam.add(new DBObject(18, 1, 12, oHrmLnAppHdrBean.getHblAppliedFor()));
      arylstParam.add(new DBObject(19, 1, 12, oHrmLnAppHdrBean.getHblBookNo()));
      arylstParam.add(new DBObject(20, 1, 12, oHrmLnAppHdrBean.getHblBranhConst()));
      arylstParam.add(new DBObject(21, 1, 12, oHrmLnAppHdrBean.getHblCity()));
      arylstParam.add(new DBObject(22, 1, 12, oHrmLnAppHdrBean.getHblDag()));
      arylstParam.add(new DBObject(23, 1, 12, oHrmLnAppHdrBean.getHblDistrict()));
      arylstParam.add(new DBObject(24, 1, 12, String.valueOf(oHrmLnAppHdrBean.getHblDocSubmitted()).equalsIgnoreCase("on") ? "Y" : "N"));
      arylstParam.add(new DBObject(25, 1, 12, oHrmLnAppHdrBean.getHblKhatian()));
      arylstParam.add(new DBObject(26, 1, 12, oHrmLnAppHdrBean.getHblMouza()));
      arylstParam.add(new DBObject(27, 1, 12, oHrmLnAppHdrBean.getHblNoOfDeed()));
      arylstParam.add(new DBObject(28, 1, 12, oHrmLnAppHdrBean.getHblPageNo()));
      arylstParam.add(new DBObject(29, 1, 12, oHrmLnAppHdrBean.getHblParentDeed()));
      arylstParam.add(new DBObject(30, 1, 12, oHrmLnAppHdrBean.getHblPO()));
      arylstParam.add(new DBObject(31, 1, 12, oHrmLnAppHdrBean.getHblRegisteredAt()));
      arylstParam.add(new DBObject(32, 1, 12, oHrmLnAppHdrBean.getHblVolOfDeed()));
      arylstParam.add(new DBObject(33, 1, 12, null));
      arylstParam.add(new DBObject(34, 1, 12, null));
      arylstParam.add(new DBObject(35, 1, 12, null));
      arylstParam.add(new DBObject(36, 1, 12, null));
      arylstParam.add(new DBObject(37, 1, 12, null));
      arylstParam.add(new DBObject(38, 1, 12, null));
      arylstParam.add(new DBObject(39, 1, 12, null));
      arylstParam.add(new DBObject(40, 1, 12, null));
      arylstParam.add(new DBObject(41, 1, 93, null));
      arylstParam.add(new DBObject(42, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParam.add(new DBObject(43, 1, 12, this.oUserInfo.getSiteId()));
      arylstParam.add(new DBObject(44, 1, 12, null));
      arylstParam.add(new DBObject(45, 2, 12));
      arylstParam.add(new DBObject(46, 2, 12));
      arylstParam.add(new DBObject(47, 2, 12));
      arylstParam.add(new DBObject(48, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLNAPPL.procUpsertHrmLnAppHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      String sFullyRepaid = new String();
      if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getBulkAmount())) {
        oHrmLnAppHdrBean.setBulkFlag("N");
        if (EnrgiseUtil.checkString(oHrmLnAppHdrBean.getTotalBalance()))
          if (Float.parseFloat(oHrmLnAppHdrBean.getTotalBalance()) == 0.0D) {
            sFullyRepaid = "Y";
          } else {
            sFullyRepaid = "N";
          }  
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "u"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmLnAppHdrBean.getEmpId()));
        arylstParam.add(new DBObject(3, 1, 12, oHrmLnAppHdrBean.getLoanCodeId()));
        arylstParam.add(new DBObject(4, 1, 12, sEligAmount));
        arylstParam.add(new DBObject(5, 1, 12, oHrmLnAppHdrBean.getAppliedAmount()));
        arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getApplnDate())));
        arylstParam.add(new DBObject(7, 1, 12, oHrmLnAppHdrBean.getLoanDetails()));
        arylstParam.add(new DBObject(8, 1, 12, sFullyRepaid));
        arylstParam.add(new DBObject(9, 1, 12, oHrmLnAppHdrBean.getSanctionedAmount()));
        arylstParam.add(new DBObject(10, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getSanctionDate())));
        arylstParam.add(new DBObject(11, 1, 12, oHrmLnAppHdrBean.getPayrollMonth()));
        arylstParam.add(new DBObject(12, 1, 12, oHrmLnAppHdrBean.getTotalInst()));
        arylstParam.add(new DBObject(13, 1, 12, oHrmLnAppHdrBean.getTotalPrincipalInst()));
        arylstParam.add(new DBObject(14, 1, 12, oHrmLnAppHdrBean.getTotalInterestInst()));
        arylstParam.add(new DBObject(15, 1, 12, oHrmLnAppHdrBean.getInstAmount()));
        arylstParam.add(new DBObject(16, 1, 12, oHrmLnAppHdrBean.getApproverNoId()));
        arylstParam.add(new DBObject(17, 1, 12, oHrmLnAppHdrBean.getRemarks()));
        arylstParam.add(new DBObject(18, 1, 12, oHrmLnAppHdrBean.getHblAppliedFor()));
        arylstParam.add(new DBObject(19, 1, 12, oHrmLnAppHdrBean.getHblBookNo()));
        arylstParam.add(new DBObject(20, 1, 12, oHrmLnAppHdrBean.getHblBranhConst()));
        arylstParam.add(new DBObject(21, 1, 12, oHrmLnAppHdrBean.getHblCity()));
        arylstParam.add(new DBObject(22, 1, 12, oHrmLnAppHdrBean.getHblDag()));
        arylstParam.add(new DBObject(23, 1, 12, oHrmLnAppHdrBean.getHblDistrict()));
        arylstParam.add(new DBObject(24, 1, 12, String.valueOf(oHrmLnAppHdrBean.getHblDocSubmitted()).equalsIgnoreCase("on") ? "Y" : "N"));
        arylstParam.add(new DBObject(25, 1, 12, oHrmLnAppHdrBean.getHblKhatian()));
        arylstParam.add(new DBObject(26, 1, 12, oHrmLnAppHdrBean.getHblMouza()));
        arylstParam.add(new DBObject(27, 1, 12, oHrmLnAppHdrBean.getHblNoOfDeed()));
        arylstParam.add(new DBObject(28, 1, 12, oHrmLnAppHdrBean.getHblPageNo()));
        arylstParam.add(new DBObject(29, 1, 12, oHrmLnAppHdrBean.getHblParentDeed()));
        arylstParam.add(new DBObject(30, 1, 12, oHrmLnAppHdrBean.getHblPO()));
        arylstParam.add(new DBObject(31, 1, 12, oHrmLnAppHdrBean.getHblRegisteredAt()));
        arylstParam.add(new DBObject(32, 1, 12, oHrmLnAppHdrBean.getHblVolOfDeed()));
        arylstParam.add(new DBObject(33, 1, 12, oHrmLnAppHdrBean.getTotalAmountPaid()));
        arylstParam.add(new DBObject(34, 1, 12, oHrmLnAppHdrBean.getPrincipalPaid()));
        arylstParam.add(new DBObject(35, 1, 12, oHrmLnAppHdrBean.getTotalBalance()));
        arylstParam.add(new DBObject(36, 1, 12, oHrmLnAppHdrBean.getPrincipalBalance()));
        arylstParam.add(new DBObject(37, 1, 12, oHrmLnAppHdrBean.getInterestBalance()));
        arylstParam.add(new DBObject(38, 1, 12, oHrmLnAppHdrBean.getInterestPaid()));
        arylstParam.add(new DBObject(39, 1, 12, null));
        arylstParam.add(new DBObject(40, 1, 12, oHrmLnAppHdrBean.getBulkFlag()));
        arylstParam.add(new DBObject(41, 1, 93, null));
        arylstParam.add(new DBObject(42, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParam.add(new DBObject(43, 1, 12, this.oUserInfo.getSiteId()));
        arylstParam.add(new DBObject(44, 1, 12, oHrmLnAppHdrBean.getHeaderPrimaryKey()));
        arylstParam.add(new DBObject(45, 2, 12));
        arylstParam.add(new DBObject(46, 2, 12));
        arylstParam.add(new DBObject(47, 2, 12));
        arylstParam.add(new DBObject(48, 2, 4));
        ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLNAPPL.procUpsertHrmLnAppHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        DBObject oOutObject = arylstOutArray.get(0);
        returnString = (String)oOutObject.getObject();
        System.out.println(returnString);
      } else if (EnrgiseUtil.checkString(oHrmLnAppHdrBean.getBulkAmount())) {
        oHrmLnAppHdrBean.setBulkFlag("Y");
        if (Double.parseDouble(oHrmLnAppHdrBean.getTotalBalance()) == Double.parseDouble(oHrmLnAppHdrBean.getBulkAmount())) {
          sFullyRepaid = "Y";
        } else {
          sFullyRepaid = "N";
        } 
        double iTotalPaid = 0.0D;
        double iPrincipalPaid = 0.0D;
        double iTotalBalance = 0.0D;
        double iPrincipalBalance = 0.0D;
        double iIntBalance = 0.0D;
        double iInterestPaid = 0.0D;
        double bulk = Double.parseDouble(oHrmLnAppHdrBean.getBulkAmount());
        if (bulk < Float.parseFloat(oHrmLnAppHdrBean.getPrincipalBalance())) {
          iTotalPaid = Float.parseFloat(oHrmLnAppHdrBean.getTotalAmountPaid()) + bulk;
          iPrincipalPaid = Float.parseFloat(oHrmLnAppHdrBean.getPrincipalPaid()) + bulk;
          iTotalBalance = Float.parseFloat(oHrmLnAppHdrBean.getTotalBalance()) - bulk;
          iPrincipalBalance = Float.parseFloat(oHrmLnAppHdrBean.getPrincipalBalance()) - bulk;
          iIntBalance = Float.parseFloat(oHrmLnAppHdrBean.getInterestBalance());
          iInterestPaid = Float.parseFloat(oHrmLnAppHdrBean.getInterestPaid());
        } else if (bulk >= Float.parseFloat(oHrmLnAppHdrBean.getPrincipalBalance())) {
          iTotalPaid = Float.parseFloat(oHrmLnAppHdrBean.getTotalAmountPaid()) + bulk;
          iPrincipalPaid = (Float.parseFloat(oHrmLnAppHdrBean.getPrincipalPaid()) + Float.parseFloat(oHrmLnAppHdrBean.getPrincipalBalance()));
          iTotalBalance = Float.parseFloat(oHrmLnAppHdrBean.getTotalBalance()) - bulk;
          iPrincipalBalance = 0.0D;
          iIntBalance = iTotalBalance;
          iInterestPaid = iTotalPaid - iPrincipalPaid;
        } 
        arylstParam = new ArrayList();
        arylstParam.add(new DBObject(1, 1, 12, "u"));
        arylstParam.add(new DBObject(2, 1, 12, oHrmLnAppHdrBean.getEmpId()));
        arylstParam.add(new DBObject(3, 1, 12, oHrmLnAppHdrBean.getLoanCodeId()));
        arylstParam.add(new DBObject(4, 1, 12, sEligAmount));
        arylstParam.add(new DBObject(5, 1, 12, oHrmLnAppHdrBean.getAppliedAmount()));
        arylstParam.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getApplnDate())));
        arylstParam.add(new DBObject(7, 1, 12, oHrmLnAppHdrBean.getLoanDetails()));
        arylstParam.add(new DBObject(8, 1, 12, sFullyRepaid));
        arylstParam.add(new DBObject(9, 1, 12, oHrmLnAppHdrBean.getSanctionedAmount()));
        arylstParam.add(new DBObject(10, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getSanctionDate())));
        arylstParam.add(new DBObject(11, 1, 12, oHrmLnAppHdrBean.getPayrollMonth()));
        arylstParam.add(new DBObject(12, 1, 12, oHrmLnAppHdrBean.getTotalInst()));
        arylstParam.add(new DBObject(13, 1, 12, oHrmLnAppHdrBean.getTotalPrincipalInst()));
        arylstParam.add(new DBObject(14, 1, 12, oHrmLnAppHdrBean.getTotalInterestInst()));
        arylstParam.add(new DBObject(15, 1, 12, oHrmLnAppHdrBean.getInstAmount()));
        arylstParam.add(new DBObject(16, 1, 12, oHrmLnAppHdrBean.getApproverNoId()));
        arylstParam.add(new DBObject(17, 1, 12, oHrmLnAppHdrBean.getRemarks()));
        arylstParam.add(new DBObject(18, 1, 12, oHrmLnAppHdrBean.getHblAppliedFor()));
        arylstParam.add(new DBObject(19, 1, 12, oHrmLnAppHdrBean.getHblBookNo()));
        arylstParam.add(new DBObject(20, 1, 12, oHrmLnAppHdrBean.getHblBranhConst()));
        arylstParam.add(new DBObject(21, 1, 12, oHrmLnAppHdrBean.getHblCity()));
        arylstParam.add(new DBObject(22, 1, 12, oHrmLnAppHdrBean.getHblDag()));
        arylstParam.add(new DBObject(23, 1, 12, oHrmLnAppHdrBean.getHblDistrict()));
        arylstParam.add(new DBObject(24, 1, 12, String.valueOf(oHrmLnAppHdrBean.getHblDocSubmitted()).equalsIgnoreCase("on") ? "Y" : "N"));
        arylstParam.add(new DBObject(25, 1, 12, oHrmLnAppHdrBean.getHblKhatian()));
        arylstParam.add(new DBObject(26, 1, 12, oHrmLnAppHdrBean.getHblMouza()));
        arylstParam.add(new DBObject(27, 1, 12, oHrmLnAppHdrBean.getHblNoOfDeed()));
        arylstParam.add(new DBObject(28, 1, 12, oHrmLnAppHdrBean.getHblPageNo()));
        arylstParam.add(new DBObject(29, 1, 12, oHrmLnAppHdrBean.getHblParentDeed()));
        arylstParam.add(new DBObject(30, 1, 12, oHrmLnAppHdrBean.getHblPO()));
        arylstParam.add(new DBObject(31, 1, 12, oHrmLnAppHdrBean.getHblRegisteredAt()));
        arylstParam.add(new DBObject(32, 1, 12, oHrmLnAppHdrBean.getHblVolOfDeed()));
        arylstParam.add(new DBObject(33, 1, 12, String.valueOf(iTotalPaid)));
        arylstParam.add(new DBObject(34, 1, 12, String.valueOf(iPrincipalPaid)));
        arylstParam.add(new DBObject(35, 1, 12, String.valueOf(iTotalBalance)));
        arylstParam.add(new DBObject(36, 1, 12, String.valueOf(iPrincipalBalance)));
        arylstParam.add(new DBObject(37, 1, 12, String.valueOf(iIntBalance)));
        arylstParam.add(new DBObject(38, 1, 12, String.valueOf(iInterestPaid)));
        arylstParam.add(new DBObject(39, 1, 12, String.valueOf(bulk)));
        arylstParam.add(new DBObject(40, 1, 12, oHrmLnAppHdrBean.getBulkFlag()));
        arylstParam.add(new DBObject(41, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getBulkPaymentDate())));
        arylstParam.add(new DBObject(42, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParam.add(new DBObject(43, 1, 12, this.oUserInfo.getSiteId()));
        arylstParam.add(new DBObject(44, 1, 12, oHrmLnAppHdrBean.getHeaderPrimaryKey()));
        arylstParam.add(new DBObject(45, 2, 12));
        arylstParam.add(new DBObject(46, 2, 12));
        arylstParam.add(new DBObject(47, 2, 12));
        arylstParam.add(new DBObject(48, 2, 4));
        ArrayList arylstOutArray = oBean.callProc(arylstParam, "HRMLNAPPL.procUpsertHrmLnAppHdr(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        DBObject oOutObject = arylstOutArray.get(0);
        returnString = (String)oOutObject.getObject();
        System.out.println(returnString);
      } 
    } 
    return returnString;
  }
  
  private String calculateEligibleAmount(HrmLnAppHdrBean oHrmLnAppHdrBean) throws EnrgiseSystemException {
    ArrayList oList = new ArrayList();
    int count = 0;
    ArrayList oParameters = new ArrayList();
    ArrayList oOutArray = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    QueryRow oRow = null;
    String sEligAmount = new String();
    String sGrLsFlag = new String();
    String sFlatAmt = new String();
    String sMaxLnPerc = new String();
    String sNoOfMnthSal = new String();
    String sPeriodLeft = new String();
    String sPeriodCompleted = new String();
    String sSalary = new String();
    String sBasic = new String();
    int count1 = 0;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmLnAppHdrBean.getLoanCodeId()));
    oParameters.add(new DBObject(2, 1, 12, oHrmLnAppHdrBean.getEmpId()));
    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, "HRMLNAPPL.procCalculateEligibleAmount(?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)oOutArray.get(0)).getObject();
    count1 = 0;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      count1++;
      oRow = oIt.next();
      sGrLsFlag = oRow.get("GREATER_LESSER_FLAG").getString();
      sFlatAmt = oRow.get("FLAT_AMOUNT").getString();
      sMaxLnPerc = oRow.get("MAX_LOAN_PERC").getString();
      sNoOfMnthSal = oRow.get("NO_OF_MTHS_SALARY").getString();
      sPeriodLeft = oRow.get("MIN_YR_SERVICE_LEFT").getString();
      sPeriodCompleted = oRow.get("MIN_YEAR_IN_SERVICE").getString();
      sBasic = oRow.get("BASIC").getString();
    } 
    if (String.valueOf(oRow.get("GREATER_LESSER_FLAG").getString()).equalsIgnoreCase("G")) {
      sSalary = String.valueOf(Float.parseFloat(sNoOfMnthSal) * Float.parseFloat(sBasic) * Float.parseFloat(sMaxLnPerc) / 100);
      if (Float.parseFloat(sSalary) - Float.parseFloat(sFlatAmt) > false) {
        sEligAmount = String.valueOf(sSalary);
      } else if (Float.parseFloat(sFlatAmt) - Float.parseFloat(sSalary) > false) {
        sEligAmount = String.valueOf(sFlatAmt);
      } else {
        sEligAmount = String.valueOf(sFlatAmt);
      } 
    } 
    if (String.valueOf(oRow.get("GREATER_LESSER_FLAG").getString()).equalsIgnoreCase("L")) {
      sSalary = String.valueOf(Float.parseFloat(sNoOfMnthSal) * Float.parseFloat(sBasic) * Float.parseFloat(sMaxLnPerc) / 100);
      if (Float.parseFloat(sSalary) - Float.parseFloat(sFlatAmt) > false) {
        sEligAmount = String.valueOf(sFlatAmt);
      } else if (Float.parseFloat(sFlatAmt) - Float.parseFloat(sSalary) > false) {
        sEligAmount = String.valueOf(sSalary);
      } else {
        sEligAmount = String.valueOf(sFlatAmt);
      } 
    } 
    if (String.valueOf(oRow.get("GREATER_LESSER_FLAG").getString()).equalsIgnoreCase("F"))
      sEligAmount = sFlatAmt; 
    if (String.valueOf(oRow.get("GREATER_LESSER_FLAG").getString()).equalsIgnoreCase("S"))
      sEligAmount = String.valueOf(Float.parseFloat(sNoOfMnthSal) * Float.parseFloat(sBasic) * Float.parseFloat(sMaxLnPerc) / 100); 
    return sEligAmount;
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    System.out.println("To Be Done");
  }
  
  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 void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    HrmLnAppHdrBean oHrmLnAppHdrBean = (HrmLnAppHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmLnAppHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D")) {
        if (sScreenName.equalsIgnoreCase("HrmLnApp"))
          if (arylstDetailBeanArray.size() != 0) {
            Iterator itrBean1 = arylstDetailBeanArray.iterator();
            int rowCount = 1;
            while (itrBean1.hasNext()) {
              HrmLnDisDtlBean oHrmLnDisDtlBean = itrBean1.next();
              if (!oHrmLnDisDtlBean.getStatus().equalsIgnoreCase("D"))
                checkMandatoryDisDtl(oHrmLnDisDtlBean, rowCount); 
            } 
            rowCount++;
          }  
        if (sScreenName.equalsIgnoreCase("HrmLnDisDtl"))
          if (arylstDetailBeanArray.size() != 0) {
            Iterator itrBean1 = arylstDetailBeanArray.iterator();
            int rowCount = 0;
            while (itrBean1.hasNext()) {
              HrmLnDisDtlBean oHrmLnDisDtlBean = itrBean1.next();
              if (!oHrmLnDisDtlBean.getStatus().equalsIgnoreCase("D"))
                checkMandatoryDisDtl(oHrmLnDisDtlBean, rowCount); 
            } 
            rowCount++;
          }  
        if (sScreenName.equalsIgnoreCase("HrmLnAppHblIntRate"))
          if (arylstDetailBeanArray.size() != 0) {
            Iterator itrBean1 = arylstDetailBeanArray.iterator();
            int rowCount = 0;
            while (itrBean1.hasNext()) {
              HrmLnHblIntDtlBean oHrmLnHblIntDtlBean = itrBean1.next();
              if (!oHrmLnHblIntDtlBean.getStatus().equalsIgnoreCase("D")) {
                checkMandatoryHblIntDtl(oHrmLnHblIntDtlBean, rowCount);
                checkNumericFields(oHrmLnHblIntDtlBean, rowCount);
              } 
              rowCount++;
            } 
          }  
      }  
  }
  
  private void checkMandatoryHeader(HrmLnAppHdrBean oHrmLnAppHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oParams = new ArrayList();
    ArrayList oErrorList = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getEmployeeNumber())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.employeeNumber");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getLoanCode())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.loanCode");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.header.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getAppliedAmount())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.appliedAmount");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getApplnDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.applnDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getSanctionedAmount())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.sanctionedAmount");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getSanctionDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.sanctionDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getTotalInst())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.noOfInstallment");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getTotalInterestInst())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.totalInterestInst");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getTotalPrincipalInst())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.totalPrincipalInst");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getInstAmount())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.instAmount");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (EnrgiseUtil.checkString(oHrmLnAppHdrBean.getMode()))
      if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getBulkAmount())) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppln.bulkAmount");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.onlyDetail.mandatoryFieldMissing", oParams, "E"));
      }  
    reportError(oErrorList);
  }
  
  private void checkMandatoryDisDtl(HrmLnDisDtlBean oHrmLnDisDtlBean, int rowCount) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    rowCount++;
    if (!EnrgiseUtil.checkString(oHrmLnDisDtlBean.getActDisAmt())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppDisbur.actDisAmt");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnDisDtlBean.getActDisDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppDisbur.actDisDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  private void checkMandatoryHblIntDtl(HrmLnHblIntDtlBean oHrmLnHblIntDtlBean, int rowCount) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    rowCount++;
    if (!EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtFromAmount())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppHblIntRate.fromAmount");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtToAmount())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppHblIntRate.toAmount");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtPercentage())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppHblIntRate.percentage");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  private void checkNumericFields(HrmLnHblIntDtlBean oHrmLnHblIntDtlBean, int rowCount) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    rowCount++;
    if (EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtFromAmount()))
      if (!EnrgiseUtil.checkNumber(oHrmLnHblIntDtlBean.getTxtFromAmount(), 15, 2, "P")) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppHblIntRate.fromAmount");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(String.valueOf(rowCount));
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.invalidNumber", oParams, "E"));
      }  
    if (EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtToAmount()))
      if (!EnrgiseUtil.checkNumber(oHrmLnHblIntDtlBean.getTxtFromAmount(), 15, 2, "P")) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppHblIntRate.toAmount");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(String.valueOf(rowCount));
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.invalidNumber", oParams, "E"));
      }  
    if (EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtPercentage()))
      if (!EnrgiseUtil.checkNumber(oHrmLnHblIntDtlBean.getTxtFromAmount(), 15, 2, "P")) {
        MessageKey oMessageKey = new MessageKey("hrm.HrmEmpLoanAppHblIntRate.percentage");
        oParams = new ArrayList();
        oParams.add(oMessageKey);
        oParams.add(String.valueOf(rowCount));
        oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.invalidNumber", oParams, "E"));
      }  
    reportError(oErrorList);
  }
  
  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();
    HrmLnAppHdrBean oHrmLnAppHdrBean = (HrmLnAppHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D")) {
        if (!sScreenMode.equalsIgnoreCase("U"))
          if (EnrgiseUtil.checkString(oHrmLnAppHdrBean.getPayrollMonth()))
            checkRecoveryYearMonth((HrmLnAppHdrBean)oBaseHeaderBean, sScreenMode);  
        if (EnrgiseUtil.checkString(oHrmLnAppHdrBean.getBulkAmount()))
          checkBulkAmount((HrmLnAppHdrBean)oBaseHeaderBean); 
        checkNoOfInstallment((HrmLnAppHdrBean)oBaseHeaderBean);
        checkServicePeriod((HrmLnAppHdrBean)oBaseHeaderBean);
      }  
    if (bDetailDataChanged) {
      if (sScreenName.equalsIgnoreCase("HrmLnApp")) {
        if (oHrmLnAppHdrBean.getLoanCode().equalsIgnoreCase("99")) {
          String sQuery = String.valueOf("Select id from hrm_loan_int_rate m where m.emp_loan_id = ").concat(String.valueOf(oHrmLnAppHdrBean.getHeaderPrimaryKey()));
          DBUtilitiesBean oBean = new DBUtilitiesBean();
          ArrayList arylstList = oBean.executeQuery(sQuery);
          if (arylstList.size() == 0) {
            ArrayList arylstParam = new ArrayList();
            arylstParam.add("");
            arylstParam.add(new Integer(0));
            arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.DisbSaveError", arylstParam));
          } 
        } 
        Iterator itrBean1 = arylstDetailBeanArray.iterator();
        int rowCount = 1;
        while (itrBean1.hasNext()) {
          HrmLnDisDtlBean oHrmLnDisDtlBean = itrBean1.next();
          if (!oHrmLnDisDtlBean.getStatus().equals("D")) {
            compareLoanAmount(oHrmLnAppHdrBean, arylstDetailBeanArray);
            checkDatesConstraint(oHrmLnAppHdrBean, arylstDetailBeanArray, arylstErrorList);
          } 
          if (oHrmLnDisDtlBean.getStatus().equals("D"))
            checkPayrollFlag(oHrmLnAppHdrBean, arylstDetailBeanArray, arylstErrorList); 
        } 
        rowCount++;
      } 
      if (sScreenName.equalsIgnoreCase("HrmLnAppHblIntRate")) {
        Iterator itrBean2 = arylstDetailBeanArray.iterator();
        int rowCount = 1;
        while (itrBean2.hasNext()) {
          HrmLnHblIntDtlBean oHrmLnHblIntDtlBean = itrBean2.next();
          if (!oHrmLnHblIntDtlBean.getStatus().equals("D")) {
            checkFromNToAmount(oHrmLnHblIntDtlBean, rowCount, arylstErrorList);
            checkPercentage(oHrmLnHblIntDtlBean, rowCount, arylstErrorList);
          } 
          rowCount++;
        } 
      } 
    } 
    reportError(arylstErrorList);
  }
  
  private void checkFromNToAmount(HrmLnHblIntDtlBean oHrmLnHblIntDtlBean, int rowCount, ArrayList arylstErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParams = new ArrayList();
    if (EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtFromAmount()))
      if (EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtToAmount()))
        if (Long.parseLong(oHrmLnHblIntDtlBean.getTxtFromAmount()) > Long.parseLong(oHrmLnHblIntDtlBean.getTxtToAmount())) {
          oParams = new ArrayList();
          oParams.add(String.valueOf(rowCount));
          arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppHblIntRate.AmountError", oParams, "E"));
        }   
  }
  
  private void checkPercentage(HrmLnHblIntDtlBean oHrmLnHblIntDtlBean, int rowCount, ArrayList arylstErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oParams = new ArrayList();
    if (EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtFromAmount()))
      if (EnrgiseUtil.checkString(oHrmLnHblIntDtlBean.getTxtToAmount()))
        if (Double.parseDouble(oHrmLnHblIntDtlBean.getTxtPercentage()) >= 100) {
          oParams = new ArrayList();
          oParams.add(String.valueOf(rowCount));
          arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppHblIntRate.PercentError", oParams, "E"));
        }   
  }
  
  private void checkPayrollFlag(HrmLnAppHdrBean oHrmLnAppHdrBean, ArrayList arylstDetailBeanArray, ArrayList arylstErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    int count = 0;
    Iterator itrBean1 = arylstDetailBeanArray.iterator();
    while (itrBean1.hasNext()) {
      HrmLnDisDtlBean oHrmLnDisDtlBean = itrBean1.next();
      String sQuery = String.valueOf(" Select ID as ID from HRM_LOAN_DISB_DTL where PAYROLL_YYYYMM is null and ID=").concat(String.valueOf(oHrmLnDisDtlBean.getDetailId()));
      System.out.println(sQuery);
      DBUtilitiesBean oBean = new DBUtilitiesBean();
      ArrayList arylstList = oBean.executeQuery(sQuery);
      if (arylstList.size() == 0) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppDisbur.deleteNotPossible", arylstParam));
      } 
      reportError(arylstErrorList);
    } 
  }
  
  private void checkDatesConstraint(HrmLnAppHdrBean oHrmLnAppHdrBean, ArrayList arylstDetailBeanArray, ArrayList arylstErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    int n = arylstDetailBeanArray.size();
    HrmLnDisDtlBean oHrmLnDisDtlBean = arylstDetailBeanArray.get(n - 1);
    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    if (EnrgiseUtil.checkString(oHrmLnDisDtlBean.getActDisDate())) {
      int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmLnDisDtlBean.getActDisDate(), oHrmLnAppHdrBean.getSanctionDate());
      if (dateFlag == -1 && dateFlag != -2)
        if (arylstErrorList.isEmpty()) {
          arylstParam = new ArrayList();
          arylstParam.add("");
          arylstParam.add(new Integer(0));
          arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppDisbur.disDateValidation", arylstParam));
        }  
    } 
  }
  
  private void checkNoOfInstallment(HrmLnAppHdrBean oHrmLnAppHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    ArrayList arylstErrorList = new ArrayList();
    String sNoOfInstallments = new String();
    String sPrincipalInstallments = new String();
    String sInterestInstallments = new String();
    String sNoOfMonths = new String();
    ArrayList oParameters = new ArrayList();
    ArrayList oOutArray = new ArrayList();
    ArrayList oList = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    QueryRow oRow = null;
    int count1 = 0;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmLnAppHdrBean.getEmpId()));
    oParameters.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getApplnDate())));
    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, "HRMLNAPPL.procGetMonthsRemaining(?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)oOutArray.get(0)).getObject();
    count1 = 0;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      count1++;
      oRow = oIt.next();
      sNoOfMonths = oRow.get("NO_OF_MONTHS").getString();
    } 
    sNoOfInstallments = oHrmLnAppHdrBean.getTotalInst();
    sPrincipalInstallments = oHrmLnAppHdrBean.getTotalInterestInst();
    sInterestInstallments = oHrmLnAppHdrBean.getTotalPrincipalInst();
    if (Float.parseFloat(sNoOfInstallments) > Float.parseFloat(sPrincipalInstallments) + Float.parseFloat(sInterestInstallments) || Float.parseFloat(sNoOfInstallments) < Float.parseFloat(sPrincipalInstallments) + Float.parseFloat(sInterestInstallments)) {
      arylstParam = new ArrayList();
      arylstParam.add("Loan Application: No Of Installment");
      arylstParam.add(new Integer(0));
      arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkNoOfInst", arylstParam));
    } 
    if (Float.parseFloat(sNoOfInstallments) > Float.parseFloat(sNoOfMonths)) {
      arylstParam = new ArrayList();
      arylstParam.add("Loan Application: No Of Installment");
      arylstParam.add(new Integer(0));
      arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.noOfInstError", arylstParam));
    } 
    reportError(arylstErrorList);
  }
  
  private void checkRecoveryYearMonth(HrmLnAppHdrBean oHrmLnAppHdrBean, String sScreenMode) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    ArrayList arylstErrorList = new ArrayList();
    String sPayrollMonth = new String();
    String sMonth = new String();
    sPayrollMonth = oHrmLnAppHdrBean.getPayrollMonth();
    if (Float.parseFloat(sPayrollMonth.substring(4, 6)) < true || Float.parseFloat(sPayrollMonth.substring(4, 6)) > 12) {
      arylstParam.add("Loan Application: Year Month");
      arylstParam.add(new Integer(0));
      arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkPayrollMonth", arylstParam));
    } 
    if (Float.parseFloat(sPayrollMonth.substring(0, 1)) == false) {
      arylstParam.add("Loan 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, oHrmLnAppHdrBean.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, "hrmlnappl.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(oHrmLnAppHdrBean.getBulkAmount())) {
      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(HrmLnAppHdrBean oHrmLnAppHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    ArrayList arylstErrorList = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmLnAppHdrBean.getTotalBalance())) {
      arylstParam.add("Loan Application: Bulk Amount");
      arylstParam.add(new Integer(0));
      arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkBulk", arylstParam));
    } else {
      if (Double.parseDouble(oHrmLnAppHdrBean.getBulkAmount()) == 0.0D) {
        arylstParam.add("Loan Application: Bulk Amount");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkBulkAmount", arylstParam));
      } 
      if (Double.parseDouble(oHrmLnAppHdrBean.getBulkAmount()) > Double.parseDouble(oHrmLnAppHdrBean.getTotalBalance())) {
        arylstParam.add("Loan Application: Bulk Amount");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.checkBulkAmount1", arylstParam));
      } 
    } 
    reportError(arylstErrorList);
  }
  
  private void checkServicePeriod(HrmLnAppHdrBean oHrmLnAppHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    ArrayList arylstErrorList = new ArrayList();
    String sMinSerPeriod = new String();
    String sRemainingSerPeriod = new String();
    String sNoOfMonthsInService = new String();
    String sNoOfMonthsRemaining = new String();
    ArrayList oParameters = new ArrayList();
    ArrayList oOutArray = new ArrayList();
    ArrayList oList = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    QueryRow oRow = null;
    int count1 = 0;
    oParameters = new ArrayList();
    oParameters.add(new DBObject(1, 1, 12, oHrmLnAppHdrBean.getEmpId()));
    oParameters.add(new DBObject(2, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmLnAppHdrBean.getApplnDate())));
    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, "HRMLNAPPL.procGetServicePeriod(?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)oOutArray.get(0)).getObject();
    count1 = 0;
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      count1++;
      oRow = oIt.next();
      sNoOfMonthsInService = oRow.get("NO_OF_MONTHS").getString();
      sNoOfMonthsRemaining = oRow.get("REMAINING_MONTHS").getString();
    } 
    ArrayList oParameters1 = new ArrayList();
    ArrayList oOutArray1 = new ArrayList();
    ArrayList oList1 = new ArrayList();
    DBUtilitiesBean oBean1 = new DBUtilitiesBean();
    QueryRow oRow1 = null;
    int count2 = 0;
    oParameters1 = new ArrayList();
    oParameters1.add(new DBObject(1, 1, 12, oHrmLnAppHdrBean.getLoanCodeId()));
    oParameters1.add(new DBObject(2, 1, 12, oHrmLnAppHdrBean.getEmpId()));
    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, "HRMLNAPPL.procCalculateEligibleAmount(?,?,?,?,?,?)");
    oList1 = (ArrayList)((DBObject)oOutArray1.get(0)).getObject();
    count2 = 0;
    Iterator oIt1 = oList1.iterator();
    while (oIt1.hasNext()) {
      count2++;
      oRow1 = oIt1.next();
      sMinSerPeriod = oRow1.get("MIN_YEAR_IN_SERVICE").getString();
      sRemainingSerPeriod = oRow1.get("MIN_YR_SERVICE_LEFT").getString();
    } 
    if (EnrgiseUtil.checkString(sMinSerPeriod) && EnrgiseUtil.checkString(sRemainingSerPeriod)) {
      if (Float.parseFloat(sMinSerPeriod) * 12 > Float.parseFloat(sNoOfMonthsInService)) {
        arylstParam = new ArrayList();
        arylstParam.add("Loan Application: Service Period");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.minServicePeriodError", arylstParam));
      } 
      if (Float.parseFloat(sRemainingSerPeriod) * 12 > Float.parseFloat(sNoOfMonthsRemaining)) {
        arylstParam = new ArrayList();
        arylstParam.add("Loan Application: Service Period");
        arylstParam.add(new Integer(0));
        arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.maxServicePeriodError", arylstParam));
      } 
    } 
    reportError(arylstErrorList);
  }
  
  private void compareLoanAmount(HrmLnAppHdrBean oHrmLnAppHdrBean, ArrayList arylstDetailBeanArray) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParam = new ArrayList();
    ArrayList arylstErrorList = new ArrayList();
    int count = 0;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    double totalAmount = 0.0D;
    double amount = 0.0D;
    while (itrBean.hasNext()) {
      HrmLnDisDtlBean oHrmLnDisDtlBean = arylstDetailBeanArray.get(count);
      if (EnrgiseUtil.checkString(oHrmLnDisDtlBean.getActDisAmt()))
        amount = Float.parseFloat(oHrmLnDisDtlBean.getActDisAmt()); 
      totalAmount += amount;
      count++;
      itrBean.next();
    } 
    ArrayList oParameters1 = new ArrayList();
    ArrayList oOutArray1 = new ArrayList();
    ArrayList oList1 = new ArrayList();
    Iterator oIt1 = arylstDetailBeanArray.iterator();
    DBUtilitiesBean oBean1 = new DBUtilitiesBean();
    QueryRow oRow1 = null;
    String sEligAmount = null;
    int count2 = 0;
    oParameters1 = new ArrayList();
    oParameters1.add(new DBObject(1, 1, 12, oHrmLnAppHdrBean.getHeaderPrimaryKey()));
    oParameters1.add(new DBObject(2, 2, -10));
    oParameters1.add(new DBObject(3, 2, 12));
    oParameters1.add(new DBObject(4, 2, 12));
    oParameters1.add(new DBObject(5, 2, 4));
    oOutArray1 = oBean1.callProc(oParameters1, "HRMLNAPPL.procGetLoanAmount(?,?,?,?,?)");
    oList1 = (ArrayList)((DBObject)oOutArray1.get(0)).getObject();
    count2 = 0;
    oIt1 = oList1.iterator();
    while (oIt1.hasNext()) {
      count2++;
      oRow1 = (QueryRow)oIt1.next();
      sEligAmount = oRow1.get("LOAN_AMOUNT").getString();
    } 
    if (totalAmount > Float.parseFloat(sEligAmount)) {
      arylstParam = new ArrayList();
      arylstParam.add("Loan Disbursement: Disbursed Amount");
      arylstParam.add(new Integer(0));
      arylstErrorList.add(new EnrgiseMessageKeyException("hrm.HrmEmpLoanAppln.disDtlTenAmt", arylstParam));
    } 
    reportError(arylstErrorList);
  }
  
  public String submitLnAppln(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    ArrayList arylstList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    HrmLnAppHdrBean oHrmLnAppHdrBean = (HrmLnAppHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    if (!EnrgiseUtil.checkString(oBaseHeaderBean.getWorkListId()))
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", "Initiated"); 
    if (status.getStatus().equalsIgnoreCase("Pending")) {
      String sAppliedAmount = null;
      String sEligAmount = null;
      String sAmount = null;
      oBean = new DBUtilitiesBean();
      arylstParameters = new ArrayList();
      sAppliedAmount = oHrmLnAppHdrBean.getAppliedAmount();
      sEligAmount = oHrmLnAppHdrBean.getEligibleAmount();
      if (Float.parseFloat(sAppliedAmount) >= Float.parseFloat(sEligAmount)) {
        sAmount = sEligAmount;
      } else if (Float.parseFloat(sAppliedAmount) < Float.parseFloat(sEligAmount)) {
        sAmount = sAppliedAmount;
      } 
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 1, 12, sAmount));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 12));
      arylstParameters.add(new DBObject(5, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMLNAPPL.procSubmitLnAppln(?,?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  public String approveLnAppln(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    ArrayList arylstList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    HrmLnAppHdrBean oHrmLnAppHdrBean = (HrmLnAppHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    if (!EnrgiseUtil.checkString(oBaseHeaderBean.getWorkListId())) {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", "Initiated");
    } else {
      status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Approve", (String)null);
    } 
    if (status.getStatus().equalsIgnoreCase("FinallyApproved")) {
      oBean = new DBUtilitiesBean();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMLNAPPL.procApproveLnAppln(?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  public String rejectLnAppln(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    ArrayList arylstList = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    HrmLnAppHdrBean oHrmLnAppHdrBean = (HrmLnAppHdrBean)oBaseHeaderBean;
    String sHeaderPrimaryKey = (null != oBaseHeaderBean) ? oBaseHeaderBean.getHeaderPrimaryKey() : "";
    WflStatus status = null;
    status = callWorkFlow(oBaseHeaderBean, arylstDetailBeanArray, "Reject", (String)null);
    if (status.getStatus().equalsIgnoreCase("Rejected")) {
      oBean = new DBUtilitiesBean();
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, sHeaderPrimaryKey));
      arylstParameters.add(new DBObject(2, 2, 12));
      arylstParameters.add(new DBObject(3, 2, 12));
      arylstParameters.add(new DBObject(4, 2, 4));
      ArrayList arrayList = oBean.callProc(arylstParameters, "HRMLNAPPL.procRejectLnAppln(?,?,?,?)");
    } 
    return sHeaderPrimaryKey;
  }
  
  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();
      HrmLnAppHdrBean oHrmLnAppHdrBean = (HrmLnAppHdrBean)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(oHrmLnAppHdrBean.getHeaderPrimaryKey());
      wflDocumentInfoImpl.setDocumentType("Loan");
      wflDocumentInfoImpl.setInitiatedFlag(initiatedFlag);
      String documentTypeId = workFlowFacade.getDocumentTypeId("LoanAppln");
      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("Loan Application No:").concat(String.valueOf(oHrmLnAppHdrBean.getHeaderPrimaryKey()))).concat(String.valueOf("is pending for approval")));
        wflDocumentInfoImpl.setDocDesc(String.valueOf("The following document has been pending for approval:Loan Application No:").concat(String.valueOf(oHrmLnAppHdrBean.getHeaderPrimaryKey())));
      } else if (!activity.equalsIgnoreCase("Approve")) {
        wflDocumentInfoImpl.setDocumentNumber(String.valueOf(String.valueOf("Loan Application No:").concat(String.valueOf(oHrmLnAppHdrBean.getHeaderPrimaryKey()))).concat(String.valueOf("is pending for rejection")));
        wflDocumentInfoImpl.setDocDesc(String.valueOf("The following document has been pending for rejection:Loan Application No:").concat(String.valueOf(oHrmLnAppHdrBean.getHeaderPrimaryKey())));
      } 
      wflDocumentInfoImpl.setModuleId("8");
      wflDocumentInfoImpl.setCreator((WflResource)wflResourceImpl);
      wflDocumentInfoImpl.setRequesterAction(activityId);
      String sLoanAmt = oHrmLnAppHdrBean.getAppliedAmount();
      HashMap oProp = new HashMap();
      oProp.put("Loan_Amt", sLoanAmt);
      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);
    } 
  }
}
