/**
   * This method queries the database to get the Invoice Number associated with the passes Invid
   *
   * @exception SQLException, if query fails
   * @author
   */
  public long getInvID(String inv_no) {
    String query;
    long invID = 0;
    Statement stmt = null;
    ResultSet rs = null;

    query = "select inv_id from inv where inv_no=" + inv_no;

    try {
      stmt = conn.createStatement();
      rs = stmt.executeQuery(query);
      if (rs.next()) {
        invID = rs.getLong(1);
      }
      if (rs != null) rs.close();
      if (stmt != null) stmt.close();
    } catch (SQLException ex) {
      USFEnv.getLog().writeCrit("Dinvview: The Invoice ID not retreived", this, ex);
      try {
        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
      } catch (SQLException e) {
        USFEnv.getLog().writeCrit("Unable to close the resultset/statement", this, e);
      }
    }

    return (invID);
  }
  /**
   * Method to build a vector from a ResultSet
   *
   * @param <code>ResultSet rsResult</code> the result from a query
   * @return Vector of objects from the ResultSet
   * @exception Throws Exception on error
   */
  protected Vector buildObjectVector(ResultSet rsResult) throws Exception {
    // vector for return data
    Vector vReturn = null;

    try {
      // init the vector
      vReturn = new Vector(super.VECT_INIT_SIZE, super.VECT_GROW_SIZE);

      // loop through the entire result set
      while (rsResult.next()) {
        // create a new one
        StageUsacForm objTmp = new StageUsacForm();

        // set the attributes
        // ADDING A NEW FIELD "ROWID"
        objTmp.ROWID = rsResult.getString("ROWID");

        objTmp.HDR_SPIN = rsResult.getLong("HDR_SPIN");
        objTmp.SPIN_NM = rsResult.getString("SPIN_NM");
        objTmp.RCPNT_EMAIL = rsResult.getString("RCPNT_EMAIL");
        objTmp.USAC_EMAIL = rsResult.getString("USAC_EMAIL");
        objTmp.RFRNC_NMBR = rsResult.getString("RFRNC_NMBR");
        objTmp.RCRD_CNT = rsResult.getLong("RCRD_CNT");
        objTmp.TOT_PAYMENT = rsResult.getDouble("TOT_PAYMENT");
        objTmp.USAC_PRCS_DAT = rsResult.getDate("USAC_PRCS_DAT");
        objTmp.RTRCT_FLAG = rsResult.getString("RTRCT_FLAG");
        objTmp.DTL_SPIN = rsResult.getLong("DTL_SPIN");
        objTmp.FRN = rsResult.getLong("FRN");
        objTmp.SDC_INV_NO = rsResult.getString("SDC_INV_NO");
        objTmp.AMT_PAID = rsResult.getDouble("AMT_PAID");
        objTmp.DSBRSMNT_TXT = rsResult.getString("DSBRSMNT_TXT");
        objTmp.EMAIL_DATE = rsResult.getDate("EMAIL_DATE");
        objTmp.FILENAME = rsResult.getString("FILENAME");
        objTmp.PROCESS_DATE = rsResult.getDate("PROCESS_DATE");
        objTmp.STATUS = rsResult.getLong("STATUS");

        // add it to the vector
        vReturn.addElement(objTmp);
      }

      return vReturn;
    } catch (Exception e) {
      throw new Exception("BuildObjectVector()\n" + e.getMessage());
    }
  }
  /**
   * This method searches the tables FRNS, FRN_DETS, FRN_DET_HSTIES for the presence of a record in
   * a specific query. It returns the invoice line number.
   *
   * @param <code>StageUsacForm</code> The STAGE_USAC object.
   * @return long containing the invoice line number.
   */
  public long searchForAmount(java.sql.Connection conn) {
    // the buffer for the query
    StringBuffer sbQuery = null;
    long returnAmt = 0;
    // Vector invline=null;

    PreparedStatement psStmt = null;
    ResultSet rsResult = null;
    try {
      // init the buffer
      sbQuery = new StringBuffer("");

      // build the query
      sbQuery.append("SELECT max(INV_LN_NO) AS INV_LN_NO_MAX ");
      sbQuery.append("FROM (SELECT sum(CRDT_AMT) AMT, INV_LN_NO ");
      sbQuery.append("FROM FRNS, FRN_DETS, FRN_DET_HSTIES, INV ");
      sbQuery.append("WHERE ");
      sbQuery.append("FRN_ID=FRN_ID_FK AND FD_ID=FD_ID_FK AND INV_STAT='I' AND ");
      sbQuery.append("INV_ID_FK=INV_ID");
      // sbQuery.append(" AND FRN = ?'");
      sbQuery.append(" AND FRN = ? ");
      // sbQuery.append(this.getFrn());
      // sbQuery.append("' GROUP BY INV_LN_NO) " );
      sbQuery.append(" GROUP BY INV_LN_NO) ");
      sbQuery.append(" WHERE AMT = ?");
      // sbQuery.append(this.getAmtPaid());

      // write to log if in debug mode
      USFEnv.getLog()
          .writeDebug(
              "searchForAmount(StageUsacForm) " + "sbQuery is " + sbQuery.toString() + "\n",
              this,
              null);

      psStmt = conn.prepareStatement(sbQuery.toString());

      // psStmt.setLong(1,this.getFrn());
      psStmt.setString(1, String.valueOf(this.getFrn()));
      psStmt.setDouble(2, this.getAmtPaid());

      rsResult = psStmt.executeQuery();

      if (rsResult.next()) {
        returnAmt = rsResult.getLong(1);
      }
      if (rsResult != null) rsResult.close();
      if (psStmt != null) psStmt.close();

    } catch (Exception e) {
      try {
        if (rsResult != null) rsResult.close();
        if (psStmt != null) psStmt.close();
      } catch (Exception ex) {
        USFEnv.getLog().writeCrit("Unable to close ResultSet and statement", this, ex);
      }
      USFEnv.getLog()
          .writeCrit("searchForAmount(StageUsacForm) Failed Query:" + sbQuery.toString(), this, e);
    }

    /*	try
    {
    	if( rsResult != null)
    		rsResult.close();
    }
    catch(Exception e)
    {
    	USFEnv.getLog().writeCrit("Unable to close ResultSet",this,null);
    }
    try
    {
    	if( psStmt != null)
    		psStmt.close();
    }
    catch(Exception e)
    {
    	 USFEnv.getLog().writeCrit("Unable to close Prepared Statement",this,null);
    }*/

    return (returnAmt);
  } // searchForAmount