void dynDepartament() {
    KeyNamePair cat = (KeyNamePair) categoryCombo.getSelectedItem();
    departmentCombo.removeActionListener(this);
    departmentCombo.removeAllItems();

    String sql = "SELECT XX_VMR_DEPARTMENT_ID, VALUE||'-'||NAME " + " FROM XX_VMR_DEPARTMENT ";

    if (cat != null && cat.getKey() != -1) {
      sql += " WHERE XX_VMR_CATEGORY_ID = " + cat.getKey();
    }
    sql += " ORDER BY VALUE||'-'||NAME ";
    sql = MRole.getDefault().addAccessSQL(sql, "", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(sql, null);
      rs = pstmt.executeQuery();

      departmentCombo.addItem(new KeyNamePair(-1, null));
      while (rs.next()) {
        departmentCombo.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
      }
      rs.close();
      pstmt.close();

      departmentCombo.addActionListener(this);
      departmentCombo.setEnabled(true);
      departmentCombo.setEditable(true);
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
  }
  public void generateLabels() {

    Cursor hourglassCursor = new Cursor(Cursor.WAIT_CURSOR);
    xProductTable.stopEditor(true);
    m_frame.setCursor(hourglassCursor);
    PrintService psZebra_glued = null;
    PrintService psZebra_flat = null;
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

    int id_label_glued = Env.getCtx().getContextAsInt("#XX_L_TYPELABELENGOMADA_ID");
    int id_label_flat = Env.getCtx().getContextAsInt("#XX_L_TYPELABELCOLGANTE_ID");

    int glued = 0, flats = 0;
    for (int row = 0; row < xProductTable.getRowCount(); row++) {
      IDColumn idcol = (IDColumn) xProductTable.getValueAt(row, 0);
      if (idcol != null && idcol.isSelected()) {
        KeyNamePair product_kp = (KeyNamePair) xProductTable.getValueAt(row, 3);
        MProduct product = new MProduct(Env.getCtx(), product_kp.getKey(), null);

        if (product.getXX_VMR_TypeLabel_ID() == id_label_glued) {
          glued++;
        } else if (product.getXX_VMR_TypeLabel_ID() == id_label_flat) {
          flats++;
        } else {
          X_XX_VMR_TypeLabel label_type =
              new X_XX_VMR_TypeLabel(Env.getCtx(), product.getXX_VMR_TypeLabel_ID(), null);

          String mss =
              Msg.getMsg(
                  Env.getCtx(),
                  "XX_WrongLabelType",
                  new String[] {label_type.getValue(), label_type.getName()});
          ADialog.error(m_WindowNo, m_frame, mss);
          dispose();
          return;
        }
      }
    }
    psZebra_glued = services[printer_glued];
    psZebra_flat = services[printer_flat];
    for (int row = 0; row < xProductTable.getRowCount(); row++) {
      IDColumn idcol = (IDColumn) xProductTable.getValueAt(row, 0);
      if (idcol != null && idcol.isSelected()) {
        KeyNamePair product_kp = (KeyNamePair) xProductTable.getValueAt(row, 3);
        MProduct product = new MProduct(Env.getCtx(), product_kp.getKey(), null);

        if (product.getXX_VMR_TypeLabel_ID() == id_label_glued) {
          print_labels(psZebra_glued, row, true);
        } else {
          print_labels(psZebra_flat, row, false);
        }
      }
    }
    if (flats + glued > 0) {
      ADialog.info(m_WindowNo, m_frame, "XX_PrintedLabels");
    }
    dispose();
  }
  private final void actionPerformed0(ActionEvent e) throws Exception {
    // Select Instance
    if (e.getSource() == bSelectExistingASI) {
      cmd_select();
      return;
    }
    // New/Edit
    else if (e.getSource() == cbNewEdit) {
      cmd_newEdit();
    }
    // Select Lot from existing
    else if (e.getSource() == fieldLot) {
      final KeyNamePair pp = fieldLot.getSelectedItem();
      if (pp != null && pp.getKey() != -1) {
        fieldLotString.setText(pp.getName());
        fieldLotString.setEditable(false);
        asiTemplate.setM_Lot_ID(pp.getKey());
      } else {
        fieldLotString.setEditable(true);
        asiTemplate.setM_Lot_ID(0);
      }
    }
    // Create New Lot
    else if (e.getSource() == bLot) {
      KeyNamePair pp = asiTemplate.createLot(m_M_Product_ID);
      if (pp != null) {
        fieldLot.addItem(pp);
        fieldLot.setSelectedItem(pp);
      }
    }
    // Create New SerNo
    else if (e.getSource() == bSerNo) {
      fieldSerNo.setText(asiTemplate.getSerNo(true));
    }

    // OK
    else if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
      final MAttributeSetInstance asi = saveSelection();
      final int M_Locator_ID = -1; // N/A
      setResultAndDispose(asi, M_Locator_ID);
      return;
    }
    // Cancel
    else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
      final int M_Locator_ID = -1; // N/A
      setResultAndDispose(null, M_Locator_ID);
    }
    // Zoom M_Lot
    else if (e.getSource() == mZoom) {
      cmd_zoom();
    } else {
      log.log(Level.SEVERE, "Unknown event: {0}", e);
    }
  } // actionPerformed
예제 #4
0
  /**
   * Table selection changed
   *
   * @param e event
   */
  public void valueChanged(ListSelectionEvent e) {
    m_M_AttributeSetInstance_ID = -1;
    m_M_AttributeSetInstanceName = null;
    m_M_Locator_ID = 0;

    int row = m_table.getSelectedRow();
    if (row > -1) {
      Integer ID = m_table.getSelectedRowKey();
      if (ID != null) {
        m_M_AttributeSetInstance_ID = ID.intValue();
        m_M_AttributeSetInstanceName = (String) m_table.getValueAt(row, 1);
        //
        Object oo = m_table.getValueAt(row, 5);
        if (oo instanceof KeyNamePair) {
          KeyNamePair pp = (KeyNamePair) oo;
          m_M_Locator_ID = pp.getKey();
        }
      }
    }
    log.fine(
        "M_AttributeSetInstance_ID="
            + m_M_AttributeSetInstance_ID
            + " - "
            + m_M_AttributeSetInstanceName
            + "; M_Locator_ID="
            + m_M_Locator_ID);

    enableButtons();
  }
예제 #5
0
 /**
  * Get BPartner Contact
  *
  * @return AD_User_ID
  */
 public int getAD_User_ID() {
   if (m_bpartner != null) {
     KeyNamePair pp = (KeyNamePair) f_user.getSelectedItem();
     if (pp != null) return pp.getKey();
   }
   return 0;
 } //	getC_BPartner_Location_ID
예제 #6
0
  /**
   * ************************************************************************ Action Listener
   *
   * @param e event
   */
  public void actionPerformed(ActionEvent e) {
    //  don't requery if fieldValue and fieldName are empty
    if ((e.getSource() == pickWarehouse || e.getSource() == pickPriceList)
        && (fieldValue.getText().length() == 0 && fieldName.getText().length() == 0)) return;

    //	Product Attribute Search
    if (e.getSource().equals(m_InfoPAttributeButton)) {
      cmd_InfoPAttribute();
      return;
    }
    m_pAttributeWhere = null;

    //	Query Product Attribute Instance
    int row = p_table.getSelectedRow();
    if (e.getSource().equals(m_PAttributeButton) && row != -1) {
      Integer productInteger = getSelectedRowKey();
      String productName = (String) p_table.getValueAt(row, INDEX_NAME);
      KeyNamePair warehouse = (KeyNamePair) pickWarehouse.getSelectedItem();
      if (productInteger == null || productInteger.intValue() == 0 || warehouse == null) return;
      String title = warehouse.getName() + " - " + productName;
      IPAttributeInstance pai =
          PAttributeInstance.get(
              this, title, warehouse.getKey(), 0, productInteger.intValue(), m_C_BPartner_ID);
      m_M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
      m_M_Locator_ID = pai.getM_Locator_ID();
      if (m_M_AttributeSetInstance_ID != -1) dispose(true);
      return;
    }
    //
    super.actionPerformed(e);
  } //  actionPerformed
  /** Associate Button Pressed */
  private void cmd_associate() {
    int productRow = xProductTable.getSelectedRow();
    log.config("Row=" + productRow);

    KeyNamePair product = (KeyNamePair) xProductTable.getValueAt(productRow, 0);

    doInsert(product.getKey(), 0);

    //  ** Load Table **
    tableInit_option = 1;
    tableInit();
    tableLoad(xAssociateTable);

    //  ** Load Table **
    tableInit_option = 2;
    tableInit();
    tableLoad(xProductTable);

    bDisassociate.setEnabled(true);
    bNewProduct.setEnabled(false);

    // Coloco la referencia como asociada
    // MVMRVendorProdRef vendorProdRef = new MVMRVendorProdRef(Env.getCtx(),
    // LineRefProv.getXX_VMR_VendorProdRef_ID(), null);
    // vendorProdRef.setXX_IsAssociated(true);
    // vendorProdRef.save();

  } //  cmd_associate
예제 #8
0
 /**
  * Set Warehouse
  *
  * @param M_Warehouse_ID warehouse
  */
 private void setWarehouse(int M_Warehouse_ID) {
   for (int i = 0; i < pickWarehouse.getItemCount(); i++) {
     KeyNamePair kn = (KeyNamePair) pickWarehouse.getItemAt(i);
     if (kn.getKey() == M_Warehouse_ID) {
       pickWarehouse.setSelectedIndex(i);
       return;
     }
   }
 } //	setWarehouse
예제 #9
0
 /**
  * Set PriceList
  *
  * @param M_PriceList_Version_ID price list
  */
 private void setPriceListVersion(int M_PriceList_Version_ID) {
   log.config("M_PriceList_Version_ID=" + M_PriceList_Version_ID);
   for (int i = 0; i < pickPriceList.getItemCount(); i++) {
     KeyNamePair kn = (KeyNamePair) pickPriceList.getItemAt(i);
     if (kn.getKey() == M_PriceList_Version_ID) {
       pickPriceList.setSelectedIndex(i);
       return;
     }
   }
   log.fine("NOT found");
 } //	setPriceList
예제 #10
0
 @Override
 public int getContextVariableAsInt(final String name) {
   final Object value = getContextVariable(name);
   if (value == null) {
     return -1;
   } else if (value instanceof Number) {
     return ((Number) value).intValue();
   } else if (value instanceof KeyNamePair) {
     final KeyNamePair knp = (KeyNamePair) value;
     if (knp.getKey() <= 0 && Check.isEmpty(knp.getName())) {
       return -1;
     } else {
       return knp.getKey();
     }
   } else {
     try {
       return Integer.parseInt(value.toString());
     } catch (final Exception e) {
       log.log(Level.WARNING, "Cannot convert " + value + " to integer", e);
     }
   }
   return -1;
 }
예제 #11
0
 /**
  * Parent Constructor
  *
  * @param client client
  * @param currency currency
  */
 public MAcctSchema(MClient client, KeyNamePair currency) {
   this(client.getCtx(), 0, client.get_TrxName());
   setClientOrg(client);
   setC_Currency_ID(currency.getKey());
   StringBuilder msgset =
       new StringBuilder()
           .append(client.getName())
           .append(" ")
           .append(getGAAP())
           .append("/")
           .append(get_ColumnCount())
           .append(" ")
           .append(currency.getName());
   setName(msgset.toString());
 } //	MAcctSchema
예제 #12
0
 /** Show History */
 protected void showHistory() {
   log.info("");
   Integer M_Product_ID = getSelectedRowKey();
   if (M_Product_ID == null) return;
   KeyNamePair kn = (KeyNamePair) pickWarehouse.getSelectedItem();
   int M_Warehouse_ID = kn.getKey();
   int M_AttributeSetInstance_ID = m_M_AttributeSetInstance_ID;
   if (m_M_AttributeSetInstance_ID < -1) // 	not selected
   M_AttributeSetInstance_ID = 0;
   //
   InvoiceHistory ih =
       new InvoiceHistory(
           this, 0, M_Product_ID.intValue(), M_Warehouse_ID, M_AttributeSetInstance_ID);
   ih.setVisible(true);
   ih = null;
 } //	showHistory
예제 #13
0
  /**
   * ************************************************************************ Construct SQL Where
   * Clause and define parameters (setParameters needs to set parameters) Includes first AND
   *
   * @return SQL WHERE clause
   */
  protected String getSQLWhere() {
    StringBuffer where = new StringBuffer();

    //	Optional PLV
    int M_PriceList_Version_ID = 0;
    KeyNamePair pl = (KeyNamePair) pickPriceList.getSelectedItem();
    if (pl != null) M_PriceList_Version_ID = pl.getKey();
    if (M_PriceList_Version_ID != 0) where.append(" AND pr.M_PriceList_Version_ID=?");

    //  Optional Product Category
    if (getM_Product_Category_ID() > 0) {
      where.append(" AND p.M_Product_Category_ID=?");
    }

    //  Optional Attribute Set
    if (getM_AttributeSet_ID() > 0) {
      where.append(" AND p.M_AttributeSet_ID=?");
    }

    //	Product Attribute Search
    if (m_pAttributeWhere != null) {
      where.append(m_pAttributeWhere);
      return where.toString();
    }

    //  => Value
    String value = fieldValue.getText().toUpperCase();
    if (!(value.equals("") || value.equals("%"))) where.append(" AND UPPER(p.Value) LIKE ?");

    //  => Name
    String name = fieldName.getText().toUpperCase();
    if (!(name.equals("") || name.equals("%"))) where.append(" AND UPPER(p.Name) LIKE ?");

    //  => UPC
    String upc = fieldUPC.getText().toUpperCase();
    if (!(upc.equals("") || upc.equals("%"))) where.append(" AND UPPER(p.UPC) LIKE ?");

    //  => SKU
    String sku = fieldSKU.getText().toUpperCase();
    if (!(sku.equals("") || sku.equals("%"))) where.append(" AND UPPER(p.SKU) LIKE ?");
    //	=> Vendor
    String vendor = fieldVendor.getText().toUpperCase();
    if (!(vendor.equals("") || vendor.equals("%")))
      where.append(" AND UPPER(bp.Name) LIKE ? AND ppo.IsCurrentVendor='Y'");

    return where.toString();
  } //	getSQLWhere
예제 #14
0
  /** Query Info */
  public void executeQuery(KeyNamePair docTypeKNPair, IMiniTable miniTable) {
    log.info("");
    int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
    //  Create SQL

    String sql = "";

    if (docTypeKNPair.getKey() == MOrder.Table_ID) {
      sql = getOrderSQL();
    } else {
      sql = getRMASql();
    }

    //  reset table
    int row = 0;
    miniTable.setRowCount(row);
    //  Execute
    try {
      PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
      pstmt.setInt(1, AD_Client_ID);
      ResultSet rs = pstmt.executeQuery();
      //
      while (rs.next()) {
        //  extend table
        miniTable.setRowCount(row + 1);
        //  set values
        miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0); //  C_Order_ID
        miniTable.setValueAt(rs.getString(2), row, 1); //  Org
        miniTable.setValueAt(rs.getString(3), row, 2); //  DocType
        miniTable.setValueAt(rs.getString(4), row, 3); //  Doc No
        miniTable.setValueAt(rs.getString(5), row, 4); //  BPartner
        miniTable.setValueAt(rs.getTimestamp(6), row, 5); //  DateOrdered
        miniTable.setValueAt(rs.getBigDecimal(7), row, 6); //  TotalLines
        //  prepare next
        row++;
      }
      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql.toString(), e);
    }
    //
    miniTable.autoSize();
    //	statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
  } //  executeQuery
 /**
  * Check availability and insert record
  *
  * @return true if saved/updated
  */
 private boolean cmd_save() {
   log.config("");
   //	Set AssignDateTo
   Calendar date = new GregorianCalendar();
   getDateAndTimeFrom(date);
   Timestamp assignDateFrom = new Timestamp(date.getTimeInMillis());
   BigDecimal qty = fQty.getValue();
   ListItem listItem = fResource.getSelectedItem();
   KeyNamePair resource =
       listItem != null
           ? new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel())
           : null;
   KeyNamePair uom = (KeyNamePair) m_lookup.get(resource);
   int minutes = MUOMConversion.convertToMinutes(Env.getCtx(), uom.getKey(), qty);
   Timestamp assignDateTo = TimeUtil.addMinutess(assignDateFrom, minutes);
   m_mAssignment.setAssignDateTo(assignDateTo);
   //
   //	m_mAssignment.dump();
   return m_mAssignment.save();
 } //	cmdSave
  /** Initialize component & values from m_mAssignment */
  private void setDisplay() {
    m_setting = true;

    //	Set Resource
    int S_Resource_ID = m_mAssignment.getS_Resource_ID();

    for (ListItem item : fResource.getItems()) {
      if ((Integer) item.getValue() == S_Resource_ID) {
        fResource.setSelectedItem(item);
        break;
      }
    }

    ListItem listItem = fResource.getSelectedItem();
    KeyNamePair check = new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel());
    if (check == null || check.getKey() != S_Resource_ID) {
      if (m_mAssignment.getS_ResourceAssignment_ID() == 0) // 	new record select first
      fResource.setSelectedItem(fResource.getSelectedItem()); // 	initiates UOM display
      else log.log(Level.SEVERE, "Resource not found ID=" + S_Resource_ID);
    }

    //	Set Date, Qty
    fDateFrom.setValue(m_mAssignment.getAssignDateFrom());
    fTimeFrom.setValue(m_mAssignment.getAssignDateFrom());
    fQty.setValue(m_mAssignment.getQty());

    //	Name, Description
    fName.setValue(m_mAssignment.getName());
    fDescription.setValue(m_mAssignment.getDescription());

    //	Set Editor to R/O if confirmed
    boolean readWrite = true;
    if (m_mAssignment.isConfirmed()) readWrite = false;
    confirmPanel.getButton("Cancel").setVisible(readWrite);
    fResource.setEnabled(readWrite);
    fDateFrom.setReadonly(!readWrite);
    fQty.setEnabled(readWrite);

    m_setting = false;
  } //	dynInit
 /** Zoom M_Lot */
 private void cmd_zoom() {
   int M_Lot_ID = 0;
   KeyNamePair pp = fieldLot.getSelectedItem();
   if (pp != null) M_Lot_ID = pp.getKey();
   MQuery zoomQuery = new MQuery("M_Lot");
   zoomQuery.addRestriction("M_Lot_ID", MQuery.EQUAL, M_Lot_ID);
   log.info(zoomQuery.toString());
   //
   setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   //
   int AD_Window_ID = 257; // Lot
   AWindow frame = new AWindow();
   if (frame.initWindow(AD_Window_ID, zoomQuery)) {
     this.setVisible(false);
     this.setModal(false); // otherwise blocked
     this.setVisible(true);
     AEnv.addToWindowManager(frame);
     AEnv.showScreen(frame, SwingConstants.EAST);
   }
   // async window - not able to get feedback
   frame = null;
   //
   setCursor(Cursor.getDefaultCursor());
 } // cmd_zoom
  /** Initialize all panel fields and editors based on {@link #asiTemplate}. */
  private final void initAttributes() {
    final Properties ctx = getCtx();
    final boolean isProductWindow = isProductWindow();
    final boolean isProcessParameter = isProcessParameter();
    final boolean isPureProductASI = isPureProductASI();
    final boolean allowSelectExistingASI = isAllowSelectExistingASI();
    final MAttributeSet as = asiTemplate.getMAttributeSet();
    Check.assumeNotNull(as, "attribute set not null");
    final boolean isASITemplateNew = asiTemplate.getM_AttributeSetInstance_ID() <= 0;

    //
    // Show Select existing ASI (if allowed)
    if (allowSelectExistingASI) {
      // New/Edit - Selection
      if (isASITemplateNew) // new ASI
      cbNewEdit.setText(msgBL.getMsg(ctx, "NewRecord"));
      else cbNewEdit.setText(msgBL.getMsg(ctx, "EditRecord"));
      cbNewEdit.addActionListener(this);
      centerPanel.add(cbNewEdit, new ALayoutConstraint(m_row++, 0));
      bSelectExistingASI.setText(msgBL.getMsg(ctx, "SelectExisting"));
      bSelectExistingASI.addActionListener(this);
      centerPanel.add(bSelectExistingASI, null);
    }

    //
    // Fetch M_Attributes
    final List<MAttribute> attributes;
    if (isProductWindow) {
      attributes = Arrays.asList(as.getMAttributes(false)); // non-instance attributes
    } else if (isPureProductASI) {
      // Regular product's attribute set instance attributes
      attributes = Arrays.asList(as.getMAttributes(true)); // all instance attributes
    } else if (isProcessParameter) {
      final IQueryBuilder<MAttribute> attributesQueryBuilder =
          queryBL
              .createQueryBuilder(MAttribute.class)
              .setContext(ctx, ITrx.TRXNAME_None)
              .addOnlyActiveRecordsFilter()
              .addOnlyContextClient();
      attributesQueryBuilder
          .orderBy()
          .addColumn(I_M_Attribute.COLUMNNAME_Name)
          .addColumn(I_M_Attribute.COLUMNNAME_M_Attribute_ID);
      attributes = attributesQueryBuilder.create().list(MAttribute.class);
    } else {
      attributes = Collections.emptyList();
    }

    //
    // Create attributes UI editors
    for (final MAttribute attribute : attributes) {
      if (!attributeExcludeBL.isExcludedAttribute(
          attribute, as, m_AD_Column_ID, attributeContext.isSOTrx())) {
        addAttributeLine(attribute);
      }
    }

    //
    // Lot
    if (isPureProductASI && as.isLot()) {
      CLabel label = new CLabel(msgBL.translate(ctx, "Lot"));
      label.setLabelFor(fieldLotString);
      centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldLotString, null);
      fieldLotString.setText(asiTemplate.getLot());
      // M_Lot_ID
      // int AD_Column_ID = 9771; // M_AttributeSetInstance.M_Lot_ID
      // fieldLot = new VLookup ("M_Lot_ID", false,false, true,
      // MLookupFactory.get(getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir));
      final String sql =
          "SELECT M_Lot_ID, Name "
              + "FROM M_Lot l "
              + "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p "
              + "WHERE p.M_AttributeSet_ID="
              + asiTemplate.getM_AttributeSet_ID()
              + " AND p.M_Product_ID=l.M_Product_ID)";
      fieldLot = new CComboBox<>(DB.getKeyNamePairs(sql, true));
      label = new CLabel(msgBL.translate(ctx, "M_Lot_ID"));
      label.setLabelFor(fieldLot);
      centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldLot, null);
      if (asiTemplate.getM_Lot_ID() > 0) {
        for (int i = 1; i < fieldLot.getItemCount(); i++) {
          KeyNamePair pp = fieldLot.getItemAt(i);
          if (pp.getKey() == asiTemplate.getM_Lot_ID()) {
            fieldLot.setSelectedIndex(i);
            fieldLotString.setEditable(false);
            break;
          }
        }
      }
      fieldLot.addActionListener(this);
      // New Lot Button
      if (asiTemplate.getMAttributeSet().getM_LotCtl_ID() > 0) {
        if (Env.getUserRolePermissions().isTableAccess(MLot.Table_ID, false)
            && Env.getUserRolePermissions().isTableAccess(MLotCtl.Table_ID, false)
            && !asiTemplate.isExcludeLot(m_AD_Column_ID, attributeContext.isSOTrx())) {
          centerPanel.add(bLot, null);
          bLot.addActionListener(this);
        }
      }
      // Popup
      fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this)); // popup
      mZoom = new CMenuItem(msgBL.getMsg(ctx, "Zoom"), Images.getImageIcon2("Zoom16"));
      mZoom.addActionListener(this);
      popupMenu.add(mZoom);
    } // Lot

    //
    // SerNo
    if (isPureProductASI && as.isSerNo()) {
      CLabel label = new CLabel(msgBL.translate(ctx, "SerNo"));
      label.setLabelFor(fieldSerNo);
      fieldSerNo.setText(asiTemplate.getSerNo());
      centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldSerNo, null);
      // New SerNo Button
      if (asiTemplate.getMAttributeSet().getM_SerNoCtl_ID() != 0) {
        if (Env.getUserRolePermissions().isTableAccess(MSerNoCtl.Table_ID, false)
            && !asiTemplate.isExcludeSerNo(m_AD_Column_ID, attributeContext.isSOTrx())) {
          centerPanel.add(bSerNo, null);
          bSerNo.addActionListener(this);
        }
      }
    } // SerNo

    //
    // GuaranteeDate.
    // We are displaying it if we deal with a pure product ASI (i.e. user is not editing the ASI
    // from product window),
    // and if:
    // * the attribute set requires a GuaranteeDate
    // * or if the ASI has a GuaranteeDate already set
    if (isPureProductASI && (as.isGuaranteeDate() || asiTemplate.getGuaranteeDate() != null)) {
      CLabel label = new CLabel(msgBL.translate(ctx, "GuaranteeDate"));
      label.setLabelFor(fieldGuaranteeDate);
      if (isASITemplateNew) {
        Date guaranteeDate = asiTemplate.getGuaranteeDate();
        if (guaranteeDate == null) {
          guaranteeDate =
              attributesBL.calculateBestBeforeDate(
                  ctx,
                  m_M_Product_ID, // product
                  attributeContext.getC_BPartner_ID(), // vendor bpartner
                  Env.getDate(ctx) // dateReceipt
                  );
        }
        fieldGuaranteeDate.setValue(guaranteeDate);
      } else {
        fieldGuaranteeDate.setValue(asiTemplate.getGuaranteeDate());
      }
      centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldGuaranteeDate, null);
      fieldGuaranteeDateDisplayed = true;
    } // GuaranteeDate

    // Make sure we have at least something to edit or something to select,
    // else there is no point in showing empty this window.
    if (m_row == 0) {
      throw new AdempiereException("@PAttributeNoInfo@");
    }

    //
    // New/Edit Window
    if (allowSelectExistingASI) {
      cbNewEdit.setSelected(isASITemplateNew);
      cmd_newEdit();
    }

    //
    // Attrribute Set Instance Description
    {
      final CLabel labelDescription = new CLabel(msgBL.translate(ctx, "Description"));
      labelDescription.setLabelFor(fieldDescription);
      fieldDescription.setText(asiTemplate.getDescription());
      fieldDescription.setEditable(false);
      centerPanel.add(labelDescription, new ALayoutConstraint(m_row++, 0));
      centerPanel.add(fieldDescription, null);
    }

    // Window usually to wide (??)
    {
      final Dimension dd = centerPanel.getPreferredSize();
      dd.width = Math.min(500, dd.width);
      centerPanel.setPreferredSize(dd);
    }
  } // initAttribute
  public void print_labels(PrintService psZebra, int row, boolean glued) {
    try {

      IDColumn column = (IDColumn) xProductTable.getValueAt(row, 0);
      KeyNamePair knp_product = (KeyNamePair) xProductTable.getValueAt(row, 3);
      KeyNamePair knp_att = (KeyNamePair) xProductTable.getValueAt(row, 11);

      MVMRDiscountAppliDetail detail =
          new MVMRDiscountAppliDetail(Env.getCtx(), column.getRecord_ID(), null);

      int cantidadEtiquetas = ((Number) xProductTable.getValueAt(row, 6)).intValue();

      MProduct producto = new MProduct(Env.getCtx(), knp_product.getKey(), null);
      String name = producto.getName();
      /*
       * Caracteristica larga
       * */
      X_XX_VMR_LongCharacteristic caracLarga =
          new X_XX_VMR_LongCharacteristic(
              Env.getCtx(), producto.getXX_VMR_LongCharacteristic_ID(), null);
      X_M_AttributeSet attrSet =
          new X_M_AttributeSet(Env.getCtx(), producto.getM_AttributeSet_ID(), null);

      DecimalFormat formato = new DecimalFormat(".##");

      // String attr = "AMARILLO T=G                  ";
      // "CHEMISE CABALLERO             "

      X_XX_VMR_Department dep =
          new X_XX_VMR_Department(Env.getCtx(), producto.getXX_VMR_Department_ID(), null);
      String departmentCode = dep.getValue();

      X_XX_VMR_Line lin = new X_XX_VMR_Line(Env.getCtx(), producto.getXX_VMR_Line_ID(), null);
      String lineCode = lin.getValue();

      X_XX_VMR_Section sec =
          new X_XX_VMR_Section(Env.getCtx(), producto.getXX_VMR_Section_ID(), null);
      String seccionCode = sec.getValue();
      String precio = formato.format(detail.getXX_PriceBeforeDiscount());

      MVMRDiscountRequest headerDiscount =
          new MVMRDiscountRequest(Env.getCtx(), detail.getXX_VMR_DiscountRequest_ID(), null);
      MWarehouse tienda = new MWarehouse(Env.getCtx(), headerDiscount.getM_Warehouse_ID(), null);

      X_XX_VMR_PriceConsecutive consecutivoViejo =
          new X_XX_VMR_PriceConsecutive(Env.getCtx(), detail.getXX_VMR_PriceConsecutive_ID(), null);
      // Debo buscar semana, mes y año de la fecha de creacion del consecutivo

      Date date = (Date) consecutivoViejo.getCreated();
      Calendar cal = new GregorianCalendar();
      cal.setTime(date);
      int mes = cal.get(Calendar.MONTH) + 1;
      int año = cal.get(Calendar.YEAR);
      int semana = cal.get(Calendar.WEEK_OF_YEAR);

      BigDecimal impuesto = new BigDecimal(0);

      if (producto.getC_TaxCategory_ID() != 0) {

        String sql_rate =
            " SELECT (RATE) FROM C_TAX "
                + " WHERE C_TaxCategory_ID= "
                + producto.getC_TaxCategory_ID()
                + " AND ValidFrom <= to_date('"
                + date.toString().substring(0, 10)
                + "','yyyy-mm-dd')"
                + " and rownum = 1 "
                + " order by ValidFrom desc ";
        try {
          PreparedStatement prst_tax = DB.prepareStatement(sql_rate, null);
          ResultSet rs_tax = prst_tax.executeQuery();
          if (rs_tax.next()) {

            impuesto = rs_tax.getBigDecimal(1).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
          }
          rs_tax.close();
          prst_tax.close();
        } catch (Exception e) {
          System.out.println("error al calcular el impuesto");
        }
      }

      String product_plus_correlative =
          "" + producto.getValue() + consecutivoTostring(consecutivoViejo.getXX_PriceConsecutive());

      String s = "";
      DocPrintJob job = psZebra.createPrintJob();

      if (impuesto.compareTo(new BigDecimal(0)) > 0) {
        precio =
            formato.format(
                (detail
                        .getXX_PriceBeforeDiscount()
                        .add((detail.getXX_PriceBeforeDiscount()).multiply(impuesto)))
                    .setScale(2, BigDecimal.ROUND_HALF_UP));
        s =
            "^XA^PRD^XZ\n"
                + "^XA^JMA^\n"
                + "^LH07,02^FS\n"
                + "^FO10,03^BE,25,N^BY3, 0.5,45^FD"
                + product_plus_correlative
                + "^FS\n"
                + "^FO10,62^AA,15,12^FD"
                + departmentCode
                + "-"
                + lineCode
                + "-"
                + seccionCode
                + "-"
                + product_plus_correlative
                + "       ^FS\n"
                + "^FO10,82^AA,20,10^FD"
                + name
                + "^FS\n";
        if (!attrSet.getName().isEmpty()
            && attrSet.get_ID() != Env.getCtx().getContextAsInt("#XX_L_P_ATTRIBUTESETST_ID")) {
          s =
              s
                  + "^FO10,97^AA,20,10^FD"
                  + (attrSet.getName().length() > 30
                      ? attrSet.getName().substring(0, 29)
                      : attrSet.getName())
                  + "^FS\n";
        } else if (caracLarga != null
            && caracLarga.getName() != null
            && !caracLarga.getName().isEmpty()) {
          s =
              s
                  + "^FO10,97^AA,20,10^FD"
                  + (caracLarga.getName().length() > 30
                      ? caracLarga.getName().substring(0, 29)
                      : caracLarga.getName())
                  + "^FS\n";
        }
        s =
            s
                + "^FO10,116^AA,14,10^FDPRECIO BS^FS\n"
                + "^FO10,170^AB,11,07^FDRIF J-00046517-7   Incluye IVA "
                + impuesto.multiply(new BigDecimal(100))
                + "%^FS\n"
                + "^FO10,153^AB,11,07^CI10^FD"
                + semana
                + " "
                + mes
                + " "
                + año
                + "^FS\n"
                + "^FO10,138^AA,11,09^FDBsF.^FS\n"
                + "^FO35,136^AB,11,07^CI10^FD         "
                + precio
                + "^FS\n"
                + "^PQ"
                + cantidadEtiquetas
                + "^FS\n"
                + "^XZ\n"
                +
                // Control label
                "^XA^PRD^XZ\n"
                + "^XA^JMA^\n"
                + "^LH00,15^FS\n"
                + "^FO2,5^AD,38,10^FD*CONTROL*     "
                + semana
                + " "
                + mes
                + ""
                + año
                + "^FS\n"
                + "^FO05,45^A0,30,07^FD                  TDA:  "
                + tienda.getValue()
                + "^FS\n"
                + "^FO28,48^A0,15,14^FDCANT:     "
                + cantidadEtiquetas
                + "      PRECIO      "
                + precio
                + "^FS\n"
                + "^FO05,95^A0,18,10^FD"
                + departmentCode
                + "-"
                + lineCode
                + "-"
                + seccionCode
                + "- "
                + product_plus_correlative
                + "^FS\n"
                + "^FO05,120^A0,18,10^FD"
                + name
                + "^FS\n"
                + "^FO05,140^A0,18,10^FD                                                  ^FS\n"
                + "^PQ1^FS\n"
                + "^XZ";
      } else {
        s =
            "^XA^PRD^XZ\n"
                + "^XA^JMA^\n"
                + "^LH07,02^FS\n"
                + "^FO10,03^BE,25,N^BY3, 0.5,45^FD"
                + product_plus_correlative
                + "^FS\n"
                + "^FO10,62^AA,15,12^FD"
                + departmentCode
                + "-"
                + lineCode
                + "-"
                + seccionCode
                + "-"
                + product_plus_correlative
                + "       ^FS\n"
                + "^FO10,82^AA,20,10^FD"
                + name
                + "^FS\n"
                + "^FO10,97^AA,20,10^FD                                                  ^FS\n"
                + "^FO10,116^AA,14,10^FDPRECIO BS^FS\n"
                + "^FO10,170^AB,11,07^FDRIF J-00046517-7   Exento de Iva%^FS\n"
                + "^FO10,153^AB,11,07^CI10^FD"
                + semana
                + " "
                + mes
                + " "
                + año
                + "^FS\n"
                + "^FO10,138^AA,11,09^FDBsF.^FS\n"
                + "^FO35,136^AB,11,07^CI10^FD         "
                + precio
                + "^FS\n"
                + "^PQ"
                + cantidadEtiquetas
                + "^FS\n"
                + "^XZ\n"
                +
                // Control label
                "^XA^PRD^XZ\n"
                + "^XA^JMA^\n"
                + "^LH00,15^FS\n"
                + "^FO2,5^AD,38,10^FD*CONTROL*     "
                + semana
                + " "
                + mes
                + ""
                + año
                + "^FS\n"
                + "^FO05,45^A0,30,07^FD                  TDA:  "
                + tienda.getValue()
                + "^FS\n"
                + "^FO28,48^A0,15,14^FDCANT:     "
                + cantidadEtiquetas
                + "      PRECIO      "
                + precio
                + "^FS\n"
                + "^FO05,95^A0,18,10^FD"
                + departmentCode
                + "-"
                + lineCode
                + "-"
                + seccionCode
                + "- "
                + product_plus_correlative
                + "^FS\n"
                + "^FO05,120^A0,18,10^FD"
                + name
                + "^FS\n"
                + "^FO05,140^A0,18,10^FD                                                  ^FS\n"
                + "^PQ1^FS\n"
                + "^XZ";
      }

      byte[] by = s.getBytes();
      DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
      Doc doc = new SimpleDoc(by, flavor, null);
      job.print(doc, null);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #20
0
  /**
   * Set Parameters for Query (as defined in getSQLWhere)
   *
   * @param pstmt pstmt
   * @param forCount for counting records
   * @throws SQLException
   */
  protected void setParameters(PreparedStatement pstmt, boolean forCount) throws SQLException {
    int index = 1;

    //  => Warehouse
    int M_Warehouse_ID = 0;
    KeyNamePair wh = (KeyNamePair) pickWarehouse.getSelectedItem();
    if (wh != null) M_Warehouse_ID = wh.getKey();
    if (!forCount) //	parameters in select
    {
      for (int i = 0; i < p_layout.length; i++) {
        if (p_layout[i].getColSQL().indexOf('?') != -1) pstmt.setInt(index++, M_Warehouse_ID);
      }
    }
    log.fine("M_Warehouse_ID=" + M_Warehouse_ID + " (" + (index - 1) + "*)");

    //  => PriceList
    int M_PriceList_Version_ID = 0;
    KeyNamePair pl = (KeyNamePair) pickPriceList.getSelectedItem();
    if (pl != null) M_PriceList_Version_ID = pl.getKey();
    if (M_PriceList_Version_ID != 0) {
      pstmt.setInt(index++, M_PriceList_Version_ID);
      log.fine("M_PriceList_Version_ID=" + M_PriceList_Version_ID);
    }
    //  => Product Category
    int M_Product_Category_ID = getM_Product_Category_ID();
    if (M_Product_Category_ID > 0) {
      pstmt.setInt(index++, M_Product_Category_ID);
      log.fine("M_Product_Category_ID=" + M_Product_Category_ID);
    }
    //  => Attribute Set - @Trifon
    int M_AttributeSet_ID = getM_AttributeSet_ID();
    if (M_AttributeSet_ID > 0) {
      pstmt.setInt(index++, M_AttributeSet_ID);
      log.fine("M_AttributeSet_ID=" + M_AttributeSet_ID);
    }
    //	Rest of Parameter in Query for Attribute Search
    if (m_pAttributeWhere != null) return;

    //  => Value
    String value = fieldValue.getText().toUpperCase();
    if (!(value.equals("") || value.equals("%"))) {
      if (!value.endsWith("%")) value += "%";
      pstmt.setString(index++, value);
      log.fine("Value: " + value);
    }

    //  => Name
    String name = fieldName.getText().toUpperCase();
    if (!(name.equals("") || name.equals("%"))) {
      if (!name.endsWith("%")) name += "%";
      pstmt.setString(index++, name);
      log.fine("Name: " + name);
    }

    //  => UPC
    String upc = fieldUPC.getText().toUpperCase();
    if (!(upc.equals("") || upc.equals("%"))) {
      if (!upc.endsWith("%")) upc += "%";
      pstmt.setString(index++, upc);
      log.fine("UPC: " + upc);
    }

    //  => SKU
    String sku = fieldSKU.getText().toUpperCase();
    if (!(sku.equals("") || sku.equals("%"))) {
      if (!sku.endsWith("%")) sku += "%";
      pstmt.setString(index++, sku);
      log.fine("SKU: " + sku);
    }

    //  => Vendor
    String vendor = fieldVendor.getText().toUpperCase();
    if (!(vendor.equals("") || vendor.equals("%"))) {
      if (!vendor.endsWith("%")) vendor += "%";
      pstmt.setString(index++, vendor);
      log.fine("Vendor: " + vendor);
    }
  } //  setParameters
예제 #21
0
  // @emmie custom
  public String generate(
      IStatusBar statusBar, KeyNamePair docTypeKNPair, int C_POS_ID, String docActionSelected)
        // @emmie custom
      {
    String info = "";
    String trxName = Trx.createTrxName("IVG");
    Trx trx = Trx.get(trxName, true); // trx needs to be committed too

    setSelectionActive(false); //  prevents from being called twice
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "InvGenerateGen"));
    statusBar.setStatusDB(String.valueOf(getSelection().size()));

    //	Prepare Process
    int AD_Process_ID = 0;

    if (docTypeKNPair.getKey() == MRMA.Table_ID) {
      AD_Process_ID =
          PROCESS_C_INVOICE_GENERATERMA_MANUAL; // C_Invoice_GenerateRMA -
                                                // org.adempiere.process.InvoiceGenerateRMA
    } else {
      AD_Process_ID = PROCESS_C_INVOICE_GENERATE_MANUAL; // HARDCODED    C_InvoiceCreate
    }
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    if (!instance.save()) {
      info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
      return info;
    }

    // insert selection
    StringBuffer insert = new StringBuffer();
    insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
    int counter = 0;
    for (Integer selectedId : getSelection()) {
      counter++;
      if (counter > 1) insert.append(" UNION ");
      insert.append("SELECT ");
      insert.append(instance.getAD_PInstance_ID());
      insert.append(", ");
      insert.append(selectedId);
      insert.append(" FROM DUAL ");

      if (counter == 1000) {
        if (DB.executeUpdate(insert.toString(), trxName) < 0) {
          String msg = "No Invoices"; //  not translated!
          info = msg;
          log.config(msg);
          trx.rollback();
          return info;
        }
        insert = new StringBuffer();
        insert.append("INSERT INTO T_SELECTION(AD_PINSTANCE_ID, T_SELECTION_ID) ");
        counter = 0;
      }
    }
    if (counter > 0) {
      if (DB.executeUpdate(insert.toString(), trxName) < 0) {
        String msg = "No Invoices"; //  not translated!
        info = msg;
        log.config(msg);
        trx.rollback();
        return info;
      }
    }

    ProcessInfo pi = new ProcessInfo("", AD_Process_ID);
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());

    //	Add Parameters
    MPInstancePara para = new MPInstancePara(instance, 10);
    para.setParameter("Selection", "Y");
    if (!para.save()) {
      String msg = "No Selection Parameter added"; //  not translated
      info = msg;
      log.log(Level.SEVERE, msg);
      return info;
    }

    para = new MPInstancePara(instance, 20);
    para.setParameter("DocAction", docActionSelected);

    if (!para.save()) {
      String msg = "No DocAction Parameter added"; //  not translated
      info = msg;
      log.log(Level.SEVERE, msg);
      return info;
    }
    // @emmie custom
    para = new MPInstancePara(instance, 30);
    para.setParameter("C_POS_ID", C_POS_ID);

    if (!para.save()) {
      String msg = "No C_POS_ID Parameter added"; //  not translated
      info = msg;
      log.log(Level.SEVERE, msg);
      return info;
    }
    // @emmie custom

    setTrx(trx);
    setProcessInfo(pi);

    return info;
  } //	generateInvoices
예제 #22
0
 /** @return selected Attribute Set ID */
 public int getM_AttributeSet_ID() {
   int M_AttributeSet_ID = 0;
   KeyNamePair as = (KeyNamePair) pickAS.getSelectedItem();
   if (as != null) M_AttributeSet_ID = as.getKey();
   return M_AttributeSet_ID;
 }
예제 #23
0
 /** @return selected product category ID */
 public int getM_Product_Category_ID() {
   int M_Product_Category_ID = 0;
   KeyNamePair pc = (KeyNamePair) pickProductCategory.getSelectedItem();
   if (pc != null) M_Product_Category_ID = pc.getKey();
   return M_Product_Category_ID;
 }
예제 #24
0
  /** Create Grid */
  private void createGrid() {
    if (attributeCombo1 == null || m_setting) return; // 	init
    int indexAttr1 = attributeCombo1.getSelectedIndex();
    int indexAttr2 = attributeCombo2.getSelectedIndex();
    if (indexAttr1 == indexAttr2) {
      log.warning("Same Attribute Selected");
      tabbedPane.setSelectedIndex(0);
      return;
    }
    m_setting = true;
    m_M_PriceList_Version_ID = 0;
    KeyNamePair pl = (KeyNamePair) pickPriceList.getSelectedItem();
    if (pl != null) m_M_PriceList_Version_ID = pl.getKey();
    m_M_Warehouse_ID = 0;
    KeyNamePair wh = (KeyNamePair) pickWarehouse.getSelectedItem();
    if (wh != null) m_M_Warehouse_ID = wh.getKey();

    //	x dimension
    int cols = 2;
    MAttributeValue[] xValues = null;
    if (indexAttr1 > 0) xValues = m_attributes[indexAttr1 - 1].getMAttributeValues();
    if (xValues != null) {
      cols = xValues.length;
      log.info("X - " + m_attributes[indexAttr1 - 1].getName() + " #" + xValues.length);
    }

    //	y dimension
    int rows = 2;
    MAttributeValue[] yValues = null;
    if (indexAttr2 > 0) yValues = m_attributes[indexAttr2 - 1].getMAttributeValues();
    if (yValues != null) {
      rows = yValues.length;
      log.info("Y - " + m_attributes[indexAttr2 - 1].getName() + " #" + yValues.length);
    }

    //
    gridPanel.removeAll();
    CPanel grid = new CPanel(new GridLayout(rows, cols, 5, 5));
    gridPanel.add(modePanel, BorderLayout.NORTH);
    gridPanel.add(new CScrollPane(grid), BorderLayout.CENTER);
    //
    log.info("Rows=" + rows + " - Cols=" + cols);
    for (int row = 0; row < rows; row++) {
      for (int col = 0; col < cols; col++) {
        MAttributeValue xValue = null;
        if (xValues != null) xValue = xValues[col];
        MAttributeValue yValue = null;
        if (yValues != null) yValue = yValues[row];
        //	log.fine("Row=" + row + " - Col=" + col);
        //
        if (row == 0 && col == 0) {
          CPanel descr = new CPanel(new GridLayout(2, 1, 0, 0));
          if (xValues != null)
            descr.add(new JLabel(m_attributes[indexAttr1 - 1].getName(), JLabel.TRAILING));
          if (yValues != null) descr.add(new JLabel(m_attributes[indexAttr2 - 1].getName()));
          grid.add(descr);
        } else if (row == 0) // 	column labels
        {
          if (xValue != null) {
            grid.add(new JLabel(xValue.getName(), JLabel.TRAILING));
          } else grid.add(new JLabel());
        } else if (col == 0) // 	row labels
        {
          if (yValue != null) grid.add(new JLabel(yValue.getName()));
          else grid.add(new JLabel());
        } else {
          grid.add(getGridElement(xValue, yValue));
        }
      }
    }
    //
    tabbedPane.setSelectedIndex(1);
    m_setting = false;
    m_frame.pack();
  } //	createGrid
  public void onEvent(Event e) throws Exception {
    if (m_setting) return;
    //	Update Assignment
    ListItem listItem = fResource.getSelectedItem();
    KeyNamePair resource =
        listItem != null
            ? new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel())
            : null;
    if (resource != null) {
      int S_Resource_ID = resource.getKey();
      m_mAssignment.setS_Resource_ID(S_Resource_ID);
    }

    Calendar date = new GregorianCalendar();
    getDateAndTimeFrom(date);

    Timestamp assignDateFrom = new Timestamp(date.getTimeInMillis());
    if (assignDateFrom != null) m_mAssignment.setAssignDateFrom(assignDateFrom);
    if (fQty.getValue() != null) {
      BigDecimal qty = fQty.getValue();
      m_mAssignment.setQty(qty);
    }
    m_mAssignment.setName((String) fName.getValue());
    m_mAssignment.setDescription((String) fDescription.getValue());

    //	Resource - Look up UOM
    if (e.getTarget() == fResource) {
      Object o = m_lookup.get(resource);
      if (o == null) lUOM.setValue(" ? ");
      else lUOM.setValue(o.toString());
    }

    //	Zoom - InfoResource
    else if (e.getTarget().getId().equals("Zoom")) {
      InfoSchedule is = new InfoSchedule(m_mAssignment, true);
      if (is.getMResourceAssignment() != null) {
        m_mAssignment = is.getMResourceAssignment();
        //	setDisplay();
        detach();
      }
      is = null;
    }

    //	cancel - return
    else if (e.getTarget().getId().equals("Cancel")) {
      m_cancel = true;
      detach();
    }

    //	delete - delete and return
    else if (e.getTarget().getId().equals("Delete")) {
      if (m_mAssignment.delete(true)) {
        m_mAssignment = null;
        detach();
      } else FDialog.error(0, this, "ResourceAssignmentNotDeleted");
    }

    //	OK - Save
    else if (e.getTarget().getId().equals("Ok")) {
      if (cmd_save()) detach();
    }
  }
  private void tableInit() {

    m_sql = new StringBuffer();
    m_sql2 = new StringBuffer();

    // Mostrar todos los ACC y AAP
    if (tableInit_option == 0) {
      m_sql.append(
          "select cb.value ||'-'|| cb.name vendor, co.name country, extract(month from cn.CREATED) month,"
              + " extract (year from cn.CREATED) year, NVL(round(sum(cn.XX_UNITPURCHASEPRICEBS),2),0) total,"
              + " dep.value || '-' || dep.name department, cat.value || '-' || cat.name category,"
              + " o.XX_VMR_DEPARTMENT_ID, o.XX_VMR_CATEGORY_ID, o.C_BPARTNER_ID vendorID"
              + " from  XX_CREDITNOTIFYRETURN cn, C_BPARTNER cb, C_COUNTRY co, C_ORDER o, XX_VMR_DEPARTMENT dep, XX_VMR_CATEGORY cat"
              + " where o.C_BPARTNER_ID=cb.C_BPARTNER_ID and co.C_COUNTRY_ID=o.C_COUNTRY_ID and"
              + " cn.XX_NOTIFICATIONTYPE='ACC'and cn.C_ORDER_ID=o.C_ORDER_ID and"
              + " dep.XX_VMR_DEPARTMENT_ID=o.XX_VMR_DEPARTMENT_ID and o.XX_VMR_CATEGORY_ID=cat.XX_VMR_CATEGORY_ID and o.AD_CLIENT_ID="
              + ctx.getAD_Client_ID()
              + " AND o.ISSOTRX = 'N'");

      m_groupBy =
          " group by cb.value ||'-'|| cb.name, co.name,  extract(month from cn.CREATED), extract (year from cn.CREATED), dep.value || '-' || dep.name,"
              + " cat.value || '-' || cat.name,o.XX_VMR_DEPARTMENT_ID, o.XX_VMR_CATEGORY_ID, o.C_BPARTNER_ID";

      m_sql2.append(
          "select cb.value ||'-'|| cb.name vendor, co.name country, det.XX_MONTH month,"
              + " det.XX_YEAR year, round(cn.XX_UNITPURCHASEPRICEBS,2) total, o.C_BPARTNER_ID vendorID,"
              + " o.XX_VMR_DEPARTMENT_ID, o.XX_VMR_CATEGORY_ID, cn.XX_CREDITNOTIFYRETURN_ID creditNotID, cn.XX_NOTIFICATIONTYPE tipo"
              + " from  XX_CREDITNOTIFYRETURN cn, C_BPARTNER cb, C_COUNTRY co, C_ORDER o, XX_VMR_DEPARTMENT dep, XX_VMR_CATEGORY cat, XX_VCN_DETAILADVICE det"
              + " where o.C_BPARTNER_ID=cb.C_BPARTNER_ID and co.C_COUNTRY_ID=o.C_COUNTRY_ID and cn.XX_NOTIFICATIONTYPE<>'ACC'"
              + " and cn.C_ORDER_ID=o.C_ORDER_ID and dep.XX_VMR_DEPARTMENT_ID=o.XX_VMR_DEPARTMENT_ID"
              + " and o.XX_VMR_CATEGORY_ID=cat.XX_VMR_CATEGORY_ID and det.XX_CREDITNOTIFYRETURN_ID=cn.XX_CREDITNOTIFYRETURN_ID and o.AD_CLIENT_ID="
              + ctx.getAD_Client_ID()
              + " AND o.ISSOTRX = 'N'");

      m_groupBy2 =
          " group by cb.value ||'-'|| cb.name, co.name,  det.XX_MONTH, det.XX_YEAR, cn.XX_UNITPURCHASEPRICEBS,"
              + " o.XX_VMR_DEPARTMENT_ID, o.XX_VMR_CATEGORY_ID, o.C_BPARTNER_ID, cn.XX_CREDITNOTIFYRETURN_ID, cn.XX_NOTIFICATIONTYPE";
      // Búsqueda por mes
      if (monthCombo.getSelectedIndex() != 0 && monthCombo.getSelectedItem() != null) {
        m_sql
            .append(" AND ")
            .append("extract(month from cn.created)=")
            .append(monthCombo.getSelectedIndex());
        m_sql2.append(" AND ").append("det.XX_MONTH=").append(monthCombo.getSelectedIndex());
      }
      // Búsqueda por año
      if (yearField.getValue() != null) {
        m_sql
            .append(" AND ")
            .append("extract(year from cn.created)=")
            .append(((BigDecimal) yearField.getValue()).intValue());
        m_sql2
            .append(" AND ")
            .append("det.XX_YEAR=")
            .append(((BigDecimal) yearField.getValue()).intValue());
      }
      // Búsqueda por proveedor
      if (comboBPartner.getSelectedIndex() != 0 && comboBPartner.getSelectedItem() != null) {
        if (((KeyNamePair) comboBPartner.getSelectedItem()).getKey() != 0) {
          int clave_vendor = ((KeyNamePair) comboBPartner.getSelectedItem()).getKey();
          m_sql.append(" AND ").append("o.C_BPartner_ID=").append(clave_vendor);
          m_sql2.append(" AND ").append("o.C_BPartner_ID=").append(clave_vendor);
        }
      }

      // agrego la categoria
      if (categoryCombo.getValue() != null) {
        KeyNamePair cat = (KeyNamePair) categoryCombo.getValue();
        if (cat.getKey() != -1) {
          m_sql.append(" AND o.XX_VMR_CATEGORY_ID = ").append(cat.getKey()).append(" ");
          m_sql2.append(" AND o.XX_VMR_CATEGORY_ID = ").append(cat.getKey()).append(" ");
        }
      }
      // agrego el departamento al query
      if (departmentCombo.getValue() != null) {
        KeyNamePair dep = (KeyNamePair) departmentCombo.getValue();
        if (dep.getKey() != -1) {
          m_sql.append(" AND o.XX_VMR_DEPARTMENT_ID = ").append(dep.getKey()).append(" ");
          m_sql2.append(" AND o.XX_VMR_DEPARTMENT_ID = ").append(dep.getKey()).append(" ");
        }
      }
    }

    String SQL = m_sql.toString() + m_groupBy;

    int i = 0;
    xTableACC.setRowCount(i);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      pstmt = DB.prepareStatement(SQL, null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        xTableACC.setRowCount(i + 1);
        // Proveedor
        xTableACC.setValueAt(rs.getString("vendor"), i, 0); // 1
        // País
        xTableACC.setValueAt(rs.getString("country"), i, 1);
        // Departamento
        xTableACC.setValueAt(rs.getString("department"), i, 2);
        // Categoría
        xTableACC.setValueAt(rs.getString("category"), i, 3);
        // Mes
        xTableACC.setValueAt(rs.getInt("month"), i, 4);
        // Año
        xTableACC.setValueAt(rs.getInt("year"), i, 5);
        // Compras hechas
        xTableACC.setValueAt(rs.getBigDecimal("total"), i, 6);

        // Se calculan los avisos cerrados(CER) de el mismo mes, año, proveedor, depto y categoría
        String SQL2 =
            "select nvl(round(sum(cn.XX_AMOUNT),2),0) totalDesc"
                + " from  XX_CREDITNOTIFYRETURN cn, C_BPARTNER cb, C_COUNTRY co, C_ORDER o, XX_VMR_DEPARTMENT dep, XX_VMR_CATEGORY cat"
                + " where o.C_BPARTNER_ID=cb.C_BPARTNER_ID and co.C_COUNTRY_ID=o.C_COUNTRY_ID"
                + " and cn.XX_NOTIFICATIONTYPE='ACC' and cn.C_ORDER_ID=o.C_ORDER_ID"
                + " and dep.XX_VMR_DEPARTMENT_ID=o.XX_VMR_DEPARTMENT_ID and o.XX_VMR_CATEGORY_ID=cat.XX_VMR_CATEGORY_ID"
                + " and XX_STATUS='CER' and extract(month from cn.CREATED)="
                + rs.getInt("month")
                + " and extract (year from cn.CREATED)="
                + rs.getInt("year")
                + " and o.C_BPARTNER_ID="
                + rs.getInt("vendorID")
                + " and o.AD_CLIENT_ID="
                + ctx.getAD_Client_ID()
                + " AND o.ISSOTRX = 'N'";
        PreparedStatement pstmt2 = null;
        ResultSet rs2 = null;

        try {
          pstmt2 = DB.prepareStatement(SQL2, null);
          rs2 = pstmt2.executeQuery();
          if (rs2.next()) xTableACC.setValueAt(rs2.getBigDecimal("totalDesc"), i, 7);
          else xTableACC.setValueAt(0, i, 7);
        } catch (SQLException e) {
          System.out.print(e.getMessage());
        } finally {
          DB.closeResultSet(rs2);
          DB.closeStatement(pstmt2);
        }

        // Se calculan los avisos pendientes(ACT) de el mismo mes, año, proveedor, depto y categoría
        String SQL3 =
            "select nvl(round(sum(cn.XX_AMOUNT),2),0) totalDesc"
                + " from  XX_CREDITNOTIFYRETURN cn, C_BPARTNER cb, C_COUNTRY co, C_ORDER o, XX_VMR_DEPARTMENT dep, XX_VMR_CATEGORY cat"
                + " where o.C_BPARTNER_ID=cb.C_BPARTNER_ID and co.C_COUNTRY_ID=o.C_COUNTRY_ID"
                + " and cn.XX_NOTIFICATIONTYPE='ACC' and cn.C_ORDER_ID=o.C_ORDER_ID"
                + " and dep.XX_VMR_DEPARTMENT_ID=o.XX_VMR_DEPARTMENT_ID and o.XX_VMR_CATEGORY_ID=cat.XX_VMR_CATEGORY_ID"
                + " and XX_STATUS='ACT' and extract(month from cn.CREATED)="
                + rs.getInt("month")
                + " and extract (year from cn.CREATED)="
                + rs.getInt("year")
                + " and o.C_BPARTNER_ID="
                + rs.getInt("vendorID")
                + " and o.AD_CLIENT_ID="
                + ctx.getAD_Client_ID()
                + " AND o.ISSOTRX = 'N'";
        PreparedStatement pstmt3 = null;
        ResultSet rs3 = null;
        try {
          pstmt3 = DB.prepareStatement(SQL3, null);
          rs3 = pstmt3.executeQuery();
          if (rs3.next()) xTableACC.setValueAt(rs3.getBigDecimal("totalDesc"), i, 8);
          else xTableACC.setValueAt(0, i, 8);
        } catch (SQLException e) {
          System.out.print(e.getMessage());
        } finally {
          DB.closeResultSet(rs3);
          DB.closeStatement(pstmt3);
        }

        i++;
      }

    } catch (SQLException e) {
      e.getMessage();
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }

    String sqlAAP = m_sql2.toString() + m_groupBy2;

    i = 0;
    xTableAAP.setRowCount(i);
    pstmt = null;
    rs = null;
    try {
      pstmt = DB.prepareStatement(sqlAAP, null);
      rs = pstmt.executeQuery();
      while (rs.next()) {
        xTableAAP.setRowCount(i + 1);
        // Proveedor
        xTableAAP.setValueAt(
            new KeyNamePair(rs.getInt("vendorID"), rs.getString("vendor")), i, 0); // 1
        // País
        xTableAAP.setValueAt(
            new KeyNamePair(rs.getInt("creditNotID"), rs.getString("country")), i, 1);
        // Mes
        xTableAAP.setValueAt(rs.getInt("month"), i, 2);
        // Año
        xTableAAP.setValueAt(rs.getInt("year"), i, 3);
        // Tipo
        xTableAAP.setValueAt(rs.getString("tipo"), i, 4);
        // Compras hechas
        xTableAAP.setValueAt(rs.getBigDecimal("total"), i, 5);

        // Se calculan los avisos cerrados(CER) de el mismo mes, año, proveedor, depto y categoría
        String SQL2 =
            "select nvl(round(sum(cn.XX_AMOUNT),2),0) totalDesc"
                + " from  XX_CREDITNOTIFYRETURN cn, C_BPARTNER cb, C_COUNTRY co, C_ORDER o, XX_VMR_DEPARTMENT dep, XX_VMR_CATEGORY cat"
                + " where o.C_BPARTNER_ID=cb.C_BPARTNER_ID and co.C_COUNTRY_ID=o.C_COUNTRY_ID"
                + " and cn.XX_NOTIFICATIONTYPE<>'ACC' and cn.C_ORDER_ID=o.C_ORDER_ID"
                + " and dep.XX_VMR_DEPARTMENT_ID=o.XX_VMR_DEPARTMENT_ID and o.XX_VMR_CATEGORY_ID=cat.XX_VMR_CATEGORY_ID"
                + " and XX_STATUS='CER' and cn.XX_CREDITNOTIFYRETURN_ID="
                + rs.getInt("creditNotID")
                + " and o.C_BPARTNER_ID="
                + rs.getInt("vendorID")
                + " and o.AD_CLIENT_ID="
                + ctx.getAD_Client_ID()
                + " AND o.ISSOTRX = 'N'";
        PreparedStatement pstmt2 = null;
        ResultSet rs2 = null;

        try {
          pstmt2 = DB.prepareStatement(SQL2, null);
          rs2 = pstmt2.executeQuery();
          if (rs2.next()) xTableAAP.setValueAt(rs2.getBigDecimal("totalDesc"), i, 6);
          else xTableAAP.setValueAt(0, i, 6);
        } catch (SQLException e) {
          System.out.print(e.getMessage());
        } finally {
          DB.closeResultSet(rs2);
          DB.closeStatement(pstmt2);
        }

        // Se calculan los avisos pendientes(ACT) de el mismo mes, año, proveedor, depto y categoría
        String SQL3 =
            "select nvl(round(sum(cn.XX_AMOUNT),2),0) totalDesc"
                + " from  XX_CREDITNOTIFYRETURN cn, C_BPARTNER cb, C_COUNTRY co, C_ORDER o, XX_VMR_DEPARTMENT dep, XX_VMR_CATEGORY cat"
                + " where o.C_BPARTNER_ID=cb.C_BPARTNER_ID and co.C_COUNTRY_ID=o.C_COUNTRY_ID"
                + " and cn.XX_NOTIFICATIONTYPE<>'ACC' and cn.C_ORDER_ID=o.C_ORDER_ID"
                + " and dep.XX_VMR_DEPARTMENT_ID=o.XX_VMR_DEPARTMENT_ID and o.XX_VMR_CATEGORY_ID=cat.XX_VMR_CATEGORY_ID"
                + " and XX_STATUS='ACT' and cn.XX_CREDITNOTIFYRETURN_ID="
                + rs.getInt("creditNotID")
                + " and o.C_BPARTNER_ID="
                + rs.getInt("vendorID")
                + " and o.AD_CLIENT_ID="
                + ctx.getAD_Client_ID()
                + " AND o.ISSOTRX = 'N'";
        PreparedStatement pstmt3 = null;
        ResultSet rs3 = null;
        try {
          pstmt3 = DB.prepareStatement(SQL3, null);
          rs3 = pstmt3.executeQuery();
          if (rs3.next()) xTableAAP.setValueAt(rs3.getBigDecimal("totalDesc"), i, 7);
          else xTableAAP.setValueAt(0, i, 7);
        } catch (SQLException e) {
          System.out.print(e.getMessage());
        } finally {
          DB.closeResultSet(rs3);
          DB.closeStatement(pstmt3);
        }

        i++;
      }

    } catch (SQLException e) {
      e.getMessage();
    } finally {
      DB.closeResultSet(rs);
      DB.closeStatement(pstmt);
    }
  } //  tableInit