/** 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
/** * 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(); }
/** Search Button Pressed */ private void cmd_Search() { tableInit(); totalCalculation(); if (xTableACC.getRowCount() != 0 || xTableAAP.getRowCount() != 0) { statusBar.setStatusLine("Acuerdos Comerciales y Cartas Compromiso"); statusBar.setStatusDB(xTableACC.getRowCount() + xTableAAP.getRowCount()); } else { showCreditNotificationCondition(); } }
/** Dynamic Init - Get defaults for primary AcctSchema - Create Table with Accounts */ private void dynInit() { findChargeElementID(); DefaultTableModel model = new DefaultTableModel(getData(), getColumnNames()); dataTable.setModel(model); setColumnClass(dataTable); findTaxCategoryID(); }
/** Refresh Query */ private void refresh() { String sql = m_sql; int pos = m_sql.lastIndexOf(" ORDER BY "); if (!showAll.isSelected()) { sql = m_sql.substring(0, pos) + s_sqlWhereSameWarehouse; if (s_sqlMinLife.length() > 0) sql += s_sqlMinLife; sql += m_sql.substring(pos); } // log.finest(sql); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_M_Product_ID); if (!showAll.isSelected()) { pstmt.setInt(2, m_M_Warehouse_ID); } rs = pstmt.executeQuery(); m_table.loadTable(rs); } catch (Exception e) { log.log(Level.SEVERE, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } enableButtons(); }
public void check_all() { boolean checkall = false; if (xProductTable.getRowCount() > 0) { IDColumn id = (IDColumn) xProductTable.getValueAt(0, 0); if (id.isSelected()) { checkall = false; } else { checkall = true; } } for (int row = 0; row < xProductTable.getRowCount(); row++) { IDColumn old_id = (IDColumn) xProductTable.getValueAt(row, 0); IDColumn id = new IDColumn(old_id.getRecord_ID()); id.setSelected(checkall); xProductTable.setValueAt(id, row, 0); } }
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(); }
/** * Tab Changed * * @param e event */ public void stateChanged(ChangeEvent e) { if (e.getSource() instanceof CTabbedPane) { CTabbedPane tab = (CTabbedPane) e.getSource(); if (tab.getSelectedIndex() == 4 & warehouseTbl.getRowCount() > 0) { // If no warehouse row is selected in the warehouse tab, use the first warehouse // row to prevent array index out of bounds. BF 3051361 int selectedRow = warehouseTbl.getSelectedRow(); if (selectedRow < 0) selectedRow = 0; String value = (String) warehouseTbl.getValueAt(selectedRow, 0); int M_Warehouse_ID = DB.getSQLValue( null, "SELECT M_Warehouse_ID FROM M_Warehouse WHERE UPPER(Name) = UPPER(?) AND AD_Client_ID=?", new Object[] {value, Env.getAD_Client_ID(Env.getCtx())}); initAtpTab(M_Warehouse_ID); } } } // stateChanged
public void totalCalculation() { BigDecimal totalPurchaseACC = BigDecimal.ZERO; BigDecimal totalPurchaseAAP = BigDecimal.ZERO; BigDecimal totalDiscACC = BigDecimal.ZERO; BigDecimal totalDiscAAP = BigDecimal.ZERO; BigDecimal vsACC = BigDecimal.ZERO; BigDecimal vsAAP = BigDecimal.ZERO; for (int i = 0; i < xTableACC.getRowCount(); i++) { totalPurchaseACC = totalPurchaseACC.add((BigDecimal) xTableACC.getValueAt(i, 6)); totalDiscACC = totalDiscACC.add((BigDecimal) xTableACC.getValueAt(i, 7)); } for (int i = 0; i < xTableAAP.getRowCount(); i++) { totalPurchaseAAP = totalPurchaseAAP.add((BigDecimal) xTableAAP.getValueAt(i, 5)); totalDiscAAP = totalDiscAAP.add((BigDecimal) xTableAAP.getValueAt(i, 6)); } if (totalPurchaseACC != BigDecimal.ZERO) vsACC = totalDiscACC .multiply(new BigDecimal(100)) .divide(totalPurchaseACC, 2, RoundingMode.HALF_UP); if (totalPurchaseAAP != BigDecimal.ZERO) vsAAP = totalDiscAAP .multiply(new BigDecimal(100)) .divide(totalPurchaseAAP, 2, RoundingMode.HALF_UP); this.totalPurchaseACC.setText( header1 + totalPurchaseACC + " " + header2 + totalDiscACC + " " + header3 + " " + vsACC + "</PRE></font>" + "</html>"); this.totalPurchaseAAP.setText( header1 + totalPurchaseAAP + " " + header2 + " " + totalDiscAAP + " " + header3 + " " + vsAAP + "</PRE></font>" + "</html>"); }
/** * Fill the table using m_sql * * @param table table */ private static void tableLoad(MiniTable table) { // log.finest(m_sql + " - " + m_groupBy); String sql = MRole.getDefault() .addAccessSQL(m_sql.toString(), "tab", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO) + m_groupBy + m_orderBy; log.finest(sql); try { Statement stmt = DB.createStatement(); ResultSet rs = stmt.executeQuery(sql); table.loadTable(rs); stmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } } // tableLoad
/** Dynamic Init. Table Layout, Visual, Listener */ private void dynInit() { // Add the column definition for the table xProductTable.addColumn(" "); xProductTable.addColumn(Msg.translate(Env.getCtx(), "ProductKey")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "VendorProductRef")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "XX_Product")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "XX_PriceConsecutive")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "XX_ProductQty")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "XX_LabelQty")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "XX_Category")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "XX_Department_I")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "XX_Line_I")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "XX_Section_I")); xProductTable.addColumn(Msg.translate(Env.getCtx(), "AttributeSetInstance")); xProductTable.setMultiSelection(true); xProductTable.setColumnClass(0, IDColumn.class, false); xProductTable.setColumnClass(1, String.class, true); xProductTable.setColumnClass(2, KeyNamePair.class, true); xProductTable.setColumnClass(3, KeyNamePair.class, true); xProductTable.setColumnClass(4, String.class, true); xProductTable.setColumnClass(5, Integer.class, true); xProductTable.setColumnClass(6, Integer.class, false); xProductTable.setColumnClass(7, KeyNamePair.class, true); xProductTable.setColumnClass(8, KeyNamePair.class, true); xProductTable.setColumnClass(9, KeyNamePair.class, true); xProductTable.setColumnClass(10, KeyNamePair.class, true); xProductTable.setColumnClass(11, KeyNamePair.class, true); CompiereColor.setBackground(this); xProductTable.setRowHeight(xProductTable.getRowHeight() + 2); generate.addActionListener(this); markall.addActionListener(this); // Init statusBar.setStatusLine(""); statusBar.setStatusDB(0); fillProductTable(); xProductTable.addKeyListener( new KeyListener() { @Override public void keyTyped(KeyEvent e) {} @Override public void keyReleased(KeyEvent e) { int row = xProductTable.getSelectedColumn(); int column = xProductTable.getSelectedRow(); xProductTable.editCellAt(column, row); } @Override public void keyPressed(KeyEvent e) {} }); xProductTable.getTableHeader().setReorderingAllowed(false); xProductTable.getModel().addTableModelListener(this); xProductTable.autoSize(true); xProductTable.repaint(); } // dynInit
private void tableDetailsInit() { xTableAAP .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int i = 0; if (xTableAAP.getSelectedRow() == -1) { xTableDetails.setRowCount(i); return; } if (e .getValueIsAdjusting()) { // Para que se ejecute solo una vez el // ListSelectionListener KeyNamePair vendorKey = (KeyNamePair) xTableAAP.getValueAt(xTableAAP.getSelectedRow(), 0); KeyNamePair creditNotKey = (KeyNamePair) xTableAAP.getValueAt(xTableAAP.getSelectedRow(), 1); xTableDetails.setRowCount(i); String SQL = "select det.XX_MONTH month," + " det.XX_YEAR year, dep.value || '-' || dep.name department," + " cat.value || '-' || cat.name category, round(det.XX_PUBAMOUNT,2) amount" + " from XX_VCN_DETAILADVICE det, XX_CREDITNOTIFYRETURN cNot, XX_VMR_DEPARTMENT dep," + " XX_VMR_CATEGORY cat, C_ORDER cOrd" + " where cNot.XX_CREDITNOTIFYRETURN_ID=det.XX_CREDITNOTIFYRETURN_ID and" + " det.C_ORDER_ID=cOrd.C_ORDER_ID and cOrd.XX_VMR_DEPARTMENT_ID=dep.XX_VMR_DEPARTMENT_ID and" + " cOrd.XX_VMR_CATEGORY_ID=cat.XX_VMR_CATEGORY_ID and cOrd.C_BPARTNER_ID=" + vendorKey.getKey() + " and det.XX_CREDITNOTIFYRETURN_ID=" + creditNotKey.getKey() + " and cOrd.AD_CLIENT_ID=" + ctx.getAD_Client_ID() + " AND cOrd.ISSOTRX = 'N'"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(SQL, null); rs = pstmt.executeQuery(); while (rs.next()) { xTableDetails.setRowCount(i + 1); // Proveedor xTableDetails.setValueAt( xTableAAP.getValueAt(xTableAAP.getSelectedRow(), 0), i, 0); // Mes xTableDetails.setValueAt(rs.getInt("month"), i, 1); // Año xTableDetails.setValueAt(rs.getInt("year"), i, 2); // Departamento xTableDetails.setValueAt(rs.getString("department"), i, 3); // Categoría xTableDetails.setValueAt(rs.getString("category"), i, 4); // Monto del descuento xTableDetails.setValueAt(rs.getString("amount"), i, 5); i++; } } catch (SQLException er) { er.getMessage(); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } } } }); }
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
private void dynInit() { // Llenar los filtros de busquedas llenarcombos(); // generacion de las columnas para los avisos de Creditos ColumnInfo[] layoutACC = new ColumnInfo[] { // 0 Proveedor new ColumnInfo(Msg.translate(Env.getCtx(), "C_BPartner_ID"), ".", String.class), // 1 País new ColumnInfo(Msg.translate(Env.getCtx(), "CountryName"), ".", String.class), // 2 Departamento new ColumnInfo(Msg.translate(Env.getCtx(), "XX_VMR_Department_ID"), ".", String.class), // 3 Categoría new ColumnInfo(Msg.translate(Env.getCtx(), "Categoria"), ".", String.class), // 4 Mes new ColumnInfo(Msg.translate(Env.getCtx(), "XX_Month"), ".", Integer.class), // 5 Año new ColumnInfo(Msg.translate(Env.getCtx(), "XX_Year"), ".", Integer.class), // 6 Compras hechas new ColumnInfo(Msg.translate(Env.getCtx(), "PurchasesDone"), "total", float.class), // 7 Descuentos generados new ColumnInfo(Msg.translate(Env.getCtx(), "GeneratedDiscount"), ".", float.class), // 8 Avisos pendientes new ColumnInfo(Msg.translate(Env.getCtx(), "PendingAdvices"), ".", float.class), }; xTableACC.prepareTable(layoutACC, "", "", true, ""); // Visual CompiereColor.setBackground(this); xTableACC.getSelectionModel().addListSelectionListener(this); xTableACC.getColumnModel().getColumn(0).setMinWidth(350); xTableACC.getColumnModel().getColumn(1).setMinWidth(150); xTableACC.getColumnModel().getColumn(2).setMinWidth(190); xTableACC.getColumnModel().getColumn(3).setMinWidth(110); xTableACC.getColumnModel().getColumn(4).setMinWidth(25); xTableACC.getColumnModel().getColumn(4).setMaxWidth(30); xTableACC.getColumnModel().getColumn(5).setMinWidth(30); xTableACC.getColumnModel().getColumn(5).setMaxWidth(35); xTableACC.getColumnModel().getColumn(6).setMinWidth(140); xTableACC.getColumnModel().getColumn(7).setMinWidth(150); xTableACC.getColumnModel().getColumn(8).setMinWidth(140); xTableACC.getSelectionModel().addListSelectionListener(this); ColumnInfo[] layoutAAP = new ColumnInfo[] { // 0 Proveedor new ColumnInfo( Msg.translate(Env.getCtx(), "C_BPartner_ID"), "vendorID", KeyNamePair.class), // 1 País new ColumnInfo(Msg.translate(Env.getCtx(), "CountryName"), ".", KeyNamePair.class), // 2 Mes new ColumnInfo(Msg.translate(Env.getCtx(), "Month"), ".", Integer.class), // 3 Año new ColumnInfo(Msg.translate(Env.getCtx(), "Year"), ".", Integer.class), // 4 Tipo new ColumnInfo(Msg.translate(Env.getCtx(), "XX_Notificationtype"), ".", String.class), // 5 Compras hechas new ColumnInfo(Msg.translate(Env.getCtx(), "PurchasesDone"), "total", float.class), // 6 Descuentos generados new ColumnInfo(Msg.translate(Env.getCtx(), "GeneratedDiscount"), ".", float.class), // 7 Avisos pendientes new ColumnInfo(Msg.translate(Env.getCtx(), "PendingAdvices"), ".", float.class), }; xTableAAP.prepareTable(layoutAAP, "", "", true, ""); // Visual CompiereColor.setBackground(this); xTableAAP.getSelectionModel().addListSelectionListener(this); xTableAAP.getColumnModel().getColumn(0).setMinWidth(350); xTableAAP.getColumnModel().getColumn(1).setMinWidth(150); xTableAAP.getColumnModel().getColumn(2).setMinWidth(25); xTableAAP.getColumnModel().getColumn(2).setMaxWidth(30); xTableAAP.getColumnModel().getColumn(3).setMinWidth(30); xTableAAP.getColumnModel().getColumn(3).setMaxWidth(35); xTableAAP.getColumnModel().getColumn(4).setMinWidth(90); xTableAAP.getColumnModel().getColumn(5).setMinWidth(150); xTableAAP.getColumnModel().getColumn(6).setMinWidth(140); xTableAAP.getColumnModel().getColumn(7).setMinWidth(140); xTableAAP.getSelectionModel().addListSelectionListener(this); ColumnInfo[] layoutDetails = new ColumnInfo[] { // 0 Proveedor new ColumnInfo(Msg.translate(Env.getCtx(), "C_BPartner_ID"), ".", String.class), // 1 Mes new ColumnInfo(Msg.translate(Env.getCtx(), "Month"), ".", Integer.class), // 2 Año new ColumnInfo(Msg.translate(Env.getCtx(), "Year"), ".", Integer.class), // 3 Departamento new ColumnInfo(Msg.translate(Env.getCtx(), "XX_VMR_Department_ID"), ".", String.class), // 4 Categoría new ColumnInfo(Msg.translate(Env.getCtx(), "Categoria"), ".", String.class), // 5 Descuento new ColumnInfo(Msg.translate(Env.getCtx(), "XX_PubAmountDisc"), ".", float.class) }; xTableDetails.prepareTable(layoutDetails, "", "", true, ""); // Visual CompiereColor.setBackground(this); xTableDetails.getSelectionModel().addListSelectionListener(this); xTableDetails.getColumnModel().getColumn(0).setMinWidth(350); xTableDetails.getColumnModel().getColumn(1).setMinWidth(25); xTableDetails.getColumnModel().getColumn(1).setMaxWidth(30); xTableDetails.getColumnModel().getColumn(2).setMinWidth(30); xTableDetails.getColumnModel().getColumn(2).setMaxWidth(35); xTableDetails.getColumnModel().getColumn(3).setMinWidth(190); xTableDetails.getColumnModel().getColumn(4).setMinWidth(150); xTableDetails.getColumnModel().getColumn(5).setMinWidth(120); xTableDetails.getSelectionModel().addListSelectionListener(this); bSearch.addActionListener(this); bReset.addActionListener(this); // Se cargan los acuerdos tableInit_option = 0; tableInit(); tableDetailsInit(); totalCalculation(); xTableACC.getTableHeader().setReorderingAllowed(false); xTableAAP.getTableHeader().setReorderingAllowed(false); xTableDetails.getTableHeader().setReorderingAllowed(false); // xTable.setAutoResizeMode(3); // data(); // Init statusBar.setStatusLine(""); statusBar.setStatusDB(0); // estatus statusBar.setStatusLine("Acuerdos Comerciales y Cartas Compromiso"); statusBar.setStatusDB(xTableACC.getRowCount() + xTableAAP.getRowCount()); } // dynInit
private void fillProductTable() { int row = 0; try { String get_details = " SELECT XX_VMR_DiscountAppliDetail_ID FROM XX_VMR_DiscountAppliDetail " + " WHERE XX_VMR_DiscountRequest_ID = " + header.get_ID(); PreparedStatement pstmt = DB.prepareStatement(get_details, null); // Setting the query parameters ResultSet rs = pstmt.executeQuery(); while (rs.next()) { row = xProductTable.getRowCount(); xProductTable.setRowCount(row + 1); MVMRDiscountAppliDetail detail = new MVMRDiscountAppliDetail(Env.getCtx(), rs.getInt(1), null); IDColumn id = new IDColumn(rs.getInt(1)); id.setSelected(true); xProductTable.setValueAt(id, row, 0); MProduct prod = new MProduct(Env.getCtx(), detail.getM_Product_ID(), null); xProductTable.setValueAt(new KeyNamePair(prod.get_ID(), prod.getValue()), row, 1); xProductTable.setValueAt(prod.getKeyNamePair(), row, 3); X_XX_VMR_VendorProdRef ref_proveedor = new X_XX_VMR_VendorProdRef(Env.getCtx(), prod.getXX_VMR_VendorProdRef_ID(), null); xProductTable.setValueAt( new KeyNamePair(ref_proveedor.get_ID(), ref_proveedor.getValue()), row, 2); // Colocar el consecutivo de precio DecimalFormat formato = new DecimalFormat("000"); X_XX_VMR_PriceConsecutive priceConsecutive = new X_XX_VMR_PriceConsecutive(Env.getCtx(), detail.getXX_PriceConsecutive_ID(), null); xProductTable.setValueAt(formato.format(priceConsecutive.getXX_PriceConsecutive()), row, 4); xProductTable.setValueAt(detail.getXX_LoweringQuantity(), row, 5); xProductTable.setValueAt(detail.getXX_LoweringQuantity(), row, 6); X_XX_VMR_Category cat = new X_XX_VMR_Category(Env.getCtx(), prod.getXX_VMR_Category_ID(), null); xProductTable.setValueAt(cat.getKeyNamePair(), row, 7); X_XX_VMR_Department dep = new X_XX_VMR_Department(Env.getCtx(), header.getXX_VMR_Department_ID(), null); xProductTable.setValueAt(dep.getKeyNamePair(), row, 8); X_XX_VMR_Line lin = new X_XX_VMR_Line(Env.getCtx(), detail.getXX_VMR_Line_ID(), null); xProductTable.setValueAt(lin.getKeyNamePair(), row, 9); X_XX_VMR_Section sec = new X_XX_VMR_Section(Env.getCtx(), detail.getXX_VMR_Section_ID(), null); xProductTable.setValueAt(sec.getKeyNamePair(), row, 10); if (priceConsecutive.getM_AttributeSetInstance_ID() != 0) { MAttributeSetInstance attins = new MAttributeSetInstance( Env.getCtx(), priceConsecutive.getM_AttributeSetInstance_ID(), null); xProductTable.setValueAt( new KeyNamePair(attins.get_ID(), attins.getDescription()), row, 11); } else { xProductTable.setValueAt(new KeyNamePair(0, ""), row, 11); } } rs.close(); pstmt.close(); } catch (Exception E) { E.printStackTrace(); } }
/** Dynamic Init. Table Layout, Visual, Listener */ private void dynInit() { ColumnInfo[] layout = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class), // 1 new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), ".", String.class) // 2 }; xProductTable.prepareTable(layout, "", "", false, ""); xAssociateTable.prepareTable(layout, "", "", true, ""); xAssociateTable.setAutoResizeMode(3); xProductTable.setAutoResizeMode(3); // Visual CompiereColor.setBackground(this); // Listener xProductTable.getSelectionModel().addListSelectionListener(this); xAssociateTable.getModel().addTableModelListener(this); bDisassociate.addActionListener(this); bNewProduct.addActionListener(this); // pregunto si hay productos asociados para ver si cargo las tablas boolean ready = verify(); if (ready == false) { tableInit_option = 0; tableInit(); tableLoad(xProductTable); } else { tableInit_option = 1; tableInit(); tableLoad(xAssociateTable); bNewProduct.setEnabled(false); bDisassociate.setEnabled(true); } xProductTable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int rowP = xProductTable.getSelectedRow(); if (!(rowP == -1)) { cmd_associate(); } } } }); // Init statusBar.setStatusLine(""); statusBar.setStatusDB(0); MOrder order = new MOrder(Env.getCtx(), LineRefProv.getC_Order_ID(), null); boolean block = false; String oS = order.getXX_OrderStatus(); String compS = order.getDocStatus(); if (oS.equals("AN") || compS.equals("CO")) { block = true; } if (order.isXX_OrderReadyStatus() && order.getXX_OrderType().equalsIgnoreCase("Nacional")) block = true; if (order.getXX_OrderType().equalsIgnoreCase("Importada") && order.get_ValueAsInt("XX_ImportingCompany_ID") != 0) { if (order.get_ValueAsInt("XX_ImportingCompany_ID") != Env.getCtx().getContextAsInt("#XX_L_VSI_CLIENTCENTROBECO_ID")) { block = true; } } if (order.getXX_StoreDistribution().equals("Y") || block) { xProductTable.setEnabled(false); xAssociateTable.setEnabled(false); bNewProduct.setEnabled(false); bDisassociate.setEnabled(false); } } // dynInit
/** Refresh Query */ private void refresh(Object obj, int M_Warehouse_ID, int M_PriceList_Version_ID) { // int M_Product_ID = 0; String sql = m_sqlWarehouse; // Add description to the query sql = sql.replace(" FROM", ", DocumentNote FROM"); log.finest(sql); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, (String) obj); rs = pstmt.executeQuery(); fieldDescription.setText(""); warehouseTbl.loadTable(rs); rs = pstmt.executeQuery(); if (rs.next()) if (rs.getString("DocumentNote") != null) fieldDescription.setText(rs.getString("DocumentNote")); } catch (Exception e) { log.log(Level.WARNING, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } m_M_Product_ID = getSelectedRowKey(); sql = m_sqlSubstitute; log.finest(sql); try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_M_Product_ID); pstmt.setInt(2, M_PriceList_Version_ID); rs = pstmt.executeQuery(); substituteTbl.loadTable(rs); rs.close(); } catch (Exception e) { log.log(Level.WARNING, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } sql = m_sqlRelated; log.finest(sql); try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_M_Product_ID); pstmt.setInt(2, M_PriceList_Version_ID); rs = pstmt.executeQuery(); relatedTbl.loadTable(rs); rs.close(); } catch (Exception e) { log.log(Level.WARNING, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } initAtpTab(M_Warehouse_ID); } // refresh
/** Query ATP */ private void initAtpTab(int m_M_Warehouse_ID) { // Header Vector<String> columnNames = new Vector<String>(); columnNames.add(Msg.translate(Env.getCtx(), "Date")); columnNames.add(Msg.translate(Env.getCtx(), "QtyOnHand")); columnNames.add(Msg.translate(Env.getCtx(), "C_BPartner_ID")); columnNames.add(Msg.translate(Env.getCtx(), "QtyOrdered")); columnNames.add(Msg.translate(Env.getCtx(), "QtyReserved")); columnNames.add(Msg.translate(Env.getCtx(), "M_Locator_ID")); columnNames.add(Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID")); columnNames.add(Msg.translate(Env.getCtx(), "DocumentNo")); columnNames.add(Msg.translate(Env.getCtx(), "M_Warehouse_ID")); // Fill Storage Data boolean showDetail = CLogMgt.isLevelFine(); String sql = "SELECT s.QtyOnHand, s.QtyReserved, s.QtyOrdered," + " productAttribute(s.M_AttributeSetInstance_ID), s.M_AttributeSetInstance_ID,"; if (!showDetail) sql = "SELECT SUM(s.QtyOnHand), SUM(s.QtyReserved), SUM(s.QtyOrdered)," + " productAttribute(s.M_AttributeSetInstance_ID), 0,"; sql += " w.Name, l.Value " + "FROM M_Storage s" + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID) " + "WHERE M_Product_ID=?"; if (m_M_Warehouse_ID != 0) sql += " AND l.M_Warehouse_ID=?"; if (m_M_AttributeSetInstance_ID > 0) sql += " AND s.M_AttributeSetInstance_ID=?"; sql += " AND (s.QtyOnHand<>0 OR s.QtyReserved<>0 OR s.QtyOrdered<>0)"; if (!showDetail) sql += " GROUP BY productAttribute(s.M_AttributeSetInstance_ID), w.Name, l.Value"; sql += " ORDER BY l.Value"; Vector<Vector<Object>> data = new Vector<Vector<Object>>(); double qty = 0; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_M_Product_ID); if (m_M_Warehouse_ID != 0) pstmt.setInt(2, m_M_Warehouse_ID); if (m_M_AttributeSetInstance_ID > 0) pstmt.setInt(3, m_M_AttributeSetInstance_ID); rs = pstmt.executeQuery(); while (rs.next()) { Vector<Object> line = new Vector<Object>(9); line.add(null); // Date double qtyOnHand = rs.getDouble(1); qty += qtyOnHand; line.add(new Double(qtyOnHand)); // Qty line.add(null); // BPartner line.add(new Double(rs.getDouble(3))); // QtyOrdered line.add(new Double(rs.getDouble(2))); // QtyReserved line.add(rs.getString(7)); // Locator String asi = rs.getString(4); if (showDetail && (asi == null || asi.length() == 0)) asi = "{" + rs.getInt(5) + "}"; line.add(asi); // ASI line.add(null); // DocumentNo line.add(rs.getString(6)); // Warehouse data.add(line); } } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } // Orders sql = "SELECT ol.DatePromised, ol.QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID), ol.M_AttributeSetInstance_ID," + " dt.DocBaseType, bp.Name," + " dt.PrintName || ' ' || o.DocumentNo As DocumentNo, w.Name " + "FROM C_Order o" + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Warehouse w ON (ol.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp ON (o.C_BPartner_ID=bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0" + " AND ol.M_Product_ID=?"; if (m_M_Warehouse_ID != 0) sql += " AND ol.M_Warehouse_ID=?"; if (m_M_AttributeSetInstance_ID > 0) sql += " AND ol.M_AttributeSetInstance_ID=?"; sql += " ORDER BY o.DatePromised"; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_M_Product_ID); if (m_M_Warehouse_ID != 0) pstmt.setInt(2, m_M_Warehouse_ID); if (m_M_AttributeSetInstance_ID > 0) pstmt.setInt(3, m_M_AttributeSetInstance_ID); rs = pstmt.executeQuery(); while (rs.next()) { Vector<Object> line = new Vector<Object>(9); line.add(rs.getTimestamp(1)); // Date double oq = rs.getDouble(2); String DocBaseType = rs.getString(5); Double qtyReserved = null; Double qtyOrdered = null; if (MDocType.DOCBASETYPE_PurchaseOrder.equals(DocBaseType)) { qtyOrdered = new Double(oq); qty += oq; } else { qtyReserved = new Double(oq); qty -= oq; } line.add(new Double(qty)); // Qty line.add(rs.getString(6)); // BPartner line.add(qtyOrdered); // QtyOrdered line.add(qtyReserved); // QtyReserved line.add(null); // Locator String asi = rs.getString(3); if (showDetail && (asi == null || asi.length() == 0)) asi = "{" + rs.getInt(4) + "}"; line.add(asi); // ASI line.add(rs.getString(7)); // DocumentNo line.add(rs.getString(8)); // Warehouse data.add(line); } } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } // Table MiniTable table = null; m_modelAtp = new DefaultTableModel(data, columnNames); m_tableAtp.setModel(m_modelAtp); table = m_tableAtp; // table.setColumnClass(0, Timestamp.class, true); // Date table.setColumnClass(1, Double.class, true); // Quantity table.setColumnClass(2, String.class, true); // Partner table.setColumnClass(3, Double.class, true); // Quantity table.setColumnClass(4, Double.class, true); // Quantity table.setColumnClass(5, String.class, true); // Locator table.setColumnClass(6, String.class, true); // ASI table.setColumnClass(7, String.class, true); // DocNo table.setColumnClass(8, String.class, true); // Warehouse // table.autoSize(); } // initAtpTab
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(); } }
/** * Dynamic Init * * @param C_BPartner_ID BP */ private void dynInit(int C_BPartner_ID) { log.config("C_BPartner_ID=" + C_BPartner_ID); if (C_BPartner_ID != 0) { int ShelfLifeMinPct = 0; int ShelfLifeMinDays = 0; String sql = "SELECT bp.ShelfLifeMinPct, bpp.ShelfLifeMinPct, bpp.ShelfLifeMinDays " + "FROM C_BPartner bp " + " LEFT OUTER JOIN C_BPartner_Product bpp" + " ON (bp.C_BPartner_ID=bpp.C_BPartner_ID AND bpp.M_Product_ID=?) " + "WHERE bp.C_BPartner_ID=?"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_M_Product_ID); pstmt.setInt(2, C_BPartner_ID); rs = pstmt.executeQuery(); if (rs.next()) { ShelfLifeMinPct = rs.getInt(1); // BP int pct = rs.getInt(2); // BP_P if (pct > 0) // overwrite ShelfLifeMinDays = pct; ShelfLifeMinDays = rs.getInt(3); } } catch (Exception e) { log.log(Level.SEVERE, sql, e); } finally { DB.close(rs, pstmt); rs = null; pstmt = null; } if (ShelfLifeMinPct > 0) { s_sqlMinLife = " AND COALESCE(TRUNC(((daysbetween(asi.GuaranteeDate, SYSDATE))/p.GuaranteeDays)*100),0)>=" + ShelfLifeMinPct; log.config("PAttributeInstance.dynInit - ShelfLifeMinPct=" + ShelfLifeMinPct); } if (ShelfLifeMinDays > 0) { s_sqlMinLife += " AND COALESCE((daysbetween(asi.GuaranteeDate, SYSDATE)),0)>=" + ShelfLifeMinDays; log.config("PAttributeInstance.dynInit - ShelfLifeMinDays=" + ShelfLifeMinDays); } } // BPartner != 0 m_sql = m_table.prepareTable( s_layout, s_sqlFrom, s_sqlWhereWithoutWarehouse + s_sqlNonZero, false, "asi") + " ORDER BY asi.GuaranteeDate, s.QtyOnHand"; // oldest, smallest first // m_table.setRowSelectionAllowed(true); m_table.setMultiSelection(false); m_table.addMouseListener(this); m_table.getSelectionModel().addListSelectionListener(this); // refresh(); // The minitable class overrides the Enter key if multi-selection is false m_table.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doDispose"); m_table.getActionMap().put("doDispose", doDispose); }
/** Static Setup - add fields to parameterPanel */ private void statInit() { labelValue.setText(Msg.getMsg(Env.getCtx(), "Value")); fieldValue.setBackground(AdempierePLAF.getInfoBackground()); fieldValue.addActionListener(this); labelName.setText(Msg.getMsg(Env.getCtx(), "Name")); fieldName.setBackground(AdempierePLAF.getInfoBackground()); fieldName.addActionListener(this); labelUPC.setText(Msg.translate(Env.getCtx(), "UPC")); fieldUPC.setBackground(AdempierePLAF.getInfoBackground()); fieldUPC.addActionListener(this); labelSKU.setText(Msg.translate(Env.getCtx(), "SKU")); fieldSKU.setBackground(AdempierePLAF.getInfoBackground()); fieldSKU.addActionListener(this); labelWarehouse.setText(Msg.getMsg(Env.getCtx(), "Warehouse")); pickWarehouse.setBackground(AdempierePLAF.getInfoBackground()); labelPriceList.setText(Msg.getMsg(Env.getCtx(), "PriceListVersion")); pickPriceList.setBackground(AdempierePLAF.getInfoBackground()); labelProductCategory.setText(Msg.translate(Env.getCtx(), "M_Product_Category_ID")); pickProductCategory.setBackground(AdempierePLAF.getInfoBackground()); // @Trifon labelAS.setText(Msg.translate(Env.getCtx(), "M_AttributeSet_ID")); pickAS.setBackground(AdempierePLAF.getInfoBackground()); m_InfoPAttributeButton.setMargin(new Insets(2, 2, 2, 2)); m_InfoPAttributeButton.setToolTipText(Msg.getMsg(Env.getCtx(), "InfoPAttribute")); m_InfoPAttributeButton.addActionListener(this); labelVendor.setText(Msg.translate(Env.getCtx(), "Vendor")); fieldVendor.setBackground(AdempierePLAF.getInfoBackground()); fieldVendor.addActionListener(this); // Line 1 parameterPanel.setLayout(new ALayout()); parameterPanel.add(labelValue, new ALayoutConstraint(0, 0)); parameterPanel.add(fieldValue, null); parameterPanel.add(labelUPC, null); parameterPanel.add(fieldUPC, null); parameterPanel.add(labelWarehouse, null); parameterPanel.add(pickWarehouse, null); parameterPanel.add(m_InfoPAttributeButton); // Line 2 parameterPanel.add(labelName, new ALayoutConstraint(1, 0)); parameterPanel.add(fieldName, null); parameterPanel.add(labelSKU, null); parameterPanel.add(fieldSKU, null); parameterPanel.add(labelVendor, null); parameterPanel.add(fieldVendor, null); // Line 3 parameterPanel.add(labelPriceList, new ALayoutConstraint(2, 0)); parameterPanel.add(pickPriceList, null); parameterPanel.add(labelProductCategory, null); parameterPanel.add(pickProductCategory, null); parameterPanel.add(labelAS, null); // @Trifon parameterPanel.add(pickAS, null); // @Trifon // Product Attribute Instance m_PAttributeButton = ConfirmPanel.createPAttributeButton(true); confirmPanel.addButton(m_PAttributeButton); m_PAttributeButton.addActionListener(this); m_PAttributeButton.setEnabled(false); // Begin - fer_luck @ centuryon // add taskpane fieldDescription.setBackground(AdempierePLAF.getInfoBackground()); fieldDescription.setEditable(false); fieldDescription.setPreferredSize(new Dimension(INFO_WIDTH - 100, 100)); warehouseStockPanel.setTitle(Msg.translate(Env.getCtx(), "WarehouseStock")); warehouseStockPanel.setUI(new AdempiereTaskPaneUI()); warehouseStockPanel.getContentPane().setBackground(new ColorUIResource(251, 248, 241)); warehouseStockPanel.getContentPane().setForeground(new ColorUIResource(251, 0, 0)); ColumnInfo[] s_layoutWarehouse = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "Warehouse"), "Warehouse", String.class), new ColumnInfo( Msg.translate(Env.getCtx(), "QtyAvailable"), "sum(QtyAvailable)", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "sum(QtyOnHand)", Double.class), new ColumnInfo( Msg.translate(Env.getCtx(), "QtyReserved"), "sum(QtyReserved)", Double.class), new ColumnInfo( Msg.translate(Env.getCtx(), "QtyAllocated"), "sum(QtyAllocated)", Double.class) }; /** From Clause */ String s_sqlFrom = " M_PRODUCT_STOCK_V "; /** Where Clause */ String s_sqlWhere = "Value = ?"; m_sqlWarehouse = warehouseTbl.prepareTable( s_layoutWarehouse, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_STOCK_V"); m_sqlWarehouse += " Group By Warehouse, documentnote "; warehouseTbl.setRowSelectionAllowed(true); warehouseTbl.setMultiSelection(false); warehouseTbl.addMouseListener(this); warehouseTbl.getSelectionModel().addListSelectionListener(this); warehouseTbl.setShowTotals(true); warehouseTbl.autoSize(); ColumnInfo[] s_layoutSubstitute = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "Warehouse"), "orgname", String.class), new ColumnInfo( Msg.translate(Env.getCtx(), "Value"), "(Select Value from M_Product p where p.M_Product_ID=M_PRODUCT_SUBSTITUTERELATED_V.Substitute_ID)", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), "Name", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"), "QtyAvailable", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "QtyOnHand", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "QtyReserved", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "PriceStd"), "PriceStd", Double.class) }; s_sqlFrom = "M_PRODUCT_SUBSTITUTERELATED_V"; s_sqlWhere = "M_Product_ID = ? AND M_PriceList_Version_ID = ? and RowType = 'S'"; m_sqlSubstitute = substituteTbl.prepareTable( s_layoutSubstitute, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_SUBSTITUTERELATED_V"); substituteTbl.setRowSelectionAllowed(false); substituteTbl.setMultiSelection(false); substituteTbl.addMouseListener(this); substituteTbl.getSelectionModel().addListSelectionListener(this); substituteTbl.autoSize(); ColumnInfo[] s_layoutRelated = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "Warehouse"), "orgname", String.class), new ColumnInfo( Msg.translate(Env.getCtx(), "Value"), "(Select Value from M_Product p where p.M_Product_ID=M_PRODUCT_SUBSTITUTERELATED_V.Substitute_ID)", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), "Name", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"), "QtyAvailable", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "QtyOnHand", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "QtyReserved", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "PriceStd"), "PriceStd", Double.class) }; s_sqlFrom = "M_PRODUCT_SUBSTITUTERELATED_V"; s_sqlWhere = "M_Product_ID = ? AND M_PriceList_Version_ID = ? and RowType = 'R'"; m_sqlRelated = relatedTbl.prepareTable( s_layoutRelated, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_SUBSTITUTERELATED_V"); relatedTbl.setRowSelectionAllowed(false); relatedTbl.setMultiSelection(false); relatedTbl.addMouseListener(this); relatedTbl.getSelectionModel().addListSelectionListener(this); relatedTbl.autoSize(); // Available to Promise Tab m_tableAtp.setRowSelectionAllowed(false); m_tableAtp.setMultiSelection(false); CTabbedPane jTab = new CTabbedPane(); jTab.addTab(Msg.translate(Env.getCtx(), "Warehouse"), new JScrollPane(warehouseTbl)); jTab.setPreferredSize(new Dimension(INFO_WIDTH, SCREEN_HEIGHT > 600 ? 250 : 105)); jTab.addTab(Msg.translate(Env.getCtx(), "Description"), new JScrollPane(fieldDescription)); jTab.addTab(Msg.translate(Env.getCtx(), "Substitute_ID"), new JScrollPane(substituteTbl)); jTab.addTab(Msg.translate(Env.getCtx(), "RelatedProduct_ID"), new JScrollPane(relatedTbl)); jTab.addTab(Msg.getMsg(Env.getCtx(), "ATP"), new JScrollPane(m_tableAtp)); jTab.addChangeListener(this); tablePanel.setPreferredSize(new Dimension(INFO_WIDTH, SCREEN_HEIGHT > 600 ? 255 : 110)); tablePanel.add(jTab); warehouseStockPanel.setCollapsed(true); warehouseStockPanel.add(tablePanel); this.addonPanel.add(warehouseStockPanel); this.p_table.addKeyListener( new KeyAdapter() { public void keyReleased(KeyEvent ke) { int row = ((MiniTable) ke.getSource()).getSelectedRow(); refresh( ((MiniTable) ke.getSource()).getValueAt(row, 2), new BigDecimal(pickWarehouse.getValue().toString()).intValue(), new BigDecimal(pickPriceList.getValue().toString()).intValue()); warehouseStockPanel.setCollapsed(false); } }); this.p_table.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent me) { int row = ((MiniTable) me.getSource()).getSelectedRow(); refresh( ((MiniTable) me.getSource()).getValueAt(row, 2), new BigDecimal(pickWarehouse.getValue().toString()).intValue(), new BigDecimal(pickPriceList.getValue().toString()).intValue()); warehouseStockPanel.setCollapsed(false); } }); // End - fer_luck @ centuryon } // statInit
/** Enable/Set Buttons and set ID */ private void enableButtons() { int row = m_table.getSelectedRow(); boolean enabled = row > -1; confirmPanel.getOKButton().setEnabled(enabled); }
@Override public void setAutoResize(boolean autoResize) { super.setAutoResize(autoResize); }
/** * Mouse Clicked * * @param e event */ public void mouseClicked(MouseEvent e) { // Double click with selected row => exit if (e.getClickCount() > 1 && m_table.getSelectedRow() > -1) { dispose(); } }