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 loadRMAData(int C_BPartner_ID) {
+ ArrayList list = new ArrayList();
- initBPInvoiceDetails(C_BPartner_ID);
- initBPRMADetails(C_BPartner_ID);
- } // initBPDetails
+ 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;
+ try {
+ pstmt = DB.prepareStatement(sqlStmt, null);
+ pstmt.setInt(1, C_BPartner_ID);
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
+ }
+ rs.close();
+ } catch (SQLException e) {
+ log.log(Level.SEVERE, sqlStmt.toString(), e);
+ } finally {
+ if (pstmt != null) {
+ try {
+ pstmt.close();
+ } catch (Exception ex) {
+ log.severe("Could not close prepared statement");
+ }
+ }
+ }
+
+ return list;
+ }
/**
- * Init Details - load invoices not shipped
- * @param C_BPartner_ID BPartner
+ * Load PBartner dependent Order/Invoice/Shipment Field.
+ * @param C_BPartner_ID
*/
- private void initBPInvoiceDetails(int C_BPartner_ID)
+ protected ArrayList 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