diff --git a/client/src/org/compiere/grid/VCreateFromShipment.java b/client/src/org/compiere/grid/CreateFromShipment.java similarity index 54% rename from client/src/org/compiere/grid/VCreateFromShipment.java rename to client/src/org/compiere/grid/CreateFromShipment.java index a834c0be3a..86d14bea1f 100644 --- a/client/src/org/compiere/grid/VCreateFromShipment.java +++ b/client/src/org/compiere/grid/CreateFromShipment.java @@ -1,6 +1,6 @@ /****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * + * Copyright (C) 2009 Low Heng Sin * + * Copyright (C) 2009 Idalica Corporation * * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * * by the Free Software Foundation. This program is distributed in the hope * @@ -10,42 +10,29 @@ * You should have received a copy of the GNU General Public License along * * with this program; if not, write to the Free Software Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * *****************************************************************************/ + package org.compiere.grid; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.VetoableChangeListener; import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; +import java.util.ArrayList; import java.util.Vector; import java.util.logging.Level; -import javax.swing.AbstractCellEditor; -import javax.swing.JTable; -import javax.swing.event.CellEditorListener; -import javax.swing.event.ChangeEvent; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableCellEditor; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import org.adempiere.plaf.AdempierePLAF; -import org.compiere.grid.ed.VLocator; +import org.compiere.minigrid.IMiniTable; import org.compiere.model.GridTab; import org.compiere.model.MInOut; import org.compiere.model.MInOutLine; import org.compiere.model.MInvoice; import org.compiere.model.MInvoiceLine; import org.compiere.model.MLocator; -import org.compiere.model.MLocatorLookup; import org.compiere.model.MOrder; import org.compiere.model.MOrderLine; import org.compiere.model.MProduct; @@ -59,228 +46,92 @@ import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; /** - * Create Shipments Transactions - from PO Orders or AP Invoices + * Create Invoice Transactions from PO Orders or Receipt * * @author Jorg Janke - * @author victor.perez@e-evolution.com, e-Evolution http://www.e-evolution.com - *
  • BF 2530254 It is wrong locator in material receipt for outsourced PO's - * @see http://sourceforge.net/tracker2/?func=detail&atid=879332&aid=2530254&group_id=176962 * @version $Id: VCreateFromShipment.java,v 1.4 2006/07/30 00:51:28 jjanke Exp $ * - * @author Teo Sarca, www.arhipac.ro + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + *
  • BF [ 1896947 ] Generate invoice from Order error *
  • BF [ 2007837 ] VCreateFrom.save() should run in trx - *
  • BF [ 2584790 ] Material Receipt error */ -public class VCreateFromShipment extends VCreateFrom implements VetoableChangeListener +public class CreateFromShipment extends CreateFrom { - /** - * - */ - private static final long serialVersionUID = -6317997004973385619L; - - /** - * Cell editor specific for the MLocator in this form's table. - */ - public class InnerLocatorTableCellEditor extends AbstractCellEditor - implements TableCellEditor, CellEditorListener - { - /** - * - */ - private static final long serialVersionUID = 8368583005837688626L; - private KeyNamePair m_locatorKey; - private VLocator m_editor; - private JTable m_table; - private int m_row; - private int m_column; - - public InnerLocatorTableCellEditor() - { - addCellEditorListener(this); - } - - public Object getCellEditorValue() - { - return m_locatorKey; - } - - /** - * - * @param table - * @param value The current value in the cell. In this case, a KeyName pair of the locator - * @param isSelected - * @param row - * @param column - * @return - */ - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) - { - m_table = table; - m_row = row; - m_column = column; - m_locatorKey = (KeyNamePair)value; - MLocatorLookup mLocatorLookup = new MLocatorLookup(Env.getCtx(), 0); - m_editor = new VLocator("M_Locator_ID", true, false, true, mLocatorLookup, 0); - m_editor.setValue(m_locatorKey.getKey()); - return m_editor; - } - - /** - * When editing stops (editing done), save the value in the table model - * and update the product's default locator. - * - * @param e - */ - public void editingStopped(ChangeEvent e) - { - // Editing ends, save value - if (m_editor.getValue() != null) - { - int key = ((Integer)m_editor.getValue()).intValue(); - MLocator locator = MLocator.get(Env.getCtx(), key); - m_locatorKey = new KeyNamePair(key, locator.getValue()); - m_table.getModel().setValueAt(m_locatorKey, m_row, m_column); - } - } - - /** - * When editing stops, do nothing. - * @param e - */ - public void editingCanceled(ChangeEvent e) - { - } - - } - // == END OF INNER CLASS InnerLocatorTableCellEditor - + /** Loaded Invoice */ + private MInvoice m_invoice = null; + /** Loaded RMA */ + private MRMA m_rma = null; + private int defaultLocator_ID=0; /** * Protected Constructor * @param mTab MTab */ - public VCreateFromShipment(GridTab mTab) + public CreateFromShipment(GridTab mTab) { - super (mTab); - // log.info( "VCreateFromShipment"); + super(mTab); + log.info(mTab.toString()); } // VCreateFromShipment - /** Loaded Invoice */ - private MInvoice m_invoice = null; - /** Loaded RMA */ - private MRMA m_rma = null; - - private static int COL_SELECT = 0; - private static int COL_QTY = 1; - private static int COL_UOM = 2; - private static int COL_LOCATOR_ID = 3; - private static int COL_PRODUCT_ID = 4; - private static int COL_VENDORPRODNO = 5; - private static int COL_ORDER_ID = 6; - private static int COL_RMA_ID = 7; - private static int COL_INVOICE_ID = 8; - - /** - * Column names - * Override names from parent class since it differs on COL_RMA_ID. - */ - protected String[] colNames = new String[] { - Msg.getMsg(Env.getCtx(), "Select"), - Msg.translate(Env.getCtx(), "Quantity"), - Msg.translate(Env.getCtx(), "C_UOM_ID"), - Msg.translate((Env.getCtx()), "M_Locator_ID"), - Msg.translate(Env.getCtx(), "M_Product_ID"), - Msg.getElement(Env.getCtx(), "VendorProductNo", false), - Msg.getElement(Env.getCtx(), "C_Order_ID", false), - Msg.getElement(Env.getCtx(), "M_RMA_ID", false), - Msg.getElement(Env.getCtx(), "C_Invoice_ID", false) - }; - - - /** - * Load Order/Invoice/RMA data into Table - * @param data data - */ - @Override - protected void loadTableOIS (Vector data) - { - // Header Info - Vector columnNames = new Vector(colNames.length); - for (int i=0; i loadInvoiceData (int C_BPartner_ID) { - // load AP Invoice closed or complete - invoiceField.removeActionListener(this); - invoiceField.removeAllItems(); - // None - KeyNamePair pp = new KeyNamePair(0,""); - invoiceField.addItem(pp); + ArrayList list = new ArrayList(); + StringBuffer display = new StringBuffer("i.DocumentNo||' - '||") .append(DB.TO_CHAR("DateInvoiced", DisplayType.Date, Env.getAD_Language(Env.getCtx()))) .append("|| ' - ' ||") @@ -309,211 +160,24 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi rs = pstmt.executeQuery(); while (rs.next()) { - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - invoiceField.addItem(pp); + list.add(new KeyNamePair(rs.getInt(1), rs.getString(2))); } + rs.close(); + pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - invoiceField.setSelectedIndex(0); - invoiceField.addActionListener(this); - upcField.addActionListener(this); + return list; } - - /** - * Load RMA that are candidates for shipment - * @param C_BPartner_ID BPartner - */ - private void initBPRMADetails(int C_BPartner_ID) - { - rmaField.removeActionListener(this); - rmaField.removeAllItems(); - // None - KeyNamePair pp = new KeyNamePair(0,""); - rmaField.addItem(pp); - - String sqlStmt = "SELECT r.M_RMA_ID, r.DocumentNo || '-' || r.Amt from M_RMA r " - + "WHERE ISSOTRX='Y' AND r.DocStatus in ('CO', 'CL') " - + "AND r.C_BPartner_ID=? " - + "AND r.M_RMA_ID in (SELECT rl.M_RMA_ID FROM M_RMALine rl " - + "WHERE rl.M_RMA_ID=r.M_RMA_ID AND rl.QtyDelivered < rl.Qty " - + "AND rl.M_InOutLine_ID IS NOT NULL)"; - - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sqlStmt, null); - pstmt.setInt(1, C_BPartner_ID); - rs = pstmt.executeQuery(); - while (rs.next()) - { - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - rmaField.addItem(pp); - } - } - catch (SQLException e) - { - log.log(Level.SEVERE, sqlStmt.toString(), e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - rmaField.setSelectedIndex(0); - rmaField.addActionListener(this); - } - - - /** - * Action Listener - * @param e event - */ - public void actionPerformed(ActionEvent e) - { - super.actionPerformed(e); - log.config("Action=" + e.getActionCommand()); - - // Order - if (e.getSource().equals(orderField)) - { - KeyNamePair pp = (KeyNamePair)orderField.getSelectedItem(); - if (pp == null || pp.getKey() == 0) - ; - else - { - int C_Order_ID = pp.getKey(); - // set Invoice and Shipment to Null - invoiceField.setSelectedIndex(-1); - shipmentField.setSelectedIndex(-1); - rmaField.setSelectedIndex(-1); - loadOrder(C_Order_ID, false); - m_invoice = null; - } - } - // Invoice - else if (e.getSource().equals(invoiceField)) - { - KeyNamePair pp = (KeyNamePair)invoiceField.getSelectedItem(); - if (pp == null || pp.getKey() == 0) - ; - else - { - int C_Invoice_ID = pp.getKey(); - // set Order and Shipment to Null - orderField.setSelectedIndex(-1); - shipmentField.setSelectedIndex(-1); - rmaField.setSelectedIndex(-1); - loadInvoice(C_Invoice_ID); - } - } - // RMA - else if (e.getSource().equals(rmaField)) - { - KeyNamePair pp = (KeyNamePair)rmaField.getSelectedItem(); - if (pp == null || pp.getKey() == 0) - ; - else - { - int M_RMA_ID = pp.getKey(); - // set Order and Shipment to Null - orderField.setSelectedIndex(-1); - shipmentField.setSelectedIndex(-1); - invoiceField.setSelectedIndex(-1); - loadRMA(M_RMA_ID); - } - } - //sameWarehouseCb - else if (e.getSource().equals(sameWarehouseCb)) - { - initBPartnerOIS(((Integer)bPartnerField.getValue()).intValue(), false); - } - else if (e.getSource().equals(upcField)) - { - checkProductUsingUPC(); - } - - } // actionPerformed - - - /** - * Checks the UPC value and checks if the UPC matches any of the products in the - * list. - */ - private void checkProductUsingUPC() - { - String upc = upcField.getText(); - DefaultTableModel model = (DefaultTableModel)dataTable.getModel(); - // Lookup UPC - List products = MProduct.getByUPC(Env.getCtx(), upc, null); - for (MProduct product : products) - { - int row = findProductRow(product.get_ID()); - if (row >= 0) - { - BigDecimal qty = (BigDecimal)model.getValueAt(row, COL_QTY); - model.setValueAt(qty, row, COL_QTY); - model.setValueAt(Boolean.TRUE, row, COL_SELECT); - model.fireTableRowsUpdated(row, row); - } - } - upcField.setText(""); - upcField.requestFocusInWindow(); - } - - /** - * Finds the row where a given product is. If the product is not found - * in the table -1 is returned. - * @param M_Product_ID - * @return Row of the product or -1 if non existing. - * - */ - private int findProductRow(int M_Product_ID) - { - DefaultTableModel model = (DefaultTableModel)dataTable.getModel(); - KeyNamePair kp; - for (int i=0; i> getOrderData (int C_Order_ID, boolean forInvoice) { /** * Selected - 0 @@ -529,7 +193,7 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi log.config("C_Order_ID=" + C_Order_ID); p_order = new MOrder (Env.getCtx(), C_Order_ID, null); // save - Vector> data = new Vector>(); + Vector> data = new Vector>(); StringBuffer sql = new StringBuffer("SELECT " + "l.QtyOrdered-SUM(COALESCE(m.Qty,0))," // 1 + "CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END," // 2 @@ -599,31 +263,104 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi DB.close(rs, pstmt); rs = null; pstmt = null; } - loadTableOIS (data); + return data; } // LoadOrder + + /** + * Load RMA details + * @param M_RMA_ID RMA + */ + protected Vector> getRMAData(int M_RMA_ID) + { + m_invoice = null; + p_order = null; + m_rma = new MRMA(Env.getCtx(), M_RMA_ID, null); + + Vector> data = new Vector>(); + StringBuffer sqlStmt = new StringBuffer(); + sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - rl.QtyDelivered, iol.M_Product_ID, p.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) "); + sqlStmt.append("FROM M_RMALine rl INNER JOIN M_InOutLine iol ON rl.M_InOutLine_ID=iol.M_InOutLine_ID "); + + if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) + { + sqlStmt.append("LEFT OUTER JOIN C_UOM uom ON (uom.C_UOM_ID=iol.C_UOM_ID) "); + } + else + { + sqlStmt.append("LEFT OUTER JOIN C_UOM_Trl uom ON (uom.C_UOM_ID=iol.C_UOM_ID AND uom.AD_Language='"); + sqlStmt.append(Env.getAD_Language(Env.getCtx())).append("') "); + } + sqlStmt.append("LEFT OUTER JOIN M_Product p ON p.M_Product_ID=iol.M_Product_ID "); + sqlStmt.append("WHERE rl.M_RMA_ID=? "); + sqlStmt.append("AND rl.M_INOUTLINE_ID IS NOT NULL"); + + sqlStmt.append(" UNION "); + + sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - rl.QtyDelivered, 0, c.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) "); + sqlStmt.append("FROM M_RMALine rl INNER JOIN C_Charge c ON c.C_Charge_ID = rl.C_Charge_ID "); + if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) + { + sqlStmt.append("LEFT OUTER JOIN C_UOM uom ON (uom.C_UOM_ID=100) "); + } + else + { + sqlStmt.append("LEFT OUTER JOIN C_UOM_Trl uom ON (uom.C_UOM_ID=100 AND uom.AD_Language='"); + sqlStmt.append(Env.getAD_Language(Env.getCtx())).append("') "); + } + sqlStmt.append("WHERE rl.M_RMA_ID=? "); + sqlStmt.append("AND rl.C_Charge_ID IS NOT NULL"); + + PreparedStatement pstmt = null; + ResultSet rs = null; + try + { + pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt.setInt(1, M_RMA_ID); + pstmt.setInt(2, M_RMA_ID); + rs = pstmt.executeQuery(); + + while (rs.next()) + { + Vector line = new Vector(7); + line.add(new Boolean(false)); // 0-Selection + line.add(rs.getBigDecimal(3)); // 1-Qty + KeyNamePair pp = new KeyNamePair(rs.getInt(6), rs.getString(7)); + line.add(pp); // 2-UOM + line.add(getLocatorKeyNamePair(0)); + pp = new KeyNamePair(rs.getInt(4), rs.getString(5)); + line.add(pp); // 4-Product + line.add(null); //5-Vendor Product No + line.add(null); //6-Order + pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); + line.add(pp); //7-RMA + line.add(null); //8-invoice + data.add(line); + } + } + catch (Exception ex) + { + log.log(Level.SEVERE, sqlStmt.toString(), ex); + } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } + + return data; + } /** - * Load Data - Invoice - * @param C_Invoice_ID Invoice - * - * Selected - 0 - * Qty - 1 - * C_UOM_ID - 2 - * M_Locator_ID - 3 - * M_Product_ID - 4 - * VendorProductNo - 5 - * OrderLine - 6 - * ShipmentLine - 7 - * InvoiceLine - 8 + * Load Invoice details + * @param C_Invoice_ID Invoice */ - private void loadInvoice(int C_Invoice_ID) + protected Vector> getInvoiceData(int C_Invoice_ID) { - log.config("C_Invoice_ID=" + C_Invoice_ID); m_invoice = new MInvoice(Env.getCtx(), C_Invoice_ID, null); // save p_order = null; m_rma = null; - - Vector> data = new Vector>(); + + Vector> data = new Vector>(); StringBuffer sql = new StringBuffer("SELECT " // Entered UOM + "l.QtyInvoiced-SUM(NVL(mi.Qty,0)),l.QtyEntered/l.QtyInvoiced," + " l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name)," // 3..4 @@ -687,119 +424,101 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi log.log(Level.SEVERE, sql.toString(), e); //throw new DBException(e, sql); } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - loadTableOIS(data); - } // loadInvoice - + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } + return data; + } + /** - * Load RMA details - * @param M_RMA_ID RMA + * Get KeyNamePair for Locator. + * If no locator specified or the specified locator is not valid (e.g. warehouse not match), + * a default one will be used. + * @param M_Locator_ID + * @return KeyNamePair */ - private void loadRMA(int M_RMA_ID) + protected KeyNamePair getLocatorKeyNamePair(int M_Locator_ID) { - m_invoice = null; - p_order = null; - - m_rma = new MRMA(Env.getCtx(), M_RMA_ID, null); - - Vector> data = new Vector>(); - StringBuffer sqlStmt = new StringBuffer(); - sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - rl.QtyDelivered, iol.M_Product_ID, p.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) "); - sqlStmt.append("FROM M_RMALine rl INNER JOIN M_InOutLine iol ON rl.M_InOutLine_ID=iol.M_InOutLine_ID "); - - if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) + MLocator locator = null; + + // Load desired Locator + if (M_Locator_ID > 0) { - sqlStmt.append("LEFT OUTER JOIN C_UOM uom ON (uom.C_UOM_ID=iol.C_UOM_ID) "); - } - else - { - sqlStmt.append("LEFT OUTER JOIN C_UOM_Trl uom ON (uom.C_UOM_ID=iol.C_UOM_ID AND uom.AD_Language='"); - sqlStmt.append(Env.getAD_Language(Env.getCtx())).append("') "); - } - sqlStmt.append("LEFT OUTER JOIN M_Product p ON p.M_Product_ID=iol.M_Product_ID "); - sqlStmt.append("WHERE rl.M_RMA_ID=? "); - sqlStmt.append("AND rl.M_INOUTLINE_ID IS NOT NULL"); - - sqlStmt.append(" UNION "); - - sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - rl.QtyDelivered, 0, c.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) "); - sqlStmt.append("FROM M_RMALine rl INNER JOIN C_Charge c ON c.C_Charge_ID = rl.C_Charge_ID "); - if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) - { - sqlStmt.append("LEFT OUTER JOIN C_UOM uom ON (uom.C_UOM_ID=100) "); - } - else - { - sqlStmt.append("LEFT OUTER JOIN C_UOM_Trl uom ON (uom.C_UOM_ID=100 AND uom.AD_Language='"); - sqlStmt.append(Env.getAD_Language(Env.getCtx())).append("') "); - } - sqlStmt.append("WHERE rl.M_RMA_ID=? "); - sqlStmt.append("AND rl.C_Charge_ID IS NOT NULL"); - - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sqlStmt.toString(), null); - pstmt.setInt(1, M_RMA_ID); - pstmt.setInt(2, M_RMA_ID); - rs = pstmt.executeQuery(); - - while (rs.next()) + locator = MLocator.get(Env.getCtx(), M_Locator_ID); + // Validate warehouse + if (locator != null && locator.getM_Warehouse_ID() != getM_Warehouse_ID()) { - Vector line = new Vector(7); - line.add(new Boolean(false)); // 0-Selection - line.add(rs.getBigDecimal(3)); // 1-Qty - KeyNamePair pp = new KeyNamePair(rs.getInt(6), rs.getString(7)); - line.add(pp); // 2-UOM - line.add(getLocatorKeyNamePair(0)); - pp = new KeyNamePair(rs.getInt(4), rs.getString(5)); - line.add(pp); // 4-Product - line.add(null); //5-Vendor Product No - line.add(null); //6-Order - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - line.add(pp); //7-RMA - line.add(null); //8-invoice - data.add(line); + locator = null; } } - catch (Exception ex) + + // Try to use default locator from Order Warehouse + if (locator == null && p_order != null && p_order.getM_Warehouse_ID() == getM_Warehouse_ID()) { - log.log(Level.SEVERE, sqlStmt.toString(), ex); + MWarehouse wh = MWarehouse.get(Env.getCtx(), p_order.getM_Warehouse_ID()); + if (wh != null) + { + locator = wh.getDefaultLocator(); + } } - finally + // Try to get from locator field + if (locator == null) { - DB.close(rs, pstmt); - rs = null; pstmt = null; + if (defaultLocator_ID > 0) + { + locator = MLocator.get(Env.getCtx(), defaultLocator_ID); + } } - loadTableOIS(data); + // Validate Warehouse + if (locator == null || locator.getM_Warehouse_ID() != getM_Warehouse_ID()) + { + locator = MWarehouse.get(Env.getCtx(), getM_Warehouse_ID()).getDefaultLocator(); + } + + KeyNamePair pp = null ; + if (locator != null) + { + pp = new KeyNamePair(locator.get_ID(), locator.getValue()); + } + return pp; + } + + /** + * List number of rows selected + */ + public void info() + { + + } // infoInvoice + + protected void configureMiniTable (IMiniTable miniTable) + { + miniTable.setColumnClass(0, Boolean.class, false); // Selection + miniTable.setColumnClass(1, BigDecimal.class, false); // Qty + miniTable.setColumnClass(2, String.class, true); // UOM + miniTable.setColumnClass(3, String.class, false); // Locator + //TableColumn col = miniTable.getColumnModel().getColumn(3); + //col.setCellEditor(new InnerLocatorTableCellEditor()); + miniTable.setColumnClass(4, String.class, true); // Product + miniTable.setColumnClass(5, String.class, true); // VendorProductNo + miniTable.setColumnClass(6, String.class, true); // Order + miniTable.setColumnClass(7, String.class, true); // Ship + miniTable.setColumnClass(8, String.class, true); // Invoice + + // Table UI + miniTable.autoSize(); + } /** - * List number of rows selected + * Save - Create Invoice Lines + * @return true if saved */ - protected void info() { - TableModel model = dataTable.getModel(); - int rows = model.getRowCount(); - int count = 0; - for (int i = 0; i < rows; i++) { - if (((Boolean) model.getValueAt(i, 0)).booleanValue()) - count++; - } - setStatusLine(count, null); - } // info - - /** - * Save - create Shipments - * - * @return true if saved - */ - protected boolean save(String trxName) - { + public boolean save(IMiniTable miniTable, String trxName) + { + /* dataTable.stopEditor(true); log.config(""); TableModel model = dataTable.getModel(); @@ -812,38 +531,42 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi locatorField.setBackground(AdempierePLAF.getFieldBackground_Error()); return false; } - int M_Locator_ID = defaultLoc.intValue(); + */ + int M_Locator_ID = defaultLocator_ID; + if (M_Locator_ID == 0) { + return false; + } // Get Shipment - int M_InOut_ID = ((Integer) p_mTab.getValue("M_InOut_ID")).intValue(); + int M_InOut_ID = ((Integer) getGridTab().getValue("M_InOut_ID")).intValue(); MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, trxName); log.config(inout + ", C_Locator_ID=" + M_Locator_ID); // Lines - for (int i = 0; i < rows; i++) + for (int i = 0; i < miniTable.getRowCount(); i++) { - if (((Boolean) model.getValueAt(i, 0)).booleanValue()) { + if (((Boolean)miniTable.getValueAt(i, 0)).booleanValue()) { // variable values - BigDecimal QtyEntered = (BigDecimal) model.getValueAt(i, COL_QTY); // Qty - KeyNamePair pp = (KeyNamePair) model.getValueAt(i, COL_UOM); // UOM + BigDecimal QtyEntered = (BigDecimal) miniTable.getValueAt(i, 1); // Qty + KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2); // UOM int C_UOM_ID = pp.getKey(); - pp = (KeyNamePair) model.getValueAt(i, COL_LOCATOR_ID); // Locator + pp = (KeyNamePair) miniTable.getValueAt(i, 3); // Locator // If a locator is specified on the product, choose that otherwise default locator - M_Locator_ID = pp!=null && pp.getKey()!=0 ? pp.getKey() : defaultLoc.intValue(); + M_Locator_ID = pp!=null && pp.getKey()!=0 ? pp.getKey() : defaultLocator_ID; - pp = (KeyNamePair) model.getValueAt(i, COL_PRODUCT_ID); // Product + pp = (KeyNamePair) miniTable.getValueAt(i, 4); // Product int M_Product_ID = pp.getKey(); int C_OrderLine_ID = 0; - pp = (KeyNamePair) model.getValueAt(i, COL_ORDER_ID); // OrderLine + pp = (KeyNamePair) miniTable.getValueAt(i, 6); // OrderLine if (pp != null) C_OrderLine_ID = pp.getKey(); int M_RMALine_ID = 0; - pp = (KeyNamePair) model.getValueAt(i, COL_RMA_ID); // RMA + pp = (KeyNamePair) miniTable.getValueAt(i, 7); // RMA // If we have RMA if (pp != null) M_RMALine_ID = pp.getKey(); int C_InvoiceLine_ID = 0; MInvoiceLine il = null; - pp = (KeyNamePair) model.getValueAt(i, COL_INVOICE_ID); // InvoiceLine + pp = (KeyNamePair) miniTable.getValueAt(i, 8); // InvoiceLine if (pp != null) C_InvoiceLine_ID = pp.getKey(); if (C_InvoiceLine_ID != 0) @@ -1005,61 +728,44 @@ public class VCreateFromShipment extends VCreateFrom implements VetoableChangeLi inout.setUser2_ID(originalIO.getUser2_ID()); } inout.saveEx(); - return true; - } // save + return true; + } // saveInvoice - /** - * Get KeyNamePair for Locator. - * If no locator specified or the specified locator is not valid (e.g. warehouse not match), - * a default one will be used. - * @param M_Locator_ID - * @return KeyNamePair - */ - protected KeyNamePair getLocatorKeyNamePair(int M_Locator_ID) + @Override + protected Vector getOISColumnNames() { - MLocator locator = null; - - // Load desired Locator - if (M_Locator_ID > 0) - { - locator = MLocator.get(Env.getCtx(), M_Locator_ID); - // Validate warehouse - if (locator != null && locator.getM_Warehouse_ID() != getM_Warehouse_ID()) - { - locator = null; - } - } - - // Try to use default locator from Order Warehouse - if (locator == null && p_order != null && p_order.getM_Warehouse_ID() == getM_Warehouse_ID()) - { - MWarehouse wh = MWarehouse.get(Env.getCtx(), p_order.getM_Warehouse_ID()); - if (wh != null) - { - locator = wh.getDefaultLocator(); - } - } - // Try to get from locator field - if (locator == null) - { - Integer id = (Integer) locatorField.getValue(); - if (id != null && id > 0) - { - locator = MLocator.get(Env.getCtx(), id); - } - } - // Validate Warehouse - if (locator == null || locator.getM_Warehouse_ID() != getM_Warehouse_ID()) - { - locator = MWarehouse.get(Env.getCtx(), getM_Warehouse_ID()).getDefaultLocator(); - } - - KeyNamePair pp = null ; - if (locator != null) - { - pp = new KeyNamePair(locator.get_ID(), locator.getValue()); - } - return pp; + // Header Info + Vector columnNames = new Vector(7); + columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); + columnNames.add(Msg.translate(Env.getCtx(), "Quantity")); + columnNames.add(Msg.translate(Env.getCtx(), "C_UOM_ID")); + columnNames.add(Msg.translate(Env.getCtx(), "M_Locator_ID")); + columnNames.add(Msg.translate(Env.getCtx(), "M_Product_ID")); + columnNames.add(Msg.getElement(Env.getCtx(), "VendorProductNo", false)); + columnNames.add(Msg.getElement(Env.getCtx(), "C_Order_ID", false)); + columnNames.add(Msg.getElement(Env.getCtx(), "M_RMA_ID", false)); + columnNames.add(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); + + return columnNames; } -} // VCreateFromShipment + + protected Vector> getOrderData (int C_Order_ID, boolean forInvoice, int M_Locator_ID) + { + defaultLocator_ID = M_Locator_ID; + return getOrderData (C_Order_ID, forInvoice); + } + + protected Vector> getRMAData (int M_RMA_ID, int M_Locator_ID) + { + defaultLocator_ID = M_Locator_ID; + return getRMAData (M_RMA_ID); + } + + protected Vector> getInvoiceData (int C_Invoice_ID, int M_Locator_ID) + { + defaultLocator_ID = M_Locator_ID; + return getInvoiceData (C_Invoice_ID); + } + +} diff --git a/client/src/org/compiere/grid/VCreateFrom.java b/client/src/org/compiere/grid/VCreateFrom.java index e31efddbf4..6f7189ec90 100644 --- a/client/src/org/compiere/grid/VCreateFrom.java +++ b/client/src/org/compiere/grid/VCreateFrom.java @@ -114,7 +114,6 @@ public abstract class VCreateFrom extends CDialog { // Register defaults: s_registeredClasses = new HashMap>(); - s_registeredClasses.put(I_M_InOut.Table_ID, VCreateFromShipment.class); //s_registeredClasses.put(I_C_PaySelection.Table_ID, null); // ignore - will call process C_PaySelection_CreateFrom s_registeredClasses.put(I_M_RMA.Table_ID, VCreateFromRMA.class); } @@ -394,13 +393,13 @@ public abstract class VCreateFrom extends CDialog ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); parameterStdPanel.add(sameWarehouseCb, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - if (this instanceof VCreateFromShipment) { +/* if (this instanceof VCreateFromShipment) { parameterStdPanel.add(upcLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); parameterStdPanel.add(upcField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); } - +*/ // Add RMA document selection to panel parameterStdPanel.add(rmaLabel, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 diff --git a/client/src/org/compiere/grid/VCreateFromFactory.java b/client/src/org/compiere/grid/VCreateFromFactory.java index fc4d1c0cf4..ff8e4bd401 100644 --- a/client/src/org/compiere/grid/VCreateFromFactory.java +++ b/client/src/org/compiere/grid/VCreateFromFactory.java @@ -50,7 +50,7 @@ public class VCreateFromFactory s_registeredClasses.put(I_C_Invoice.Table_ID, VCreateFromInvoiceUI.class); s_registeredClasses.put(I_C_BankStatement.Table_ID, VCreateFromStatementUI.class); - s_registeredClasses.put(I_M_InOut.Table_ID, VCreateFromShipment.class); + s_registeredClasses.put(I_M_InOut.Table_ID, VCreateFromShipmentUI.class); s_registeredClasses.put(I_M_RMA.Table_ID, VCreateFromRMA.class); } diff --git a/client/src/org/compiere/grid/VCreateFromShipmentUI.java b/client/src/org/compiere/grid/VCreateFromShipmentUI.java new file mode 100644 index 0000000000..fccedb3dd0 --- /dev/null +++ b/client/src/org/compiere/grid/VCreateFromShipmentUI.java @@ -0,0 +1,482 @@ +/****************************************************************************** + * Copyright (C) 2009 Low Heng Sin * + * Copyright (C) 2009 Idalica Corporation * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ + +package org.compiere.grid; + +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.VetoableChangeListener; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; +import java.util.logging.Level; + +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.table.DefaultTableModel; + +import org.compiere.apps.AEnv; +import org.compiere.grid.ed.VLocator; +import org.compiere.grid.ed.VLookup; +import org.compiere.minigrid.IMiniTable; +import org.compiere.model.GridTab; +import org.compiere.model.MDocType; +import org.compiere.model.MLocator; +import org.compiere.model.MLocatorLookup; +import org.compiere.model.MLookup; +import org.compiere.model.MLookupFactory; +import org.compiere.model.MProduct; +import org.compiere.swing.CPanel; +import org.compiere.util.CLogger; +import org.compiere.util.DisplayType; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.Msg; + +public class VCreateFromShipmentUI extends CreateFromShipment implements ActionListener, VetoableChangeListener +{ + private static final long serialVersionUID = 1L; + + private VCreateFromDialog dialog; + + public VCreateFromShipmentUI(GridTab mTab) + { + super(mTab); + log.info(getGridTab().toString()); + + dialog = new VCreateFromDialog(this, getGridTab().getWindowNo(), true); + + p_WindowNo = getGridTab().getWindowNo(); + + try + { + if (!dynInit()) + return; + jbInit(); + + setInitOK(true); + } + catch(Exception e) + { + log.log(Level.SEVERE, "", e); + setInitOK(false); + } + AEnv.positionCenterWindow(Env.getWindow(p_WindowNo), dialog); + } // VCreateFrom + + /** Window No */ + private int p_WindowNo; + + /** Logger */ + private CLogger log = CLogger.getCLogger(getClass()); + + // + private JLabel bPartnerLabel = new JLabel(); + private VLookup bPartnerField; + + private JLabel orderLabel = new JLabel(); + private JComboBox orderField = new JComboBox(); + + private JLabel invoiceLabel = new JLabel(); + private JComboBox invoiceField = new JComboBox(); + + /** Label for the rma selection */ + private JLabel rmaLabel = new JLabel(); + /** Combo box for selecting RMA document */ + private JComboBox rmaField = new JComboBox(); + + private JLabel upcLabel = new JLabel(); + private JTextField upcField = new JTextField(); + + private JCheckBox sameWarehouseCb = new JCheckBox(); + private JLabel locatorLabel = new JLabel(); + private VLocator locatorField = new VLocator(); + + /** + * Dynamic Init + * @throws Exception if Lookups cannot be initialized + * @return true if initialized + */ + public boolean dynInit() throws Exception + { + log.config(""); + + super.dynInit(); + + dialog.setTitle(getTitle()); + + // load Locator + MLocatorLookup locator = new MLocatorLookup(Env.getCtx(), p_WindowNo); + locatorField = new VLocator ("M_Locator_ID", true, false, true, locator, p_WindowNo); + sameWarehouseCb.setSelected(true); + sameWarehouseCb.addActionListener(this); + + initBPartner(false); + bPartnerField.addVetoableChangeListener(this); + + return true; + } // dynInit + + /** + * Static Init. + *
    +	 *  parameterPanel
    +	 *      parameterBankPanel
    +	 *      parameterStdPanel
    +	 *          bPartner/order/invoice/shopment/licator Label/Field
    +	 *  dataPane
    +	 *  southPanel
    +	 *      confirmPanel
    +	 *      statusBar
    +	 *  
    + * @throws Exception + */ + private void jbInit() throws Exception + { + bPartnerLabel.setText(Msg.getElement(Env.getCtx(), "C_BPartner_ID")); + orderLabel.setText(Msg.getElement(Env.getCtx(), "C_Order_ID", false)); + locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID")); + invoiceLabel.setText(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); + sameWarehouseCb.setText(Msg.getMsg(Env.getCtx(), "FromSameWarehouseOnly", true)); + sameWarehouseCb.setToolTipText(Msg.getMsg(Env.getCtx(), "FromSameWarehouseOnly", false)); + rmaLabel.setText(Msg.translate(Env.getCtx(), "M_RMA_ID")); + upcLabel.setText(Msg.getElement(Env.getCtx(), "UPC", false)); + + CPanel parameterPanel = dialog.getParameterPanel(); + parameterPanel.setLayout(new BorderLayout()); + CPanel parameterStdPanel = new CPanel(new GridBagLayout()); + parameterPanel.add(parameterStdPanel, BorderLayout.CENTER); + + parameterStdPanel.add(bPartnerLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + if (bPartnerField != null) + parameterStdPanel.add(bPartnerField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); + + parameterStdPanel.add(orderLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + parameterStdPanel.add(orderField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); + + parameterStdPanel.add(invoiceLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + parameterStdPanel.add(invoiceField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); + + parameterStdPanel.add(locatorLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + parameterStdPanel.add(locatorField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); + parameterStdPanel.add(sameWarehouseCb, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); + parameterStdPanel.add(upcLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + parameterStdPanel.add(upcField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); + + // Add RMA document selection to panel + parameterStdPanel.add(rmaLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 + ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); + parameterStdPanel.add(rmaField, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0 + ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); + } // jbInit + + /*************************************************************************/ + + private boolean m_actionActive = false; + + /** + * Action Listener + * @param e event + */ + public void actionPerformed(ActionEvent e) + { + log.config("Action=" + e.getActionCommand()); + + if (m_actionActive) + return; + m_actionActive = true; + log.config("Action=" + e.getActionCommand()); + // Order + if (e.getSource().equals(orderField)) + { + KeyNamePair pp = (KeyNamePair)orderField.getSelectedItem(); + int C_Order_ID = 0; + if (pp != null) + C_Order_ID = pp.getKey(); + // set Invoice, RMA and Shipment to Null + rmaField.setSelectedIndex(-1); + invoiceField.setSelectedIndex(-1); + loadOrder(C_Order_ID, false, locatorField.getValue()!=null?((Integer)locatorField.getValue()).intValue():0); + } + // Invoice + else if (e.getSource().equals(invoiceField)) + { + KeyNamePair pp = (KeyNamePair)invoiceField.getSelectedItem(); + int C_Invoice_ID = 0; + if (pp != null) + C_Invoice_ID = pp.getKey(); + // set Order, RMA to Null + orderField.setSelectedIndex(-1); + rmaField.setSelectedIndex(-1); + loadInvoice(C_Invoice_ID, locatorField.getValue()!=null?((Integer)locatorField.getValue()).intValue():0); + } + // RMA + else if (e.getSource().equals(rmaField)) + { + KeyNamePair pp = (KeyNamePair)rmaField.getSelectedItem(); + int M_RMA_ID = 0; + if (pp != null) + M_RMA_ID = pp.getKey(); + // set Order and Invoice to Null + orderField.setSelectedIndex(-1); + invoiceField.setSelectedIndex(-1); + loadRMA(M_RMA_ID, locatorField.getValue()!=null?((Integer)locatorField.getValue()).intValue():0); + } + //sameWarehouseCb + else if (e.getSource().equals(sameWarehouseCb)) + { + initBPOrderDetails(((Integer)bPartnerField.getValue()).intValue(), false); + } + else if (e.getSource().equals(upcField)) + { + checkProductUsingUPC(); + } + m_actionActive = false; + } // actionPerformed + + /** + * Change Listener + * @param e event + */ + public void vetoableChange (PropertyChangeEvent e) + { + log.config(e.getPropertyName() + "=" + e.getNewValue()); + + // BPartner - load Order/Invoice/Shipment + if (e.getPropertyName().equals("C_BPartner_ID")) + { + int C_BPartner_ID = ((Integer)e.getNewValue()).intValue(); + initBPOrderDetails (C_BPartner_ID, false); + } + dialog.tableChanged(null); + } // vetoableChange + + /************************************************************************** + * Load BPartner Field + * @param forInvoice true if Invoices are to be created, false receipts + * @throws Exception if Lookups cannot be initialized + */ + protected void initBPartner (boolean forInvoice) throws Exception + { + // load BPartner + int AD_Column_ID = 3499; // C_Invoice.C_BPartner_ID + MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.Search); + bPartnerField = new VLookup ("C_BPartner_ID", true, false, true, lookup); + // + int C_BPartner_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BPartner_ID"); + bPartnerField.setValue(new Integer(C_BPartner_ID)); + + // initial loading + initBPOrderDetails(C_BPartner_ID, forInvoice); + } // initBPartner + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID BPartner + * @param forInvoice for invoice + */ + protected void initBPOrderDetails (int C_BPartner_ID, boolean forInvoice) + { + log.config("C_BPartner_ID=" + C_BPartner_ID); + KeyNamePair pp = new KeyNamePair(0,""); + // load PO Orders - Closed, Completed + orderField.removeActionListener(this); + orderField.removeAllItems(); + orderField.addItem(pp); + + ArrayList list = loadOrderData(C_BPartner_ID, forInvoice, sameWarehouseCb.isSelected()); + for(KeyNamePair knp : list) + orderField.addItem(knp); + + orderField.setSelectedIndex(0); + orderField.addActionListener(this); + dialog.pack(); + + initBPDetails(C_BPartner_ID); + } // initBPartnerOIS + + public void initBPDetails(int C_BPartner_ID) + { + initBPInvoiceDetails(C_BPartner_ID); + initBPRMADetails(C_BPartner_ID); + } + + /** + * Init Details - load invoices not shipped + * @param C_BPartner_ID BPartner + */ + private void initBPInvoiceDetails(int C_BPartner_ID) + { + log.config("C_BPartner_ID" + C_BPartner_ID); + + // load Shipments (Receipts) - Completed, Closed + invoiceField.removeActionListener(this); + invoiceField.removeAllItems(); + // None + KeyNamePair pp = new KeyNamePair(0,""); + invoiceField.addItem(pp); + + ArrayList list = loadInvoiceData(C_BPartner_ID); + for(KeyNamePair knp : list) + invoiceField.addItem(knp); + + invoiceField.setSelectedIndex(0); + invoiceField.addActionListener(this); + upcField.addActionListener(this); + } + + /** + * Load RMA that are candidates for shipment + * @param C_BPartner_ID BPartner + */ + private void initBPRMADetails(int C_BPartner_ID) + { + rmaField.removeActionListener(this); + rmaField.removeAllItems(); + // None + KeyNamePair pp = new KeyNamePair(0,""); + rmaField.addItem(pp); + + ArrayList list = loadRMAData(C_BPartner_ID); + for(KeyNamePair knp : list) + rmaField.addItem(knp); + + rmaField.setSelectedIndex(0); + rmaField.addActionListener(this); + } + + /** + * Load Data - Order + * @param C_Order_ID Order + * @param forInvoice true if for invoice vs. delivery qty + * @param M_Locator_ID + */ + protected void loadOrder (int C_Order_ID, boolean forInvoice, int M_Locator_ID) + { + loadTableOIS(getOrderData(C_Order_ID, forInvoice, M_Locator_ID)); + } // LoadOrder + + /** + * Load Data - RMA + * @param M_RMA_ID RMA + * @param M_Locator_ID + */ + protected void loadRMA (int M_RMA_ID, int M_Locator_ID) + { + loadTableOIS(getRMAData(M_RMA_ID, M_Locator_ID)); + } + + /** + * Load Data - Invoice + * @param C_Invoice_ID Invoice + * @param M_Locator_ID + */ + protected void loadInvoice (int C_Invoice_ID, int M_Locator_ID) + { + loadTableOIS(getInvoiceData(C_Invoice_ID, M_Locator_ID)); + } + + /** + * Load Order/Invoice/Shipment data into Table + * @param data data + */ + protected void loadTableOIS (Vector data) + { + // Remove previous listeners + dialog.getMiniTable().getModel().removeTableModelListener(dialog); + // Set Model + DefaultTableModel model = new DefaultTableModel(data, getOISColumnNames()); + model.addTableModelListener(dialog); + dialog.getMiniTable().setModel(model); + // + + configureMiniTable(dialog.getMiniTable()); + } // loadOrder + + public void showWindow() + { + dialog.setVisible(true); + } + + public void closeWindow() + { + dialog.dispose(); + } + + /** + * Checks the UPC value and checks if the UPC matches any of the products in the + * list. + */ + private void checkProductUsingUPC() + { + String upc = upcField.getText(); + DefaultTableModel model = (DefaultTableModel)dialog.getMiniTable().getModel(); + // Lookup UPC + List products = MProduct.getByUPC(Env.getCtx(), upc, null); + for (MProduct product : products) + { + int row = findProductRow(product.get_ID()); + if (row >= 0) + { + BigDecimal qty = (BigDecimal)model.getValueAt(row, 1); + model.setValueAt(qty, row, 1); + model.setValueAt(Boolean.TRUE, row, 0); + model.fireTableRowsUpdated(row, row); + } + } + upcField.setText(""); + upcField.requestFocusInWindow(); + } + + /** + * Finds the row where a given product is. If the product is not found + * in the table -1 is returned. + * @param M_Product_ID + * @return Row of the product or -1 if non existing. + * + */ + private int findProductRow(int M_Product_ID) + { + DefaultTableModel model = (DefaultTableModel)dialog.getMiniTable().getModel(); + KeyNamePair kp; + for (int i=0; i products = MProduct.getByUPC(Env.getCtx(), upc, null); + for (MProduct product : products) + { + int row = findProductRow(product.get_ID()); + if (row >= 0) + { + BigDecimal qty = (BigDecimal)model.getValueAt(row, 1); + model.setValueAt(qty, row, 1); + model.setValueAt(Boolean.TRUE, row, 0); + model.updateComponent(row, row); + } + } + upcField.setValue(""); + upcField.setHasFocus(true); + } + + /** + * Finds the row where a given product is. If the product is not found + * in the table -1 is returned. + * @param M_Product_ID + * @return Row of the product or -1 if non existing. + * + */ + private int findProductRow(int M_Product_ID) + { + //DefaultTableModel model = (DefaultTableModel)dialog.getMiniTable().getModel(); + ListModelTable model = (ListModelTable) window.getWListbox().getModel(); + KeyNamePair kp; + for (int i=0; i list = loadInvoiceData(C_BPartner_ID); + for(KeyNamePair knp : list) + invoiceField.addItem(knp); + + invoiceField.setSelectedIndex(0); + invoiceField.addActionListener(this); + upcField.addValueChangeListener(this); + } + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID BPartner + * @param forInvoice for invoice + */ + protected void initBPOrderDetails (int C_BPartner_ID, boolean forInvoice) + { + log.config("C_BPartner_ID=" + C_BPartner_ID); + KeyNamePair pp = new KeyNamePair(0,""); + // load PO Orders - Closed, Completed + orderField.removeActionListener(this); + orderField.removeAllItems(); + orderField.addItem(pp); + + ArrayList list = loadOrderData(C_BPartner_ID, forInvoice, false); + for(KeyNamePair knp : list) + orderField.addItem(knp); + + orderField.setSelectedIndex(0); + orderField.addActionListener(this); + + initBPDetails(C_BPartner_ID); + } // initBPartnerOIS + + public void initBPDetails(int C_BPartner_ID) + { + initBPInvoiceDetails(C_BPartner_ID); + initBPRMADetails(C_BPartner_ID); + } + + + /** + * Load RMA that are candidates for shipment + * @param C_BPartner_ID BPartner + */ + private void initBPRMADetails(int C_BPartner_ID) + { + rmaField.removeActionListener(this); + rmaField.removeAllItems(); + // None + KeyNamePair pp = new KeyNamePair(0,""); + rmaField.addItem(pp); + + ArrayList list = loadRMAData(C_BPartner_ID); + for(KeyNamePair knp : list) + rmaField.addItem(knp); + + rmaField.setSelectedIndex(0); + rmaField.addActionListener(this); + } + + /** + * Load Data - Order + * @param C_Order_ID Order + * @param forInvoice true if for invoice vs. delivery qty + */ +/* protected void loadOrder (int C_Order_ID, boolean forInvoice) + { + loadTableOIS(getOrderData(C_Order_ID, forInvoice)); + } // LoadOrder + + protected void loadRMA (int M_RMA_ID) + { + loadTableOIS(getRMAData(M_RMA_ID)); + } + + protected void loadShipment (int M_InOut_ID) + { + loadTableOIS(getShipmentData(M_InOut_ID)); + }*/ + + /** + * Load Data - Order + * @param C_Order_ID Order + * @param forInvoice true if for invoice vs. delivery qty + * @param M_Locator_ID + */ + protected void loadOrder (int C_Order_ID, boolean forInvoice, int M_Locator_ID) + { + loadTableOIS(getOrderData(C_Order_ID, forInvoice, M_Locator_ID)); + } // LoadOrder + + /** + * Load Data - RMA + * @param M_RMA_ID RMA + * @param M_Locator_ID + */ + protected void loadRMA (int M_RMA_ID, int M_Locator_ID) + { + loadTableOIS(getRMAData(M_RMA_ID, M_Locator_ID)); + } + + /** + * Load Data - Invoice + * @param C_Invoice_ID Invoice + * @param M_Locator_ID + */ + protected void loadInvoice (int C_Invoice_ID, int M_Locator_ID) + { + loadTableOIS(getInvoiceData(C_Invoice_ID, M_Locator_ID)); + } + + /** + * Load Order/Invoice/Shipment data into Table + * @param data data + */ + protected void loadTableOIS (Vector data) + { + window.getWListbox().clear(); + + // Remove previous listeners + window.getWListbox().getModel().removeTableModelListener(window); + // Set Model + ListModelTable model = new ListModelTable(data); + model.addTableModelListener(window); + window.getWListbox().setData(model, getOISColumnNames()); + // + + configureMiniTable(window.getWListbox()); + } // loadOrder + + public void showWindow() + { + window.setVisible(true); + } + + public void closeWindow() + { + window.dispose(); + } +} diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java index 576f2506da..a3a51665f7 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java @@ -91,10 +91,10 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh setColumnName(columnName); m_mLocator = mLocator; getComponent().setButtonImage("/images/Locator10.png"); - + + m_WindowNo = windowNo; //Yvonne: move it b4 setDefault_Locator_ID() setDefault_Locator_ID(); // set default locator, teo_sarca [ 1661546 ] - m_WindowNo = windowNo; } /**