@Override
  public String getSQLWhere() {
    StringBuffer sql = new StringBuffer();
    if (txtDocumentNo.getText().length() > 0) sql.append(" AND UPPER(o.DocumentNo) LIKE ?");
    if (txtDescription.getText().length() > 0) sql.append(" AND UPPER(o.Description) LIKE ?");
    if (txtOrderRef.getText().length() > 0) sql.append(" AND UPPER(o.POReference) LIKE ?");
    //
    if (editorBPartner.getValue() != null) sql.append(" AND o.C_BPartner_ID=?");
    //
    Date fromDate = null;
    Date toDate = null;
    try {
      fromDate = dateFrom.getValue();
    } catch (WrongValueException e) {

    }
    try {
      toDate = dateTo.getValue();
    } catch (WrongValueException e) {

    }
    if (fromDate == null && toDate != null) {
      sql.append(" AND TRUNC(o.DateOrdered) <= ?");
    } else if (fromDate != null && toDate == null) {
      sql.append(" AND TRUNC(o.DateOrdered) >= ?");
    } else if (fromDate != null && toDate != null) {
      sql.append(" AND TRUNC(o.DateOrdered) BETWEEN ? AND ?");
    }
    //
    Double fromAmount = null;
    Double toAmount = null;
    if (amountFrom.getText() != null && amountFrom.getText().trim().length() > 0) {
      try {
        fromAmount = Double.parseDouble(amountFrom.getText());
      } catch (NumberFormatException e) {

      }
    }
    if (amountTo.getText() != null && amountTo.getText().trim().length() > 0) {
      try {
        toAmount = Double.parseDouble(amountTo.getText());
      } catch (NumberFormatException e) {

      }
    }
    if (fromAmount == null && toAmount != null) {
      sql.append(" AND o.GrandTotal <= ?");
    } else if (fromAmount != null && toAmount == null) {
      sql.append(" AND o.GrandTotal >= ?");
    } else if (fromAmount != null && toAmount != null) {
      sql.append(" AND o.GrandTotal BETWEEN ? AND ?");
    }
    sql.append(" AND o.IsSOTrx=?");

    log.finer(sql.toString());
    return sql.toString();
  }
示例#2
0
  /** Save */
  public void onOK() {
    log.config("Activity=" + m_activity);
    if (m_activity == null) {
      Clients.showBusy(null, false);
      return;
    }
    int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
    String textMsg = fTextMsg.getValue();
    //
    MWFNode node = m_activity.getNode();

    Object forward = null; // fForward.getValue();

    // ensure activity is ran within a transaction - [ 1953628 ]
    Trx trx = null;
    try {
      trx = Trx.get(Trx.createTrxName("FWFA"), true);
      m_activity.set_TrxName(trx.getTrxName());

      if (forward != null) {
        log.config("Forward to " + forward);
        int fw = ((Integer) forward).intValue();
        if (fw == AD_User_ID || fw == 0) {
          log.log(Level.SEVERE, "Forward User="******"CannotForward");
          trx.rollback();
          trx.close();
          return;
        }
      }
      //	User Choice - Answer
      else if (MWFNode.ACTION_UserChoice.equals(node.getAction())) {
        if (m_column == null) m_column = node.getColumn();
        //	Do we have an answer?
        int dt = m_column.getAD_Reference_ID();
        String value = fAnswerText.getText();
        if (dt == DisplayType.YesNo || dt == DisplayType.List) {
          ListItem li = fAnswerList.getSelectedItem();
          if (li != null) value = li.getValue().toString();
        }
        if (value == null || value.length() == 0) {
          FDialog.error(m_WindowNo, this, "FillMandatory", Msg.getMsg(Env.getCtx(), "Answer"));
          trx.rollback();
          trx.close();
          return;
        }
        //
        log.config("Answer=" + value + " - " + textMsg);
        try {
          m_activity.setUserChoice(AD_User_ID, value, dt, textMsg);
        } catch (Exception e) {
          log.log(Level.SEVERE, node.getName(), e);
          FDialog.error(m_WindowNo, this, "Error", e.toString());
          trx.rollback();
          trx.close();
          return;
        }
      }
      //	User Action
      else {
        log.config("Action=" + node.getAction() + " - " + textMsg);
        try {
          // ensure activity is ran within a transaction
          m_activity.setUserConfirmation(AD_User_ID, textMsg);
        } catch (Exception e) {
          log.log(Level.SEVERE, node.getName(), e);
          FDialog.error(m_WindowNo, this, "Error", e.toString());
          trx.rollback();
          trx.close();
          return;
        }
      }

      trx.commit();
    } finally {
      Clients.showBusy(null, false);
      if (trx != null) trx.close();
    }

    //	Next
    loadActivities();
    display(-1);
  } //	onOK
 /**
  * Get SQL WHERE parameter
  *
  * @param f field
  * @return sql
  */
 private String getSQLText(Textbox f) {
   String s = f.getText().toUpperCase();
   if (!s.endsWith("%")) s += "%";
   log.fine("String=" + s);
   return s;
 } //  getSQLText
  @Override
  protected void setParameters(PreparedStatement pstmt, boolean forCount) throws SQLException {
    int index = 1;
    if (txtDocumentNo.getText().length() > 0) pstmt.setString(index++, getSQLText(txtDocumentNo));
    if (txtDescription.getText().length() > 0) pstmt.setString(index++, getSQLText(txtDescription));
    if (txtOrderRef.getText().length() > 0) pstmt.setString(index++, getSQLText(txtOrderRef));
    //
    if (editorBPartner.getValue() != null) {
      Integer bp = (Integer) editorBPartner.getValue();
      pstmt.setInt(index++, bp.intValue());
      log.fine("BPartner=" + bp);
    }
    //

    Date fromD = null;
    Date toD = null;
    Timestamp from = null;
    Timestamp to = null;
    try {
      if (dateFrom.getValue() != null) {
        fromD = dateFrom.getValue();
        from = new Timestamp(fromD.getTime());
      }
    } catch (WrongValueException e) {

    }
    try {
      if (dateTo.getValue() != null) {
        toD = dateTo.getValue();
        to = new Timestamp(toD.getTime());
      }
    } catch (WrongValueException e) {

    }

    log.fine("Date From=" + from + ", To=" + to);
    if (from == null && to != null) {
      pstmt.setTimestamp(index++, to);
    } else if (from != null && to == null) {
      pstmt.setTimestamp(index++, from);
    } else if (from != null && to != null) {
      pstmt.setTimestamp(index++, from);
      pstmt.setTimestamp(index++, to);
    }

    //
    BigDecimal fromBD = null;
    BigDecimal toBD = null;
    Double fromAmt = null;
    Double toAmt = null;

    if (amountFrom.getText() != null && amountFrom.getText().trim().length() > 0) {
      try {
        fromAmt = Double.parseDouble(amountFrom.getText());
        fromBD = BigDecimal.valueOf(fromAmt);
      } catch (Exception e) {

      }
    }

    if (amountTo.getText() != null && amountTo.getText().trim().length() > 0) {
      try {
        toAmt = Double.parseDouble(amountTo.getText());
        toBD = BigDecimal.valueOf(toAmt);
      } catch (Exception e) {

      }
    }

    if (fromBD == null && toBD != null) {
      pstmt.setBigDecimal(index++, toBD);
    } else if (fromBD != null && toBD == null) {
      pstmt.setBigDecimal(index++, fromBD);
    } else if (fromBD != null && toBD != null) {
      pstmt.setBigDecimal(index++, fromBD);
      pstmt.setBigDecimal(index++, toBD);
    }

    pstmt.setString(index++, isSoTrx.isChecked() ? "Y" : "N");
  }