示例#1
0
  /** get info of window export, index of active tab, list child tab */
  protected void initTabInfo() {
    IADTabbox adTab = panel.getADTab();
    int selected = adTab.getSelectedIndex();
    int tabLevel = panel.getActiveGridTab().getTabLevel();
    Set<String> tables = new HashSet<String>();
    childs = new ArrayList<GridTab>();
    List<GridTab> includedList = panel.getActiveGridTab().getIncludedTabs();
    for (GridTab included : includedList) {
      String tableName = included.getTableName();
      if (tables.contains(tableName)) continue;
      tables.add(tableName);
      childs.add(included);
    }
    for (int i = selected + 1; i < adTab.getTabCount(); i++) {
      IADTabpanel adTabPanel = adTab.getADTabpanel(i);
      if (adTabPanel.getGridTab().isSortTab()) continue;
      if (adTabPanel.getGridTab().getTabLevel() <= tabLevel) break;
      String tableName = adTabPanel.getGridTab().getTableName();
      if (tables.contains(tableName)) continue;
      tables.add(tableName);
      childs.add(adTabPanel.getGridTab());
    }

    indxDetailSelected = 0;
    if (adTab.getSelectedDetailADTabpanel() != null)
      indxDetailSelected = adTab.getSelectedDetailADTabpanel().getGridTab().getTabNo();
  }
  private boolean dynInit(WButtonEditor button) throws Exception {
    // 获取海外入库单产生的异常
    Vector<Vector> data = getBExceptionData();
    if (data.size() <= 0) {
      // 当卖家海外仓入库单内所有单品状态都变更为"海外仓上架完成"时,将卖家海外仓入库单状态更新为"海外仓入库完成"
      if (m_mTab.getAD_Table_ID() == MOrder.Table_ID) {
        MOrder order = new MOrder(Env.getCtx(), m_mTab.getRecord_ID(), null);
        order.setStatus(MOrder.STATUS_ForeignWarehouseInboundCompleted);
        order.saveEx();
      } else if (m_mTab.getAD_Table_ID() == MWorkOrder.Table_ID) {
        MWorkOrder order = new MWorkOrder(Env.getCtx(), m_mTab.getRecord_ID(), null);
        order.setStatus(MWorkOrder.STATUS_Completed);
        order.saveEx();
      }

      // 不显示业务异常提示窗口
      return false;
    }

    ColumnInfo[] layout =
        new ColumnInfo[] {
          new ColumnInfo(Msg.translate(Env.getCtx(), "WT_ExceptionType"), ".", String.class),
          new ColumnInfo(Msg.translate(Env.getCtx(), "WT_ExceptionID"), ".", String.class)
        };
    xTable.prepareTable(layout, "", "", false, "");
    xTable.loadTable(data);
    // 显示业务异常提示窗口
    return true;
  } // dynInit
 public GridRowCtx(Properties ctx, GridTab tab, int row) {
   super();
   this.ctx = ctx;
   this.gridTab = tab;
   this.gridTable = tab.getTableModel();
   this._windowNo = tab.getWindowNo();
   this.row = row;
 }
示例#4
0
 public static void bind(DataModel data, GridTab curTab) {
   Set<String> keys = data.getData().keySet();
   for (String key : keys) {
     if (curTab.getField(key) != null) {
       // ?? wat abt callouts?
       curTab.setValue(key, data.get(key));
     }
   }
 }
示例#5
0
  /**
   * Save (Insert new) Row of Tab
   *
   * @param windowNo relative window
   * @param AD_Tab_ID tab
   * @param curRow insert after relative row number in results
   * @param context current (relevant) context of new row
   * @return error message or null
   */
  public ChangeVO insertRow(
      int windowNo, int AD_Tab_ID, int queryResultID, int curRow, Map<String, String> context) {
    if (context == null || context.size() == 0) return new ChangeVO(true, "No Context");
    UITab tab = getTab(AD_Tab_ID);
    if (tab == null) {
      log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
      return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID);
    }

    log.info("Line Amt:" + context.get("LineNetAmt"));
    CContext ctx = new CContext(m_context.entrySet());
    ctx.addWindow(windowNo, context);
    ChangeVO retValue = tab.saveRow(ctx, windowNo, true);
    if (retValue.hasError()) return retValue;
    // Update Results
    ArrayList<String[]> data = m_results.get(queryResultID);
    if (data == null) retValue.addError("Data Not Found");
    else {
      String[] dataRow = retValue.rowData;
      if (curRow >= data.size()) data.add(dataRow);
      else data.add(curRow, dataRow);
      retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
    }
    return retValue;
  } // insertRow
示例#6
0
 public ChangeVO updateRow(
     int windowNo,
     int AD_Tab_ID,
     int queryResultID,
     int relRowNo,
     Map<String, String> context,
     boolean force) {
   if (context == null || context.size() == 0)
     return new ChangeVO(true, Msg.translate(m_context, "NoContext"));
   ArrayList<String[]> data = m_results.get(queryResultID);
   if (data == null || data.size() == 0)
     return new ChangeVO(true, Msg.translate(m_context, "CachedDataNotFound"));
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return new ChangeVO(true, Msg.translate(m_context, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID));
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue;
   if (force) retValue = tab.saveRow(ctx, windowNo, false, null);
   else retValue = tab.saveRow(ctx, windowNo, false, data.get(relRowNo));
   if (retValue.hasError()) return retValue;
   // Update Results
   String[] dataRow = retValue.rowData.clone();
   data.set(relRowNo, dataRow);
   postProcessChangeVO(retValue, windowNo, context, dataRow, tab);
   retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
   if (retValue.isRefreshAll()) {}
   return retValue;
 }
示例#7
0
  /**
   * Method returns true if the given gridTab is a {@link I_C_OLCand} with the correct data
   * destination.
   *
   * @param gridTab
   */
  @Override
  public boolean isPreconditionApplicable(final GridTab gridTab) {
    if (!I_C_OLCand.Table_Name.equals(gridTab.get_TableName())) {
      return false;
    }

    final I_C_OLCand olCand = GridTabWrapper.create(gridTab, I_C_OLCand.class);
    if (olCand.isError()) {
      return false;
    }

    final IInputDataSourceDAO inputDataSourceDAO = Services.get(IInputDataSourceDAO.class);

    final I_AD_InputDataSource dest =
        inputDataSourceDAO.retrieveInputDataSource(
            Env.getCtx(), Contracts_Constants.DATA_DESTINATION_INTERNAL_NAME, false, get_TrxName());
    if (dest == null) {
      return false;
    }
    if (dest.getAD_InputDataSource_ID() != olCand.getAD_DataDestination_ID()) {
      return false;
    }

    return true;
  }
  public String priceBeco(
      Ctx ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) {
    System.out.println("pricebeco ... ");
    try {
      BigDecimal precio = (BigDecimal) mField.getValue();

      String priceRuleSQL =
          "select xx_lowrank,xx_highrank,xx_termination,xx_increase,xx_infinitevalue from xx_vme_pricerule order by (xx_lowrank)";
      PreparedStatement priceRulePstmt = DB.prepareStatement(priceRuleSQL, null);
      ResultSet priceRuleRs = priceRulePstmt.executeQuery();

      Integer precioInt = precio.intValue();
      BigDecimal precioBig = new BigDecimal(precioInt);
      while (priceRuleRs.next()) {
        if (precioBig.compareTo(priceRuleRs.getBigDecimal("xx_lowrank")) >= 0
            && precioBig.compareTo(priceRuleRs.getBigDecimal("xx_highrank")) <= 0) {
          Integer incremento = priceRuleRs.getInt("xx_increase");

          for (Integer i = priceRuleRs.getInt("xx_lowrank") - 1;
              i <= priceRuleRs.getInt("xx_highrank");
              i = i + incremento) {
            BigDecimal var = new BigDecimal(i);

            if (precioBig.compareTo(var) <= 0) {
              BigDecimal beco = var;

              BigDecimal terminacion = priceRuleRs.getBigDecimal("xx_termination");
              if (terminacion.intValue() == 0) {
                beco = var.add(terminacion);
              } else {
                var = var.divide(new BigDecimal(10));
                Integer aux = var.intValue() * 10;
                beco = new BigDecimal(aux).add(terminacion);
              }
              // mTab.setValue("PriceList", beco);
              priceRuleRs.close();
              priceRulePstmt.close();

              if (beco.compareTo(precio) == 0) {
                return priceBandBeco(ctx, WindowNo, mTab, mField, value, oldValue);
                // return"";
              } else {
                mTab.setValue("PriceList", beco);
                return "";
                // return "Precio Beco Sugerido "+beco.toString();
              }
            }
          }
        }
      }
      priceRuleRs.close();
      priceRulePstmt.close();

      return priceBandBeco(ctx, WindowNo, mTab, mField, value, oldValue);
      // return "";
    } catch (Exception e) {
      return e.getMessage();
    }
  }
  /**
   * ************************************************************************ Save Multiple records
   * - Clone a record and assign new values to each clone for a specific column.
   *
   * @param ctx context
   * @param tableName Table Name
   * @param columnName Column for which value need to be changed
   * @param recordId Record to clone
   * @param values Values to be assigned to clones for the specified column
   * @param trxName Transaction
   * @throws Exception If error is occured when loading the PO or saving clones
   * @author ashley
   */
  protected void saveMultipleRecords(
      Properties ctx,
      String tableName,
      String columnName,
      int recordId,
      Integer[] values,
      String trxName)
      throws Exception {
    if (values == null) {
      return;
    }

    int oldRow = gridTab.getCurrentRow();
    GridField lineField = gridTab.getField("Line");

    for (int i = 0; i < values.length; i++) {
      if (!gridTab.dataNew(true)) {
        throw new IllegalStateException("Could not clone tab");
      }

      gridTab.setValue(columnName, values[i]);

      if (lineField != null) {
        gridTab.setValue(lineField, 0);
      }

      if (!gridTab.dataSave(false)) {
        throw new IllegalStateException("Could not update tab");
      }

      gridTab.setCurrentRow(oldRow);
    }
  }
示例#10
0
 /** Save Selection */
 private void saveSelection() {
   if (m_changed && m_gridController != null) {
     int row = m_gridController.getTable().getSelectedRow();
     if (row >= 0)
       m_C_ValidCombination_ID =
           ((Integer) m_mTab.getValue(row, "C_ValidCombination_ID")).intValue();
     log.config("(" + row + ") - " + m_C_ValidCombination_ID);
   }
 } //	saveSelection
示例#11
0
 @Override
 public synchronized Object put(Object key, Object value) {
   if (gridTab == null) throw new IllegalStateException("Method not supported (gridTab is null)");
   if (gridTab.getCurrentRow() != row) {
     return ctx.put(key, value);
   }
   String columnName = getColumnName(key);
   if (columnName == null) {
     return ctx.put(key, value);
   }
   GridField field = gridTab.getField(columnName);
   if (field == null) {
     return ctx.put(key, value);
   }
   Object valueOld = field.getValue();
   field.setValue(value, false); // inserting=false
   return valueOld;
 }
示例#12
0
  public ProcessHelper setPO(Object o) {
    PO po = InterfaceWrapperHelper.getStrictPO(o);
    if (po != null) {
      setTableId(po.get_Table_ID());
      setRecordId(po.get_ID());
      return this;
    }

    GridTab gridTab = GridTabWrapper.getGridTab(o);
    if (gridTab != null) {
      setTableId(gridTab.get_TableName());
      setRecordId(gridTab.getKeyID(gridTab.getCurrentRow()));
      return this;
    }

    fail("Object " + o + " is not supported in setPO");
    return this;
  }
示例#13
0
  /** Show list tab can export for user selection */
  protected void displayExportTabSelection() {
    initTabInfo();

    exporter = getExporter();
    if (exporter == null) {
      Events.echoEvent("onExporterException", winExportFile, null);
    }

    // clear list checkbox selection to recreate with new reporter
    selectionTabRow.getChildren().clear();
    Vlayout vlayout = new Vlayout();
    selectionTabRow.appendChild(new Space());
    selectionTabRow.appendChild(vlayout);
    vlayout.appendChild(new Label(Msg.getMsg(Env.getCtx(), "SelectTabToExport")));

    chkSelectionTabForExport = new ArrayList<Checkbox>();
    boolean isHasSelectionTab = false;
    boolean isSelectTabDefault = false;
    // with 2Pack, default is export all child tab
    if (exporter.getClass().getName().equals("org.adempiere.pipo2.GridTab2PackExporter")) {
      isSelectTabDefault = true;
    }
    // for to make each export tab with one checkbox
    for (GridTab child : childs) {
      Checkbox chkSelectionTab = new Checkbox();
      chkSelectionTab.setLabel(child.getName());
      // just allow selection tab can export
      if (!exporter.isExportableTab(child)) {
        continue;
      }
      if (child.getTabNo() == indxDetailSelected || isSelectTabDefault) {
        chkSelectionTab.setSelected(true);
      }
      chkSelectionTab.setAttribute("tabBinding", child);
      vlayout.appendChild(chkSelectionTab);
      chkSelectionTabForExport.add(chkSelectionTab);
      isHasSelectionTab = true;
    }

    // in case no child tab can export. clear selection area
    if (isHasSelectionTab == false) {
      selectionTabRow.getChildren().clear();
    }
  }
示例#14
0
 /**
  * Status Change Listener
  *
  * @param e event
  */
 public void dataStatusChanged(DataStatusEvent e) {
   log.config(e.toString());
   String info = (String) m_mTab.getValue("Description");
   f_Description.setText(info);
   //
   //	log.info( ">> Field=" + m_mTab.getValue("AD_Org_ID"),
   //		"Editor=" + f_AD_Org_ID.getValue());
   //	if (f_AD_Org_ID.getValue() == null)
   //		f_AD_Org_ID.setValue(m_mTab.getValue("AD_Org_ID"));
 } //	statusChanged
示例#15
0
  public int getTabNo() {
    final int tabNo;
    if (gridTab != null) {
      tabNo = gridTab.getTabNo();
    } else if (gridTable != null) {
      tabNo = gridTable.getTabNo();
    } else {
      tabNo = Env.TAB_None;
    }

    return tabNo;
  }
  public ProcessDialogBuilder setFromGridTab(GridTab gridTab) {
    final int windowNo = gridTab.getWindowNo();
    final int tabNo = gridTab.getTabNo();

    setWindowAndTabNo(windowNo, tabNo);
    setIsSOTrx(Env.isSOTrx(gridTab.getCtx(), windowNo));
    setTableAndRecord(gridTab.getAD_Table_ID(), gridTab.getRecord_ID());
    setWhereClause(gridTab.getTableModel().getSelectWhereClauseFinal());
    skipResultsPanel();

    return this;
  }
示例#17
0
 /**
  * Refresh current row of Tab
  *
  * @param windowNo relative window
  * @param AD_Tab_ID tab
  * @param relRowNo relative row number in results
  * @param context current (relevant) context of new row
  * @return error message or null
  */
 public ChangeVO refreshRow(
     int windowNo, int AD_Tab_ID, int queryResultID, int relRowNo, Map<String, String> context) {
   if (context == null || context.size() == 0) return new ChangeVO(true, "No Context");
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID);
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue = tab.refreshRow(ctx, windowNo);
   if (retValue.hasError()) return retValue;
   // Update Results
   ArrayList<String[]> data = m_results.get(queryResultID);
   if (data == null) retValue.addError("Data Not Found");
   else {
     String[] dataRow = retValue.rowData.clone();
     data.set(relRowNo, dataRow);
     postProcessChangeVO(retValue, windowNo, context, dataRow, tab);
     retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
   }
   return retValue;
 } // refreshRow
示例#18
0
  private Vector<Vector> getBExceptionData() {
    Vector<Vector> data = new Vector<Vector>();

    final String whereClause =
        MBExceptionDetail.COLUMNNAME_Record_ID
            + " = "
            + m_mTab.getRecord_ID()
            + " AND "
            + MBExceptionDetail.COLUMNNAME_Status
            + "<>"
            + DB.TO_STRING(MBExceptionDetail.STATUS_Completed);
    MBExceptionDetail[] bExceptionDetails =
        MBExceptionDetail.getBExceptionDetail(Env.getCtx(), whereClause);
    for (MBExceptionDetail ex : bExceptionDetails) {

      Vector<String> row = new Vector<String>();
      row.add(ex.getWT_BExceptionType().getName());
      row.add(ex.getValue());
      data.add(row);
    }

    return data;
  }
示例#19
0
  /**
   * Action Find. - create where clause - query database
   *
   * @param includeAliasCombination include alias combination
   */
  private void action_Find(boolean includeAliasCombination) {
    log.info("");
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    //	Create where Clause
    MQuery query = null;
    if (m_query != null) query = m_query.deepCopy();
    else query = new MQuery();
    //	Alias
    if (includeAliasCombination && f_Alias != null && f_Alias.getValue().toString().length() > 0) {
      String value = f_Alias.getValue().toString().toUpperCase();
      if (!value.endsWith("%")) value += "%";
      query.addRestriction("UPPER(Alias)", MQuery.LIKE, value);
    }
    //	Combination (mandatory)
    if (includeAliasCombination && f_Combination.getValue().toString().length() > 0) {
      String value = f_Combination.getValue().toString().toUpperCase();
      if (!value.endsWith("%")) value += "%";
      query.addRestriction("UPPER(Combination)", MQuery.LIKE, value);
    }
    //	Org (mandatory)
    if (f_AD_Org_ID != null && f_AD_Org_ID.getValue() != null)
      query.addRestriction("AD_Org_ID", MQuery.EQUAL, f_AD_Org_ID.getValue());
    //	Account (mandatory)
    if (f_Account_ID != null && f_Account_ID.getValue() != null)
      query.addRestriction("Account_ID", MQuery.EQUAL, f_Account_ID.getValue());
    if (f_SubAcct_ID != null && f_SubAcct_ID.getValue() != null)
      query.addRestriction("C_SubAcct_ID", MQuery.EQUAL, f_SubAcct_ID.getValue());

    //	Product
    if (f_M_Product_ID != null && f_M_Product_ID.getValue() != null)
      query.addRestriction("M_Product_ID", MQuery.EQUAL, f_M_Product_ID.getValue());
    //	BPartner
    if (f_C_BPartner_ID != null && f_C_BPartner_ID.getValue() != null)
      query.addRestriction("C_BPartner_ID", MQuery.EQUAL, f_C_BPartner_ID.getValue());
    //	Campaign
    if (f_C_Campaign_ID != null && f_C_Campaign_ID.getValue() != null)
      query.addRestriction("C_Campaign_ID", MQuery.EQUAL, f_C_Campaign_ID.getValue());
    //	Loc From
    if (f_C_LocFrom_ID != null && f_C_LocFrom_ID.getValue() != null)
      query.addRestriction("C_LocFrom_ID", MQuery.EQUAL, f_C_LocFrom_ID.getValue());
    //	Loc To
    if (f_C_LocTo_ID != null && f_C_LocTo_ID.getValue() != null)
      query.addRestriction("C_LocTo_ID", MQuery.EQUAL, f_C_LocTo_ID.getValue());
    //	Project
    if (f_C_Project_ID != null && f_C_Project_ID.getValue() != null)
      query.addRestriction("C_Project_ID", MQuery.EQUAL, f_C_Project_ID.getValue());
    //	SRegion
    if (f_C_SalesRegion_ID != null && f_C_SalesRegion_ID.getValue() != null)
      query.addRestriction("C_SalesRegion_ID", MQuery.EQUAL, f_C_SalesRegion_ID.getValue());
    //	Org Trx
    if (f_AD_OrgTrx_ID != null && f_AD_OrgTrx_ID.getValue() != null)
      query.addRestriction("AD_OrgTrx_ID", MQuery.EQUAL, f_AD_OrgTrx_ID.getValue());
    //	Activity
    if (f_C_Activity_ID != null && f_C_Activity_ID.getValue() != null)
      query.addRestriction("C_Activity_ID", MQuery.EQUAL, f_C_Activity_ID.getValue());
    //	User 1
    if (f_User1_ID != null && f_User1_ID.getValue() != null)
      query.addRestriction("User1_ID", MQuery.EQUAL, f_User1_ID.getValue());
    //	User 2
    if (f_User2_ID != null && f_User2_ID.getValue() != null)
      query.addRestriction("User2_ID", MQuery.EQUAL, f_User2_ID.getValue());

    //	Query
    m_mTab.setQuery(query);
    m_mTab.query(false);
    statusBar.setStatusDB(String.valueOf(m_mTab.getRowCount()));
    setCursor(Cursor.getDefaultCursor());
  } //	action_Find
示例#20
0
  /**
   * Invoke the form VCreateFromPackage
   *
   * @param ctx context
   * @param WindowNo window no
   * @param mTab tab
   * @param mField field
   * @param value value
   * @return null or error message
   */
  public String createFrom(
      final Properties ctx,
      final int WindowNo,
      final GridTab mTab,
      final GridField mField,
      final Object value) {

    final I_C_Invoice invoice = InterfaceWrapperHelper.create(mTab, I_C_Invoice.class);
    if (invoice.getC_Invoice_ID() <= 0) {
      return "";
    }
    final I_C_DocType dt = invoice.getC_DocTypeTarget();

    if (!Constants.DOCBASETYPE_AEInvoice.equals(dt.getDocBaseType())
        || !CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION.equals(
            dt.getDocSubType())) {
      // nothing to do
      final IDocumentPA docPA = Services.get(IDocumentPA.class);
      final I_C_DocType dtCorr =
          docPA.retrieve(
              ctx,
              invoice.getAD_Org_ID(),
              Constants.DOCBASETYPE_AEInvoice,
              CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION,
              true,
              null);
      if (dtCorr != null) {
        final String msg =
            Msg.getMsg(
                ctx, MSG_INVOICECORR_CREATEFROM_WRONG_DOCTYPE_1P, new Object[] {dtCorr.getName()});
        return msg;
      } else {
        throw new AdempiereException(
            "Missing C_DocType with DocBaseType='"
                + Constants.DOCBASETYPE_AEInvoice
                + "' and DocSubType='"
                + CommissionConstants.COMMISSON_INVOICE_DOCSUBTYPE_CORRECTION
                + "'");
      }
    }

    final String swingclassname = "de.metas.commission.form.VCreateCorrections";
    final String zkclassname = "not.yet.implemented";
    final String classname;
    if (Ini.isClient()) {
      classname = swingclassname;
    } else {
      classname = zkclassname;
      return "";
    }

    ICreateFrom cf = null;
    Class cl;
    try {
      if (Ini.isClient()) {
        cl = Class.forName(classname);
      } else {
        cl = Thread.currentThread().getContextClassLoader().loadClass(classname);
      }
    } catch (final ClassNotFoundException e) {
      log.error(e.getLocalizedMessage(), e);
      return e.getLocalizedMessage();
    }
    if (cl != null) {
      try {
        java.lang.reflect.Constructor<? extends ICreateFrom> ctor =
            cl.getConstructor(I_C_Invoice.class, int.class);
        cf = ctor.newInstance(invoice, WindowNo);
      } catch (Throwable e) {
        log.error(e.getLocalizedMessage(), e);
        return e.getLocalizedMessage();
      }
    }

    if (cf != null) {
      if (cf.isInitOK()) {
        cf.showWindow();
        cf.closeWindow();
        mTab.dataRefresh();
      } else cf.closeWindow();
    }

    return "";
  } // createShippingPackages
  /** Start dialog */
  private void cmd_dialog() {
    //
    Integer oldValue = (Integer) getValue();
    int oldValueInt = oldValue == null ? 0 : oldValue.intValue();
    int M_AttributeSetInstance_ID = oldValueInt;
    int M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_Product_ID");
    int M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductBOM_ID");

    log.config(
        "M_Product_ID="
            + M_Product_ID
            + "/"
            + M_ProductBOM_ID
            + ",M_AttributeSetInstance_ID="
            + M_AttributeSetInstance_ID
            + ", AD_Column_ID="
            + gridField.getAD_Column_ID());

    //	M_Product.M_AttributeSetInstance_ID = 8418
    boolean productWindow = (gridField.getAD_Column_ID() == 8418); // 	HARDCODED

    //	Exclude ability to enter ASI
    boolean exclude = true;

    if (M_Product_ID != 0) {
      MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
      int M_AttributeSet_ID = Services.get(IProductBL.class).getM_AttributeSet_ID(product);
      if (M_AttributeSet_ID != 0) {
        final IAttributeExcludeBL excludeBL = Services.get(IAttributeExcludeBL.class);
        final I_M_AttributeSet attributeSet =
            InterfaceWrapperHelper.create(
                Env.getCtx(), M_AttributeSet_ID, I_M_AttributeSet.class, ITrx.TRXNAME_None);
        final I_M_AttributeSetExclude asExclude =
            excludeBL.getAttributeSetExclude(
                attributeSet, gridField.getAD_Column_ID(), Env.isSOTrx(Env.getCtx(), m_WindowNo));
        if ((null == asExclude) || (!excludeBL.isFullExclude(asExclude))) {
          exclude = false;
        }
      }
    }

    boolean changed = false;
    if (M_ProductBOM_ID != 0) // 	Use BOM Component
    M_Product_ID = M_ProductBOM_ID;
    //
    if (!productWindow && (M_Product_ID == 0 || exclude)) {
      changed = true;
      getComponent().setText(null);
      M_AttributeSetInstance_ID = 0;
    } else {
      WPAttributeDialog vad =
          new WPAttributeDialog(
              M_AttributeSetInstance_ID,
              M_Product_ID,
              m_C_BPartner_ID,
              productWindow,
              gridField.getAD_Column_ID(),
              m_WindowNo);
      if (vad.isChanged()) {
        getComponent().setText(vad.getM_AttributeSetInstanceName());
        M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID();
        if (m_GridTab != null && !productWindow && vad.getM_Locator_ID() > 0)
          m_GridTab.setValue("M_Locator_ID", vad.getM_Locator_ID());
        changed = true;
      }
    }
    /**
     * Selection { // Get Model MAttributeSetInstance masi = MAttributeSetInstance.get(Env.getCtx(),
     * M_AttributeSetInstance_ID, M_Product_ID); if (masi == null) { log.log(Level.SEVERE, "No Model
     * for M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID + ", M_Product_ID=" +
     * M_Product_ID); } else { Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID",
     * masi.getM_AttributeSet_ID()); // Get Attribute Set MAttributeSet as =
     * masi.getMAttributeSet(); // Product has no Attribute Set if (as == null)
     * ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet"); // Product has no Instance
     * Attributes else if (!as.isInstanceAttribute()) ADialog.error(m_WindowNo, this,
     * "PAttributeNoInstanceAttribute"); else { int M_Warehouse_ID = Env.getContextAsInt (Env.getCtx
     * (), m_WindowNo, "M_Warehouse_ID"); int M_Locator_ID = Env.getContextAsInt (Env.getCtx (),
     * m_WindowNo, "M_Locator_ID"); String title = ""; PAttributeInstance pai = new
     * PAttributeInstance ( Env.getFrame(this), title, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
     * m_C_BPartner_ID); if (pai.getM_AttributeSetInstance_ID() != -1) {
     * m_text.setText(pai.getM_AttributeSetInstanceName()); M_AttributeSetInstance_ID =
     * pai.getM_AttributeSetInstance_ID(); changed = true; } } } }
     */

    //	Set Value
    if (changed) {
      log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
      m_value = new Object(); // 	force re-query display
      if (M_AttributeSetInstance_ID == 0) setValue(null);
      else setValue(new Integer(M_AttributeSetInstance_ID));

      ValueChangeEvent vce =
          new ValueChangeEvent(this, gridField.getColumnName(), new Object(), getValue());
      fireValueChange(vce);
      if (M_AttributeSetInstance_ID == oldValueInt && m_GridTab != null && gridField != null) {
        //  force Change - user does not realize that embedded object is already saved.
        m_GridTab.processFieldChange(gridField);
      }
    } //	change
  } //  cmd_file
示例#22
0
  /** @param e */
  public void valueChange(ValueChangeEvent e) {
    if (gridTab.isProcessed()) //  only active records
    {
      Object source = e.getSource();
      if (source instanceof WEditor) {
        // Elaine 2009/05/06
        WEditor editor = (WEditor) source;
        GridField gridField = editor.getGridField();

        if (gridField != null) {
          if (!gridField.isEditable(true)) {
            logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
            return;
          }
        } else if (!editor.isReadWrite()) {
          logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
          return;
        }
      } else {
        logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
        return;
      }
    } //  processed
    logger.config(
        "("
            + gridTab.toString()
            + ") "
            + e.getPropertyName()
            + "="
            + e.getNewValue()
            + " ("
            + e.getOldValue()
            + ") "
            + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));

    //  Get Row/Col Info
    GridTable mTable = gridTab.getTableModel();
    int row = gridTab.getCurrentRow();
    int col = mTable.findColumn(e.getPropertyName());
    //
    if (e.getNewValue() == null
        && e.getOldValue() != null
        && e.getOldValue().toString().length() > 0) //  some editors return "" instead of null
      //        	  this is the original code from GridController, don't know what it does there but
      // it breaks ignore button for web ui
      //            mTable.setChanged (true);
      mTable.setValueAt(e.getNewValue(), row, col);
    else {

      Object newValue = e.getNewValue();
      Integer newValues[] = null;

      if (newValue instanceof Integer[]) {
        newValues = ((Integer[]) newValue);
        newValue = newValues[0];

        if (newValues.length > 1) {
          Integer valuesCopy[] = new Integer[newValues.length - 1];
          System.arraycopy(newValues, 1, valuesCopy, 0, valuesCopy.length);
          newValues = valuesCopy;
        } else {
          newValues = null;
        }
      } else if (newValue instanceof Object[]) {
        logger.severe("Multiple values can only be processed for IDs (Integer)");
        throw new IllegalArgumentException(
            "Multiple Selection values not available for this field. " + e.getPropertyName());
      }

      mTable.setValueAt(newValue, row, col);
      //  Force Callout
      if (e.getPropertyName().equals("S_ResourceAssignment_ID")) {
        GridField mField = gridTab.getField(col);
        if (mField != null && mField.getCallout().length() > 0) {
          gridTab.processFieldChange(mField); //  Dependencies & Callout
        }
      }

      if (newValues != null && newValues.length > 0) {
        // Save data, since record need to be used for generating clones.
        if (!gridTab.dataSave(false)) {
          throw new AdempiereException("SaveError");
        }

        // Retrieve the current record ID
        int recordId = gridTab.getKeyID(gridTab.getCurrentRow());

        Trx trx = Trx.get(Trx.createTrxName(), true);
        trx.start();
        try {
          saveMultipleRecords(
              Env.getCtx(),
              gridTab.getTableName(),
              e.getPropertyName(),
              recordId,
              newValues,
              trx.getTrxName());
          trx.commit();
          gridTab.dataRefreshAll();
        } catch (Exception ex) {
          trx.rollback();
          logger.severe(ex.getMessage());
          throw new AdempiereException("SaveError");
        } finally {
          trx.close();
        }
      }
    }
  } // ValueChange
示例#23
0
  /**
   * Dyanmic Init. When a row is selected, the editor values are set (editors do not change grid)
   *
   * @return true if initialized
   */
  private boolean initAccount() {
    m_AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID");
    //	Get AcctSchema Info
    if (s_AcctSchema == null || s_AcctSchema.getC_AcctSchema_ID() != m_C_AcctSchema_ID)
      s_AcctSchema = new MAcctSchema(Env.getCtx(), m_C_AcctSchema_ID, null);
    log.config(s_AcctSchema.toString() + ", #" + s_AcctSchema.getAcctSchemaElements().length);
    Env.setContext(Env.getCtx(), m_WindowNo, "C_AcctSchema_ID", m_C_AcctSchema_ID);

    //  Model
    int AD_Window_ID = 153; // 	Maintain Account Combinations
    GridWindowVO wVO = AEnv.getMWindowVO(m_WindowNo, AD_Window_ID, 0);
    if (wVO == null) return false;
    m_mWindow = new GridWindow(wVO);
    m_mTab = m_mWindow.getTab(0);
    // Make sure is the tab is loaded - teo_sarca [ 1659124 ]
    if (!m_mTab.isLoadComplete()) m_mWindow.initTab(0);

    //  ParameterPanel restrictions
    m_mTab.getField("Alias").setDisplayLength(15);
    m_mTab.getField("Combination").setDisplayLength(15);
    //  Grid restrictions
    m_mTab.getField("AD_Client_ID").setDisplayed(false);
    m_mTab.getField("C_AcctSchema_ID").setDisplayed(false);
    m_mTab.getField("IsActive").setDisplayed(false);
    m_mTab.getField("IsFullyQualified").setDisplayed(false);
    //  don't show fields not being displayed in this environment
    for (int i = 0; i < m_mTab.getFieldCount(); i++) {
      GridField field = m_mTab.getField(i);
      if (!field.isDisplayed(true)) //  check context
      field.setDisplayed(false);
    }

    //  GridController
    m_gridController = new GridController();
    m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null);
    m_gridController.setPreferredSize(new Dimension(300, 100));
    panel.add(m_gridController, BorderLayout.CENTER);

    //  Prepare Parameter
    m_gbc.anchor = GridBagConstraints.NORTHWEST;
    m_gbc.gridy = 0; // 	line
    m_gbc.gridx = 0;
    m_gbc.gridwidth = 1;
    m_gbc.insets = m_fieldInsets;
    m_gbc.fill = GridBagConstraints.HORIZONTAL;
    m_gbc.weightx = 0;
    m_gbc.weighty = 0;

    int TabNo = 0;

    //	Alias
    if (s_AcctSchema.isHasAlias()) {
      GridField alias = m_mTab.getField("Alias");
      f_Alias = VEditorFactory.getEditor(m_mTab, alias, false);
      addLine(alias, f_Alias, false);
    } //	Alias

    //	Combination
    GridField combination = m_mTab.getField("Combination");
    f_Combination = VEditorFactory.getEditor(m_mTab, combination, false);
    addLine(combination, f_Combination, false);
    m_newRow = true;

    /** Create Fields in Element Order */
    MAcctSchemaElement[] elements = s_AcctSchema.getAcctSchemaElements();
    for (int i = 0; i < elements.length; i++) {
      MAcctSchemaElement ase = elements[i];
      String type = ase.getElementType();
      boolean isMandatory = ase.isMandatory();
      //
      if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) {
        GridField field = m_mTab.getField("AD_Org_ID");
        f_AD_Org_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_AD_Org_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Account)) {
        GridField field = m_mTab.getField("Account_ID");
        f_Account_ID = VEditorFactory.getEditor(m_mTab, field, false);
        //	((VLookup)f_Account_ID).setWidth(400);
        addLine(field, f_Account_ID, isMandatory);
        f_Account_ID.addVetoableChangeListener(this);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
        GridField field = m_mTab.getField("C_SubAcct_ID");
        f_SubAcct_ID = VEditorFactory.getEditor(m_mTab, field, false);
        //	((VLookup)f_SubAcct_ID).setWidth(400);
        addLine(field, f_SubAcct_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Product)) {
        GridField field = m_mTab.getField("M_Product_ID");
        f_M_Product_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_M_Product_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner)) {
        GridField field = m_mTab.getField("C_BPartner_ID");
        f_C_BPartner_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_C_BPartner_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign)) {
        GridField field = m_mTab.getField("C_Campaign_ID");
        f_C_Campaign_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_C_Campaign_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom)) {
        GridField field = m_mTab.getField("C_LocFrom_ID");
        f_C_LocFrom_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_C_LocFrom_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo)) {
        GridField field = m_mTab.getField("C_LocTo_ID");
        f_C_LocTo_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_C_LocTo_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Project)) {
        GridField field = m_mTab.getField("C_Project_ID");
        f_C_Project_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_C_Project_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion)) {
        GridField field = m_mTab.getField("C_SalesRegion_ID");
        f_C_SalesRegion_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_C_SalesRegion_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx)) {
        GridField field = m_mTab.getField("AD_OrgTrx_ID");
        f_AD_OrgTrx_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_AD_OrgTrx_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Activity)) {
        GridField field = m_mTab.getField("C_Activity_ID");
        f_C_Activity_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_C_Activity_ID, isMandatory);
      }
      //	User1
      else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1)) {
        GridField field = m_mTab.getField("User1_ID");
        f_User1_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_User1_ID, isMandatory);
      } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
        GridField field = m_mTab.getField("User2_ID");
        f_User2_ID = VEditorFactory.getEditor(m_mTab, field, false);
        addLine(field, f_User2_ID, isMandatory);
      }
    } //	Create Fields in Element Order

    //	Add description
    m_newRow = true;
    m_gbc.gridy = m_line++;
    m_gbc.gridx = 0;
    m_gbc.gridwidth = 4;
    m_gbc.insets = new Insets(5, 15, 2, 0); // 	top,left,bottom,right
    m_gbc.fill = GridBagConstraints.HORIZONTAL;
    f_Description.setFont(f_Description.getFont().deriveFont(Font.ITALIC));
    parameterPanel.add(f_Description, m_gbc);

    //	Finish
    m_query = new MQuery();
    m_query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
    m_query.addRestriction("IsFullyQualified", MQuery.EQUAL, "Y");
    if (m_mAccount.C_ValidCombination_ID == 0) m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
    else {
      MQuery query = new MQuery();
      query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
      query.addRestriction("C_ValidCombination_ID", MQuery.EQUAL, m_mAccount.C_ValidCombination_ID);
      m_mTab.setQuery(query);
    }
    m_mTab.query(false);
    m_gridController.getTable().addMouseListener(new VAccountDialog_mouseAdapter(this));
    m_gridController.addDataStatusListener(this);

    statusBar.setStatusLine(s_AcctSchema.toString());
    statusBar.setStatusDB("?");

    //	Initial value
    if (m_mAccount.C_ValidCombination_ID != 0) m_mTab.navigate(0);

    log.config("fini");
    return true;
  } //	initAccount
  public String priceBandBeco(
      Ctx ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) {
    System.out.println("pricebandBeco");

    PreparedStatement pstmtC = null;
    ResultSet rsC = null;
    try {

      MVMRPOLineRefProv lineRefProv =
          new MVMRPOLineRefProv(ctx, (Integer) mTab.getValue("XX_VMR_PO_LineRefProv_ID"), null);
      MOrder order = new MOrder(ctx, lineRefProv.getC_Order_ID(), null);

      // String conceptoProducto = ctx.getContext(WindowNo, "XX_ConceptValue_ID");
      Integer conceptoProducto = lineRefProv.getXX_VME_ConceptValue_ID();

      // String seccionProducto = ctx.getContext(WindowNo,"XX_SECTION_ID");
      Integer seccionProducto = lineRefProv.getXX_VMR_Section_ID();

      // String lineaProducto = ctx.getContext(WindowNo,"XX_LINE_ID");
      Integer lineaProducto = lineRefProv.getXX_VMR_Line_ID();

      // String departamentoProducto = ctx.getContext(WindowNo,"XX_VMR_DEPARTMENT_ID");
      Integer departamentoProducto = order.getXX_VMR_DEPARTMENT_ID();

      /** Agregado por Javier Pino, para que funcione en distribucion */
      if (mTab.getValue("M_Product_ID") != null) {
        MProduct producto = new MProduct(ctx, (Integer) mTab.getValue("M_Product_ID"), null);
        conceptoProducto = producto.getXX_VME_ConceptValue_ID();
        departamentoProducto = producto.getXX_VMR_Department_ID();
        seccionProducto = producto.getXX_VMR_Section_ID();
        lineaProducto = producto.getXX_VMR_Line_ID();
      }
      /** Fin agregado Javier Pino */
      String conceptoComparar = null;

      String SQLA =
          "select P.xx_comparisonvalue_id "
              + "from xx_vme_priceband P , xx_vme_conceptvalue C "
              + "where C.XX_VME_ConceptValue_ID = "
              + conceptoProducto
              + " and "
              +
              // "where C.XX_VME_ConceptValue_ID = 1000002 and " +
              // "where C.XX_VME_ConceptValue_ID = 1000002 and " +
              "C.XX_VME_ConceptValue_id = P.xx_conceptvalue_id";

      // System.out.println("sqla "+SQLA);

      PreparedStatement pstmtA = DB.prepareStatement(SQLA, null);
      ResultSet rsA = pstmtA.executeQuery();

      if (rsA.next()) {
        conceptoComparar = rsA.getString("xx_comparisonvalue_id");
        // conceptoComparar="1000002";
      }
      rsA.close();
      pstmtA.close();

      Double promedioSeccion = 0.0;
      Double promedioLinea = 0.0;
      Double promedioDepartamento = 0.0;

      String SQL =
          "SELECT AVG(AUX.A) valor FROM "
              + "(SELECT MAX(P.XX_SALEPRICE) A, P.M_PRODUCT_ID "
              + "FROM XX_VMR_PRICECONSECUTIVE P, M_PRODUCT M "
              + "WHERE ";

      if (conceptoComparar == null) {
        SQL += "M.XX_VME_ConceptValue_ID IS NULL and ";
      } else {
        SQL += "M.XX_VME_ConceptValue_ID=" + conceptoComparar + " and ";
      }

      SQL +=
          "M.XX_VMR_Section_ID = "
              + seccionProducto
              + " "
              +
              //			"P.m_product_id <> "+ctx.getContext(WindowNo, "M_Product_ID")+" and "+
              "AND P.M_PRODUCT_ID = M.M_PRODUCT_ID "
              + "group by P.M_PRODUCT_ID) AUX";

      PreparedStatement pstmt = DB.prepareStatement(SQL, null);
      ResultSet rs = pstmt.executeQuery();

      // System.out.println("sql "+SQL);

      if (rs.next()) {
        promedioSeccion = rs.getDouble("valor");
      }
      rs.close();
      pstmt.close();

      if (promedioSeccion == 0.0) {
        String SQL2 =
            "SELECT AVG(AUX.A) valor FROM "
                + "(SELECT MAX(P.XX_SALEPRICE) A, P.M_PRODUCT_ID "
                + "FROM XX_VMR_PRICECONSECUTIVE P, M_PRODUCT M "
                + "WHERE ";

        if (conceptoComparar == null) {
          SQL2 += "M.XX_VME_ConceptValue_ID IS NULL and ";
        } else {
          SQL2 += "M.XX_VME_ConceptValue_ID=" + conceptoComparar + " and ";
        }

        SQL2 +=
            "M.XX_VMR_Line_ID = "
                + lineaProducto
                + " "
                +
                //				 			  "P.m_product_id <> "+ctx.getContext(WindowNo, "M_Product_ID")+" and "+
                "AND P.M_PRODUCT_ID = M.M_PRODUCT_ID "
                + "group by P.M_PRODUCT_ID) AUX";

        PreparedStatement pstmt2 = DB.prepareStatement(SQL2, null);
        ResultSet rs2 = pstmt2.executeQuery();
        // System.out.println("sql2"+SQL2);

        if (rs2.next()) {
          promedioLinea = rs2.getDouble("valor");
        }
        rs2.close();
        pstmt2.close();

        if (promedioLinea == 0.0) {
          String SQL3 =
              "SELECT AVG(AUX.A) valor FROM "
                  + "(SELECT MAX(P.XX_SALEPRICE) A, P.M_PRODUCT_ID "
                  + "FROM XX_VMR_PRICECONSECUTIVE P, m_product M "
                  + "WHERE ";

          if (conceptoComparar == null) {
            SQL2 += "M.XX_VME_ConceptValue_ID IS NULL and ";
          } else {
            SQL2 += "M.XX_VME_ConceptValue_ID=" + conceptoComparar + " and ";
          }

          SQL3 +=
              "M.XX_VMR_Department_ID = "
                  + departamentoProducto
                  + " "
                  +
                  //		 			  			 "P.m_product_id <> "+ctx.getContext(WindowNo, "M_Product_ID")+" and
                  // "+
                  "AND P.M_PRODUCT_ID = M.M_PRODUCT_ID "
                  + "group by P.M_PRODUCT_ID) AUX";

          PreparedStatement pstmt3 = DB.prepareStatement(SQL3, null);
          ResultSet rs3 = pstmt3.executeQuery();
          // System.out.println("TRES");
          if (rs3.next()) {
            promedioDepartamento = rs3.getDouble("valor");
          }
          rs3.close();
          pstmt3.close();
        }
      }

      Double promedio = promedioSeccion + promedioLinea + promedioDepartamento;

      System.out.println("Promedio -> " + promedio);

      // Si no tiene precio en depart, linea y seccion
      if (promedio == 0.0) {
        return "";
      }

      String SQLC =
          "SELECT * "
              + "FROM xx_vme_priceband P , xx_vme_conceptvalue C "
              + "WHERE C.xx_vme_conceptvalue_id = "
              + conceptoProducto
              + " AND "
              + "C.xx_vme_conceptvalue_id = P.xx_conceptvalue_id";

      pstmtC = DB.prepareStatement(SQLC, null);
      rsC = pstmtC.executeQuery();

      System.out.println(SQLC);

      if (rsC.next()) {
        Double precioProducto = new Double(ctx.getContext(WindowNo, "XX_SalePricePlusTax"));
        Double low = rsC.getDouble("xx_lowrank");
        Double high = rsC.getDouble("xx_highrank");

        // if((low-rsC.getDouble("xx_percentagevalue")) < 0 )
        // {
        //	low = new Double(0);
        // }

        Double percentage = rsC.getDouble("xx_percentagevalue");

        Double incrementaBanda = promedio * (percentage / 100);

        String operador = rsC.getString("xx_operating");

        DB.closeStatement(pstmtC);
        DB.closeResultSet(rsC);

        // Menor que 10000012
        // Mayor que 10000013

        C_OrderCallout precio = new C_OrderCallout();

        System.out.println(operador);

        if (operador.equals("Minor")) {
          // Double bandaMayor = (promedio - promedio*(low/100))+incrementaBanda;
          // Double bandaMenor = (promedio - promedio*(high/(100)))-incrementaBanda;

          BigDecimal doubleAux =
              new BigDecimal((promedio - promedio * (low / 100)) + incrementaBanda);
          doubleAux = doubleAux.setScale(2, BigDecimal.ROUND_HALF_UP);
          Double bandaMayor = doubleAux.doubleValue();

          doubleAux = new BigDecimal((promedio - promedio * (high / (100))) - incrementaBanda);
          doubleAux = doubleAux.setScale(2, BigDecimal.ROUND_HALF_UP);
          Double bandaMenor = doubleAux.doubleValue();

          if ((precioProducto <= bandaMayor) && (precioProducto >= bandaMenor)) {
            System.out.println(1);
            mTab.setValue("XX_CanSetDefinitive", "Y");
            return "";
          } else {
            // Si el precio no esta entre las bandas entonces no lo dejo colocar el precio como
            // definitivo
            mTab.setValue("XX_CanSetDefinitive", "N");
            return "Advertencia, el precio debe estar entre las bandas "
                + bandaMenor
                + " y "
                + bandaMayor
                + " Precio BECO bandas "
                + precio.priceBeco(new BigDecimal(bandaMenor))
                + " y "
                + PrecioBecoRebaja(new BigDecimal(bandaMayor));
          }
        }

        if (operador.equals("higher")) {
          // Double bandaMayor = (promedio + promedio*(high/(100))+incrementaBanda);
          // Double bandaMenor = (promedio + promedio*(low/100))-incrementaBanda;

          BigDecimal doubleAux =
              new BigDecimal((promedio + promedio * (high / (100)) + incrementaBanda));
          doubleAux = doubleAux.setScale(2, BigDecimal.ROUND_HALF_UP);
          Double bandaMayor = doubleAux.doubleValue();

          doubleAux = new BigDecimal((promedio + promedio * (low / 100)) - incrementaBanda);
          doubleAux = doubleAux.setScale(2, BigDecimal.ROUND_HALF_UP);
          Double bandaMenor = doubleAux.doubleValue();

          if ((precioProducto <= bandaMayor) && (precioProducto >= bandaMenor)) {
            System.out.println(2);
            mTab.setValue("XX_CanSetDefinitive", "Y");
            return "";
          } else {
            // Si el precio no esta entre las bandas entonces no lo dejo colocar el precio como
            // definitivo
            mTab.setValue("XX_CanSetDefinitive", "N");

            String message =
                "Advertencia, el precio deberia estar entre las bandas "
                    + ""
                    + bandaMenor
                    + " y "
                    + bandaMayor
                    + "Precio BECO bandas";
            // +precio.priceBeco(new BigDecimal(bandaMenor))+" y ";
            // + PrecioBecoRebaja(new BigDecimal(bandaMayor));

            return message;
          }
        }
      }

      return "";
    } catch (Exception e) {
      System.out.println("Error an la base de datos " + e.getMessage());
    } finally {
      DB.closeStatement(pstmtC);
      DB.closeResultSet(rsC);
    }

    return "";
  }
  public String priceBecoGlobal(
      Ctx ctx,
      int WindowNo,
      GridTab mTab,
      GridField mField,
      Object value,
      Object oldValue,
      int option,
      BigDecimal auxValue) {
    // System.out.println("priceBecoGlobal");
    try {
      BigDecimal precio;

      if (option == 1) precio = (BigDecimal) mTab.getValue("XX_SalePricePlusTax");
      else precio = auxValue;

      // VME_PriceProductCallout banda = new VME_PriceProductCallout();

      String priceRuleSQL =
          "select xx_lowrank,xx_highrank,xx_termination,xx_increase,xx_infinitevalue from xx_vme_pricerule order by (xx_lowrank)";
      PreparedStatement priceRulePstmt = DB.prepareStatement(priceRuleSQL, null);
      ResultSet priceRuleRs = priceRulePstmt.executeQuery();

      Integer precioInt = precio.intValue();
      BigDecimal precioBig = new BigDecimal(precioInt);
      while (priceRuleRs.next()) {
        if (precioBig.compareTo(priceRuleRs.getBigDecimal("xx_lowrank")) >= 0
            && precioBig.compareTo(priceRuleRs.getBigDecimal("xx_highrank")) <= 0) {
          Integer incremento = priceRuleRs.getInt("xx_increase");

          for (Integer i = priceRuleRs.getInt("xx_lowrank") - 1;
              i <= priceRuleRs.getInt("xx_highrank");
              i = i + incremento) {
            BigDecimal var = new BigDecimal(i);

            if (precioBig.compareTo(var) <= 0) {
              BigDecimal beco = var;

              BigDecimal terminacion = priceRuleRs.getBigDecimal("xx_termination");
              if (terminacion.intValue() == 0) {
                beco = var.add(terminacion);
              } else {
                var = var.divide(new BigDecimal(10));
                Integer aux = var.intValue() * 10;
                beco = new BigDecimal(aux).add(terminacion);
              }
              // mTab.setValue("PriceList", beco);
              priceRuleRs.close();
              priceRulePstmt.close();

              if (beco.compareTo(precio) == 0 && option != 5) {
                return ""; // ModifyPVP(ctx, WindowNo, mTab, mField,value);
              } else {
                // Jpires
                // lo llamo desde XX_CreateDiscountPDA. Si es 5 es q lo estoy llamando desde algo
                // que no es un callout x eso no lo seteo en el mTab
                if (option != 5) mTab.setValue("XX_SalePricePlusTax", beco);

                if (option == 1) {
                  // return banda.priceBandBeco(ctx, WindowNo, mTab, mField, value,
                  // oldValue);//banda.priceBandBeco(ctx, WindowNo, mTab, mField, value, oldValue);
                  return priceBandBeco(
                      ctx, WindowNo, mTab, mField, value,
                      oldValue); // banda.priceBandBeco(ctx, WindowNo, mTab, mField, value,
                  // oldValue);
                } else {
                  return beco.toString();
                }
              }
            }
          }
        }
      }
      priceRuleRs.close();
      priceRulePstmt.close();

      return ""; // ModifyPVP(ctx, WindowNo, mTab, mField,value);
    } catch (Exception e) {
      return e.getMessage();
    }
  }