diff --git a/client/src/org/compiere/grid/CreateFrom.java b/client/src/org/compiere/grid/CreateFrom.java index 98a5003a46..7e2f6b9210 100644 --- a/client/src/org/compiere/grid/CreateFrom.java +++ b/client/src/org/compiere/grid/CreateFrom.java @@ -129,24 +129,6 @@ public abstract class CreateFrom implements ICreateFrom return list; } // initBPartnerOIS - /** - * Load PBartner dependent Order/Invoice/Shipment Field. - * @param C_BPartner_ID BPartner - */ - protected ArrayList loadRMAData (int C_BPartner_ID) - { - return null; - } - - /** - * Load PBartner dependent Order/Invoice/Shipment Field. - * @param C_BPartner_ID BPartner - */ - protected ArrayList loadShipmentData (int C_BPartner_ID) - { - return null; - } - /** * Load Data - Order * @param C_Order_ID Order @@ -234,36 +216,6 @@ public abstract class CreateFrom implements ICreateFrom return data; } // LoadOrder - protected Vector> getRMAData(int M_RMA_ID) - { - return null; - } - - protected Vector> getShipmentData(int M_InOut_ID) - { - return null; - } - - /** - * Load Order/Invoice/Shipment data into Table - * @param data data - */ - protected Vector getOISColumnNames() - { - // 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_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_InOut_ID", false)); - columnNames.add(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); - - return columnNames; - } // loadOrder - public void showWindow() { diff --git a/client/src/org/compiere/grid/CreateFromInvoice.java b/client/src/org/compiere/grid/CreateFromInvoice.java index c86cf2515e..d9a95b9f9c 100644 --- a/client/src/org/compiere/grid/CreateFromInvoice.java +++ b/client/src/org/compiere/grid/CreateFromInvoice.java @@ -480,7 +480,6 @@ public class CreateFromInvoice extends CreateFrom return true; } // saveInvoice - @Override protected Vector getOISColumnNames() { // Header Info diff --git a/client/src/org/compiere/grid/VCreateFromRMA.java b/client/src/org/compiere/grid/CreateFromRMA.java similarity index 56% rename from client/src/org/compiere/grid/VCreateFromRMA.java rename to client/src/org/compiere/grid/CreateFromRMA.java index 5e856ae954..6cf8629be4 100644 --- a/client/src/org/compiere/grid/VCreateFromRMA.java +++ b/client/src/org/compiere/grid/CreateFromRMA.java @@ -1,239 +1,183 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 2007 Adempiere, Inc. All Rights Reserved. * - * 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.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Vector; -import java.util.logging.Level; - -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableModel; - -import org.compiere.model.GridTab; -import org.compiere.model.MRMA; -import org.compiere.model.MRMALine; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Msg; - -/** - * Create Transactions for RMA - * @author ashley - * @author Teo Sarca, www.arhipac.ro - *
  • BF [ 2007837 ] VCreateFrom.save() should run in trx - */ -public class VCreateFromRMA extends VCreateFrom -{ - /** - * - */ - private static final long serialVersionUID = 8621409442057992906L; - - /** - * - * @param mTab - */ - public VCreateFromRMA(GridTab mTab) - { - super(mTab); - log.info(mTab.toString()); - } - - protected boolean dynInit() throws Exception - { - log.config(""); - setTitle("Customer RMA - Create Lines From"); - - parameterBankPanel.setVisible(false); - - invoiceLabel.setVisible(false); - invoiceField.setVisible(false); - - locatorLabel.setVisible(false); - locatorField.setVisible(false); - - orderLabel.setVisible(false); - orderField.setVisible(false); - - shipmentLabel.setVisible(false); - shipmentField.setVisible(false); - - sameWarehouseCb.setVisible(false); - - rmaLabel.setVisible(false); - rmaField.setVisible(false); - - initBPartner(true); - - bPartnerField.setEnabled(false); - - int inOutId = Env.getContextAsInt(Env.getCtx(), p_mTab.getWindowNo(), "InOut_ID"); - - loadShipment(inOutId); - - return true; - } - - @Override - protected void loadTableOIS (Vector data) - { - // Header Info - Vector columnNames = new Vector(7); - columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); - columnNames.add("Line"); - columnNames.add(Msg.translate(Env.getCtx(), "M_Product_ID")); - columnNames.add("ASI"); - columnNames.add(Msg.translate(Env.getCtx(), "Quantity")); - columnNames.add(Msg.getElement(Env.getCtx(), "QtyDelivered", false)); - - - // Remove previous listeners - dataTable.getModel().removeTableModelListener(this); - // Set Model - DefaultTableModel model = new DefaultTableModel(data, columnNames); - model.addTableModelListener(this); - dataTable.setModel(model); - // - dataTable.setColumnClass(0, Boolean.class, false); // 0-Selection - dataTable.setColumnClass(1, String.class, true); // 1-Line - dataTable.setColumnClass(2, String.class, true); // 2-Product - dataTable.setColumnClass(3, String.class, true); // 3-ASI - dataTable.setColumnClass(4, BigDecimal.class, true); // 4-Qty - dataTable.setColumnClass(5, BigDecimal.class, true); // 5-Delivered Qty - - // Table UI - dataTable.autoSize(); - } // loadOrder - - /** - * Load Data - Shipment not invoiced - * @param M_InOut_ID InOut - */ - private void loadShipment (int M_InOut_ID) - { - int m_rma_id = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "M_RMA_ID"); - log.config("M_InOut_ID=" + M_InOut_ID); - log.config("M_RMA_ID=" + m_rma_id); - // - Vector> data = new Vector>(); - - /** - * 1 M_InOutLine_ID - * 2 Line - * 3 Product Name - * 4 Qty Entered - * 5 Movement Qty - * 6 ASI - */ - StringBuffer sqlStmt = new StringBuffer(); - - sqlStmt.append("SELECT iol.M_InOutLine_ID, iol.Line, "); - sqlStmt.append("CASE WHEN iol.M_Product_ID IS NOT NULL THEN (Select p.Name from M_Product p where p.M_Product_ID = iol.M_Product_ID) END as ProductName, "); - sqlStmt.append("iol.QtyEntered, "); - sqlStmt.append("iol.movementQty, "); - sqlStmt.append("CASE WHEN iol.M_AttributeSetInstance_ID IS NOT NULL THEN (SELECT SerNo FROM M_AttributeSetInstance asi where asi.M_AttributeSetInstance_ID=iol.M_AttributeSetInstance_ID) END as ASI "); - sqlStmt.append("from M_InOutLine iol where M_InOut_ID=? "); - sqlStmt.append("and iol.M_InOutLine_ID not in (select rmal.M_InOutLine_ID from M_RMALine rmal where rmal.M_RMA_ID=?)"); - - - try - { - PreparedStatement pstmt = DB.prepareStatement(sqlStmt.toString(), null); - pstmt.setInt(1, M_InOut_ID); - pstmt.setInt(2, m_rma_id); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - Vector line = new Vector(7); - line.add(new Boolean(false)); // 0-Selection - - KeyNamePair lineKNPair = new KeyNamePair(rs.getInt(1), rs.getString(2)); // 1-Line - line.add(lineKNPair); - line.add(rs.getString(3)); //2-Product - line.add(rs.getString(6)); //3-ASI - - BigDecimal qtyEntered = rs.getBigDecimal(4); - BigDecimal movementQty = rs.getBigDecimal(5); - - line.add(qtyEntered); //4-Qty - line.add(movementQty); //5-Movement Qty - - - data.add(line); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sqlStmt.toString(), e); - } - loadTableOIS (data); - } // loadShipment - - protected void initBPDetails(int C_BPartner_ID) - { - - } - - protected void info() - { - - } - - protected boolean save(String trxName) - { - log.config(""); - int m_rma_id = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "M_RMA_ID"); - TableModel model = dataTable.getModel(); - int rows = model.getRowCount(); - if (rows == 0) - { - return false; - } - -// Integer bpId = (Integer)bPartnerField.getValue(); - MRMA rma = new MRMA(Env.getCtx(), m_rma_id, trxName); - //update BP -// rma.setC_BPartner_ID(bpId); - - for (int i = 0; i < rows; i++) - { - if (((Boolean)model.getValueAt(i, 0)).booleanValue()) - { - BigDecimal d = (BigDecimal)model.getValueAt(i, 5); // 5-Movement Qty - KeyNamePair pp = (KeyNamePair)model.getValueAt(i, 1); // 1-Line - - int inOutLineId = pp.getKey(); - - MRMALine rmaLine = new MRMALine(rma.getCtx(), 0, rma.get_TrxName()); - rmaLine.setM_RMA_ID(m_rma_id); - rmaLine.setM_InOutLine_ID(inOutLineId); - rmaLine.setQty(d); - rmaLine.setAD_Org_ID(rma.getAD_Org_ID()); - if (!rmaLine.save()) - { - throw new IllegalStateException("Could not create RMA Line"); - } - } - } - rma.saveEx(); - return true; - } - -} +/****************************************************************************** + * 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.math.BigDecimal; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Vector; +import java.util.logging.Level; + +import org.compiere.minigrid.IMiniTable; +import org.compiere.model.GridTab; +import org.compiere.model.MRMA; +import org.compiere.model.MRMALine; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.Msg; + +/** + * Create Transactions for RMA + * @author ashley + * @author Teo Sarca, www.arhipac.ro + *
  • BF [ 2007837 ] VCreateFrom.save() should run in trx + */ +public class CreateFromRMA extends CreateFrom { + + public CreateFromRMA(GridTab mTab) + { + super(mTab); + log.info(mTab.toString()); + } + + @Override + public boolean dynInit() throws Exception + { + log.config(""); + setTitle("Customer RMA - Create Lines From"); + + return true; + } + + protected Vector> getRMAData() + { + int M_InOut_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "InOut_ID"); + int M_RMA_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "M_RMA_ID"); + + Vector> data = new Vector>(); + + /** + * 1 M_InOutLine_ID + * 2 Line + * 3 Product Name + * 4 Qty Entered + * 5 Movement Qty + * 6 ASI + */ + StringBuffer sqlStmt = new StringBuffer(); + + sqlStmt.append("SELECT iol.M_InOutLine_ID, iol.Line, "); + sqlStmt.append("CASE WHEN iol.M_Product_ID IS NOT NULL THEN (Select p.Name from M_Product p where p.M_Product_ID = iol.M_Product_ID) END as ProductName, "); + sqlStmt.append("iol.QtyEntered, "); + sqlStmt.append("iol.movementQty, "); + sqlStmt.append("CASE WHEN iol.M_AttributeSetInstance_ID IS NOT NULL THEN (SELECT SerNo FROM M_AttributeSetInstance asi where asi.M_AttributeSetInstance_ID=iol.M_AttributeSetInstance_ID) END as ASI "); + sqlStmt.append("from M_InOutLine iol where M_InOut_ID=? "); + sqlStmt.append("and iol.M_InOutLine_ID not in (select rmal.M_InOutLine_ID from M_RMALine rmal where rmal.M_RMA_ID=?)"); + + try + { + PreparedStatement pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt.setInt(1, M_InOut_ID); + pstmt.setInt(2, M_RMA_ID); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + { + Vector line = new Vector(7); + line.add(new Boolean(false)); // 0-Selection + + KeyNamePair lineKNPair = new KeyNamePair(rs.getInt(1), rs.getString(2)); // 1-Line + line.add(lineKNPair); + line.add(rs.getString(3)); //2-Product + line.add(rs.getString(6)); //3-ASI + + BigDecimal qtyEntered = rs.getBigDecimal(4); + BigDecimal movementQty = rs.getBigDecimal(5); + + line.add(qtyEntered); //4-Qty + line.add(movementQty); //5-Movement Qty + + + data.add(line); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sqlStmt.toString(), e); + } + + return data; + } + + @Override + public void info() + { + + } + + protected void configureMiniTable (IMiniTable miniTable) + { + miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection + miniTable.setColumnClass(1, String.class, true); // 1-Line + miniTable.setColumnClass(2, String.class, true); // 2-Product + miniTable.setColumnClass(3, String.class, true); // 3-ASI + miniTable.setColumnClass(4, BigDecimal.class, true); // 4-Qty + miniTable.setColumnClass(5, BigDecimal.class, true); // 5-Delivered Qty + + // Table UI + miniTable.autoSize(); + } + + @Override + public boolean save(IMiniTable miniTable, String trxName) + { + log.config(""); + int M_RMA_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "M_RMA_ID"); + +// Integer bpId = (Integer)bPartnerField.getValue(); + MRMA rma = new MRMA(Env.getCtx(), M_RMA_ID, trxName); + //update BP +// rma.setC_BPartner_ID(bpId); + + for (int i = 0; i < miniTable.getRowCount(); i++) + { + if (((Boolean)miniTable.getValueAt(i, 0)).booleanValue()) + { + BigDecimal d = (BigDecimal)miniTable.getValueAt(i, 5); // 5-Movement Qty + KeyNamePair pp = (KeyNamePair)miniTable.getValueAt(i, 1); // 1-Line + + int inOutLineId = pp.getKey(); + + MRMALine rmaLine = new MRMALine(rma.getCtx(), 0, rma.get_TrxName()); + rmaLine.setM_RMA_ID(M_RMA_ID); + rmaLine.setM_InOutLine_ID(inOutLineId); + rmaLine.setQty(d); + rmaLine.setAD_Org_ID(rma.getAD_Org_ID()); + if (!rmaLine.save()) + { + throw new IllegalStateException("Could not create RMA Line"); + } + } + } + rma.saveEx(); + return true; + } + + protected Vector getOISColumnNames() + { + // Header Info + Vector columnNames = new Vector(7); + columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); + columnNames.add("Line"); + columnNames.add(Msg.translate(Env.getCtx(), "M_Product_ID")); + columnNames.add("ASI"); + columnNames.add(Msg.translate(Env.getCtx(), "Quantity")); + columnNames.add(Msg.getElement(Env.getCtx(), "QtyDelivered", false)); + + return columnNames; + } +} diff --git a/client/src/org/compiere/grid/CreateFromShipment.java b/client/src/org/compiere/grid/CreateFromShipment.java index 86d14bea1f..326ad0c7eb 100644 --- a/client/src/org/compiere/grid/CreateFromShipment.java +++ b/client/src/org/compiere/grid/CreateFromShipment.java @@ -732,7 +732,6 @@ public class CreateFromShipment extends CreateFrom } // saveInvoice - @Override protected Vector getOISColumnNames() { // Header Info diff --git a/client/src/org/compiere/grid/CreateFromStatement.java b/client/src/org/compiere/grid/CreateFromStatement.java index c61175445f..23a571c9f6 100644 --- a/client/src/org/compiere/grid/CreateFromStatement.java +++ b/client/src/org/compiere/grid/CreateFromStatement.java @@ -316,7 +316,6 @@ public class CreateFromStatement extends CreateFrom return true; } // save - @Override protected Vector getOISColumnNames() { // Header Info diff --git a/client/src/org/compiere/grid/VCreateFrom.java b/client/src/org/compiere/grid/VCreateFrom.java deleted file mode 100644 index 6f7189ec90..0000000000 --- a/client/src/org/compiere/grid/VCreateFrom.java +++ /dev/null @@ -1,787 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * 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. * - * 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.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.awt.event.KeyEvent; -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Vector; -import java.util.logging.Level; - -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JScrollPane; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableModel; - -import org.compiere.apps.ADialog; -import org.compiere.apps.AEnv; -import org.compiere.apps.AppsAction; -import org.compiere.apps.ConfirmPanel; -import org.compiere.apps.StatusBar; -import org.compiere.grid.ed.VDate; -import org.compiere.grid.ed.VLocator; -import org.compiere.grid.ed.VLookup; -import org.compiere.grid.ed.VNumber; -import org.compiere.grid.ed.VString; -import org.compiere.minigrid.MiniTable; -import org.compiere.model.GridTab; -import org.compiere.model.I_M_InOut; -import org.compiere.model.I_M_RMA; -import org.compiere.model.MLookup; -import org.compiere.model.MLookupFactory; -import org.compiere.model.MOrder; -import org.compiere.swing.CButton; -import org.compiere.swing.CDialog; -import org.compiere.swing.CLabel; -import org.compiere.swing.CPanel; -import org.compiere.swing.CTextField; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Msg; -import org.compiere.util.Trx; -import org.compiere.util.TrxRunnable; - -/** - * CreateFrom (Called from GridController.startProcess) - * - * @author Jorg Janke - * @version $Id: VCreateFrom.java,v 1.4 2006/10/11 09:52:23 comdivision Exp $ - * - * @author Teo Sarca, SC ARHIPAC SERVICE SRL - *
  • FR [ 1794050 ] Usability: VCreateFrom OK button always enabled - *
  • FR [ 1974354 ] VCreateFrom.create should be more flexible - *
  • BF [ 2007837 ] VCreateFrom.save() should run in trx - *
  • BF [ 2584790 ] Material Receipt error - * @author Victor Perez, e-Evolucion - *
  • RF [1811114] http://sourceforge.net/tracker/index.php?func=detail&aid=1811114&group_id=176962&atid=879335 - * @author Karsten Thiemann, Schaeffer AG - *
  • Bug [ 1759431 ] Problems with VCreateFrom - */ -public abstract class VCreateFrom extends CDialog - implements ICreateFrom, ActionListener, TableModelListener -{ - /** - * - */ - private static final long serialVersionUID = 7749087067953806144L; - - /** - * Register custom VCreateFrom* class - * @param ad_table_id - * @param cl custom class - */ - public static final void registerClass(int ad_table_id, Class cl) - { - s_registeredClasses.put(ad_table_id, cl); - s_log.info("Registered AD_Table_ID="+ad_table_id+", Class="+cl); - } - - /** Registered classes map (AD_Table_ID -> Class) */ - private static HashMap> s_registeredClasses = null; - static - { - // Register defaults: - s_registeredClasses = new HashMap>(); - //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); - } - - /** - * Factory - called from APanel - * @param mTab Model Tab for the trx - * @return JDialog - */ - public static VCreateFrom create (GridTab mTab) - { - // dynamic init preparation - int AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), "BaseTable_ID"); - - VCreateFrom retValue = null; - Class cl = s_registeredClasses.get(AD_Table_ID); - if (cl != null) - { - try - { - java.lang.reflect.Constructor ctor = cl.getConstructor(GridTab.class); - retValue = ctor.newInstance(mTab); - } - catch (Throwable e) - { - s_log.log(Level.SEVERE, e.getLocalizedMessage(), e); - return null; - } - } - if (retValue == null) - { - s_log.info("Unsupported AD_Table_ID=" + AD_Table_ID); - return null; - } - return retValue; - } // create - - - /************************************************************************** - * Protected super class Constructor - * @param mTab MTab - */ - VCreateFrom (GridTab mTab) - { - super(Env.getWindow(mTab.getWindowNo()), true); - log.info(mTab.toString()); - p_WindowNo = mTab.getWindowNo(); - p_mTab = mTab; - - try - { - if (!dynInit()) - return; - jbInit(); - confirmPanel.addActionListener(this); - // Set status - statusBar.setStatusDB(""); - tableChanged(null); - p_initOK = true; - } - catch(Exception e) - { - log.log(Level.SEVERE, "", e); - p_initOK = false; - } - AEnv.positionCenterWindow(Env.getWindow(p_WindowNo), this); - } // VCreateFrom - - /** Window No */ - protected int p_WindowNo; - /** Model Tab */ - protected GridTab p_mTab; - - private boolean p_initOK = false; - - /** Loaded Order */ - protected MOrder p_order = null; - /** Logger */ - protected CLogger log = CLogger.getCLogger(getClass()); - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (VCreateFrom.class); - - // - protected CPanel parameterPanel = new CPanel(); - protected CPanel parameterBankPanel = new CPanel(); - private BorderLayout parameterLayout = new BorderLayout(); - private JLabel bankAccountLabel = new JLabel(); - protected CPanel parameterStdPanel = new CPanel(); - private JLabel bPartnerLabel = new JLabel(); - protected VLookup bankAccountField; - //RF [1811114] - private JLabel authorizationLabel = new JLabel(); - protected VString authorizationField = new VString(); - private GridBagLayout parameterStdLayout = new GridBagLayout(); - private GridBagLayout parameterBankLayout = new GridBagLayout(); - // - private JLabel tenderTypeLabel = new JLabel(); - protected VLookup tenderTypeField; - private JLabel documentTypeLabel = new JLabel(); - protected VLookup documentTypeField; - // Bug [1759431] - protected JCheckBox sameWarehouseCb = new JCheckBox(); - protected VLookup bPartnerField; - protected JLabel orderLabel = new JLabel(); - protected JComboBox orderField = new JComboBox(); - protected JLabel invoiceLabel = new JLabel(); - protected JComboBox invoiceField = new JComboBox(); - protected JLabel shipmentLabel = new JLabel(); - protected JComboBox shipmentField = new JComboBox(); - protected JLabel upcLabel = new JLabel(); - protected JTextField upcField = new JTextField(); - private JScrollPane dataPane = new JScrollPane(); - private CPanel southPanel = new CPanel(); - private BorderLayout southLayout = new BorderLayout(); - protected ConfirmPanel confirmPanel = new ConfirmPanel(true); - private StatusBar statusBar = new StatusBar(); - protected MiniTable dataTable = new MiniTable(); - protected JLabel locatorLabel = new JLabel(); - protected VLocator locatorField = new VLocator(); - private CLabel documentNoLabel = new CLabel(Msg.translate(Env.getCtx(), "DocumentNo")); - protected CTextField documentNoField = new CTextField(10); - protected CLabel BPartner_idLabel = new CLabel(Msg.translate(Env.getCtx(), "BPartner")); - protected VLookup bPartnerLookup; - private CLabel dateFromLabel = new CLabel(Msg.translate(Env.getCtx(), "DateTrx")); - protected VDate dateFromField = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom")); - private CLabel dateToLabel = new CLabel("-"); - protected VDate dateToField = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo")); - private CLabel amtFromLabel = new CLabel(Msg.translate(Env.getCtx(), "PayAmt")); - protected VNumber amtFromField = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom")); - private CLabel amtToLabel = new CLabel("-"); - protected VNumber amtToField = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo")); - - public static final String SELECT_ALL = "SelectAll"; -// public static final String SELECT_ALL_TOOLTIP = "Select all records"; - - /** Label for the rma selection */ - protected JLabel rmaLabel = new JLabel(); - /** Combo box for selecting RMA document */ - protected JComboBox rmaField = new JComboBox(); - /** - * Static Init. - *
    -	 *  parameterPanel
    -	 *      parameterBankPanel
    -	 *      parameterStdPanel
    -	 *          bPartner/order/invoice/shopment/licator Label/Field
    -	 *  dataPane
    -	 *  southPanel
    -	 *      confirmPanel
    -	 *      statusBar
    -	 *  
    - * @throws Exception - */ - private void jbInit() throws Exception - { - parameterPanel.setLayout(parameterLayout); - parameterStdPanel.setLayout(parameterStdLayout); - parameterBankPanel.setLayout(parameterBankLayout); - // - bankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); - //RF [1811114] - authorizationLabel.setText(Msg.translate(Env.getCtx(), "R_AuthCode")); - bPartnerLabel.setText(Msg.getElement(Env.getCtx(), "C_BPartner_ID")); - orderLabel.setText(Msg.getElement(Env.getCtx(), "C_Order_ID", false)); - invoiceLabel.setText(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); - shipmentLabel.setText(Msg.getElement(Env.getCtx(), "M_InOut_ID", false)); - locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID")); - rmaLabel.setText(Msg.translate(Env.getCtx(), "M_RMA_ID")); - sameWarehouseCb.setText(Msg.getMsg(Env.getCtx(), "FromSameWarehouseOnly", true)); - sameWarehouseCb.setToolTipText(Msg.getMsg(Env.getCtx(), "FromSameWarehouseOnly", false)); - upcLabel.setText(Msg.getElement(Env.getCtx(), "UPC", false)); - documentTypeLabel.setText(Msg.translate(Env.getCtx(), "C_DocType_ID")); - tenderTypeLabel.setText(Msg.translate(Env.getCtx(), "TenderType")); - - // - this.getContentPane().add(parameterPanel, BorderLayout.NORTH); - parameterPanel.add(parameterBankPanel, BorderLayout.NORTH); - //RF [1811114] - documentNoLabel.setLabelFor(documentNoField); - // - - - dateFromLabel.setLabelFor(dateFromField); - dateFromField.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom")); - dateToLabel.setLabelFor(dateToField); - dateToField.setToolTipText(Msg.translate(Env.getCtx(), "DateTo")); - amtFromLabel.setLabelFor(amtFromField); - amtFromField.setToolTipText(Msg.translate(Env.getCtx(), "AmtFrom")); - amtToLabel.setLabelFor(amtToField); - amtToField.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo")); - - parameterBankPanel.add(bankAccountLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - if (bankAccountField != null) - parameterBankPanel.add(bankAccountField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(documentTypeLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - if(documentTypeField!= null) - parameterBankPanel.add(documentTypeField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(tenderTypeLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - if(tenderTypeField!=null) - parameterBankPanel.add(tenderTypeField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(BPartner_idLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - if ( bPartnerLookup != null ) - { - parameterBankPanel.add(bPartnerLookup, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - } - - - parameterBankPanel.add(documentNoLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(documentNoField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(authorizationLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(authorizationField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - - - parameterBankPanel.add(amtFromLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(amtFromField, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - parameterBankPanel.add(amtToLabel, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(amtToField, new GridBagConstraints(5, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterBankPanel.add(dateFromLabel, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(dateFromField, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - parameterBankPanel.add(dateToLabel, new GridBagConstraints(4, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterBankPanel.add(dateToField, new GridBagConstraints(5, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - parameterStdPanel.add(orderField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 1, 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, 1, 5, 5), 0, 0)); - 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(shipmentLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterStdPanel.add(shipmentField, new GridBagConstraints(3, 2, 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)); -/* 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 - ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - parameterStdPanel.add(rmaField, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0 - ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); - - this.getContentPane().add(dataPane, BorderLayout.CENTER); - dataPane.getViewport().add(dataTable, null); - // - // - // @Trifon - AppsAction selectAllAction = new AppsAction (SELECT_ALL, KeyStroke.getKeyStroke(KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK), null); - - CButton selectAllButton = (CButton)selectAllAction.getButton(); - selectAllButton.setMargin(new Insets (0, 10, 0, 10)); - selectAllButton.setDefaultCapable(true); - selectAllButton.addActionListener(this); -// selectAllButton.setToolTipText(Msg.getMsg(Env.getCtx(), SELECT_ALL_TOOLTIP)); - confirmPanel.addButton(selectAllButton); - // - this.getContentPane().add(southPanel, BorderLayout.SOUTH); - southPanel.setLayout(southLayout); - southPanel.add(confirmPanel, BorderLayout.CENTER); - // Trifon End - - this.getContentPane().add(southPanel, BorderLayout.SOUTH); - southPanel.setLayout(southLayout); - southPanel.add(confirmPanel, BorderLayout.CENTER); - southPanel.add(statusBar, BorderLayout.SOUTH); - } // jbInit - - /** - * Init OK to be able to make changes? - * @return on if initialized - */ - public boolean isInitOK() - { - return p_initOK; - } // isInitOK - - /** - * Get Warehouse from window's context - * @return warehouse id - */ - public int getM_Warehouse_ID() - { - return Env.getContextAsInt(Env.getCtx(), p_WindowNo, "M_Warehouse_ID"); - } - - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - abstract boolean dynInit() throws Exception; - - /** - * Init Business Partner Details - * @param C_BPartner_ID BPartner - */ - abstract void initBPDetails(int C_BPartner_ID); - - /** - * Add Info - */ - abstract void info(); - - /** - * Save & Insert Data - * @return true if saved - */ - abstract boolean save(String trxName); - - /*************************************************************************/ - - /** - * Action Listener - * @param e event - */ - public void actionPerformed(ActionEvent e) - { - log.config("Action=" + e.getActionCommand()); - // if (m_action) - // return; - // m_action = true; - - // OK - Save - if (e.getActionCommand().equals(ConfirmPanel.A_OK)) - { - try - { - Trx.run(new TrxRunnable() - { - public void run(String trxName) - { - if (save(trxName)) - { - dispose(); - } - } - }); - } - catch (Exception ex) - { - ADialog.error(p_WindowNo, this, "Error", ex.getLocalizedMessage()); - } - } - // Cancel - else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) - { - dispose(); - } - // Select All - // Trifon - else if (e.getActionCommand().equals(SELECT_ALL)) - { - TableModel model = dataTable.getModel(); - int rows = model.getRowCount(); - for (int i = 0; i < rows; i++) - { - model.setValueAt(new Boolean(true), i, 0); - } - info(); - } - // m_action = false; - } // actionPerformed - - /** - * Table Model Listener - * @param e event - */ - public void tableChanged (TableModelEvent e) - { - int type = -1; - if (e != null) - { - type = e.getType(); - if (type != TableModelEvent.UPDATE) - return; - } - log.config("Type=" + type); - info(); - dataTable.repaint(); - } // tableChanged - - - /************************************************************************** - * 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 - initBPartnerOIS(C_BPartner_ID, forInvoice); - } // initBPartner - - /** - * Load PBartner dependent Order/Invoice/Shipment Field. - * @param C_BPartner_ID BPartner - * @param forInvoice for invoice - */ - protected void initBPartnerOIS (int C_BPartner_ID, boolean forInvoice) - { - log.config("C_BPartner_ID=" + C_BPartner_ID); - KeyNamePair pp = new KeyNamePair(0,""); - boolean sameWarehouseOnly = sameWarehouseCb.isVisible() && sameWarehouseCb.isSelected(); - // load PO Orders - Closed, Completed - orderField.removeActionListener(this); - orderField.removeAllItems(); - orderField.addItem(pp); - // Display - StringBuffer display = new StringBuffer("o.DocumentNo||' - ' ||") - .append(DB.TO_CHAR("o.DateOrdered", DisplayType.Date, Env.getAD_Language(Env.getCtx()))) - .append("||' - '||") - .append(DB.TO_CHAR("o.GrandTotal", DisplayType.Amount, Env.getAD_Language(Env.getCtx()))); - // - String column = "ol.QtyDelivered"; - if (forInvoice) - column = "ol.QtyInvoiced"; - StringBuffer sql = new StringBuffer("SELECT o.C_Order_ID,").append(display) - .append(" FROM C_Order o " - + "WHERE o.C_BPartner_ID=? AND o.IsSOTrx='N' AND o.DocStatus IN ('CL','CO')" - + " AND o.C_Order_ID IN " - + "(SELECT ol.C_Order_ID FROM C_OrderLine ol" - + " WHERE ol.QtyOrdered - ").append(column).append(" != 0) "); - if(sameWarehouseOnly) - { - sql = sql.append(" AND o.M_Warehouse_ID=? "); - } - sql = sql.append("ORDER BY o.DateOrdered"); - // - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), null); - pstmt.setInt(1, C_BPartner_ID); - if(sameWarehouseOnly) - { - //only active for material receipts - pstmt.setInt(2, getM_Warehouse_ID()); - } - rs = pstmt.executeQuery(); - while (rs.next()) - { - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - orderField.addItem(pp); - } - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql.toString(), e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - orderField.setSelectedIndex(0); - orderField.addActionListener(this); - this.pack(); - - initBPDetails(C_BPartner_ID); - } // initBPartnerOIS - - /** - * 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) - { - /** - * Selected - 0 - * Qty - 1 - * C_UOM_ID - 2 - * M_Product_ID - 3 - * VendorProductNo - 4 - * OrderLine - 5 - * ShipmentLine - 6 - * InvoiceLine - 7 - */ - log.config("C_Order_ID=" + C_Order_ID); - p_order = new MOrder (Env.getCtx(), C_Order_ID, null); - - 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 - + " l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name)," // 3..4 - + " COALESCE(l.M_Product_ID,0),COALESCE(p.Name,c.Name),po.VendorProductNo," // 5..7 - + " l.C_OrderLine_ID,l.Line " // 8..9 - + "FROM C_OrderLine l" - + " LEFT OUTER JOIN M_Product_PO po ON (l.M_Product_ID = po.M_Product_ID AND l.C_BPartner_ID = po.C_BPartner_ID) " - + " LEFT OUTER JOIN M_MatchPO m ON (l.C_OrderLine_ID=m.C_OrderLine_ID AND "); - sql.append(forInvoice ? "m.C_InvoiceLine_ID" : "m.M_InOutLine_ID"); - sql.append(" IS NOT NULL)") - .append(" LEFT OUTER JOIN M_Product p ON (l.M_Product_ID=p.M_Product_ID)" - + " LEFT OUTER JOIN C_Charge c ON (l.C_Charge_ID=c.C_Charge_ID)"); - if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) - sql.append(" LEFT OUTER JOIN C_UOM uom ON (l.C_UOM_ID=uom.C_UOM_ID)"); - else - sql.append(" LEFT OUTER JOIN C_UOM_Trl uom ON (l.C_UOM_ID=uom.C_UOM_ID AND uom.AD_Language='") - .append(Env.getAD_Language(Env.getCtx())).append("')"); - // - sql.append(" WHERE l.C_Order_ID=? " // #1 - + "GROUP BY l.QtyOrdered,CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END, " - + "l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name),po.VendorProductNo, " - + "l.M_Product_ID,COALESCE(p.Name,c.Name), l.Line,l.C_OrderLine_ID " - + "ORDER BY l.Line"); - // - log.finer(sql.toString()); - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql.toString(), null); - pstmt.setInt(1, C_Order_ID); - rs = pstmt.executeQuery(); - while (rs.next()) - { - Vector line = new Vector(); - line.add(new Boolean(false)); // 0-Selection - BigDecimal qtyOrdered = rs.getBigDecimal(1); - BigDecimal multiplier = rs.getBigDecimal(2); - BigDecimal qtyEntered = qtyOrdered.multiply(multiplier); - line.add(qtyEntered); // 1-Qty - KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(4).trim()); - line.add(pp); // 2-UOM - pp = new KeyNamePair(rs.getInt(5), rs.getString(6)); - line.add(pp); // 3-Product - line.add(rs.getString(7)); // 4-VendorProductNo - pp = new KeyNamePair(rs.getInt(8), rs.getString(9)); - line.add(pp); // 5-OrderLine - line.add(null); // 6-Ship - line.add(null); // 7-Invoice - data.add(line); - } - } - catch (Exception e) - { - log.log(Level.SEVERE, sql.toString(), e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - - loadTableOIS (data); - } // LoadOrder - - - /** - * Load Order/Invoice/Shipment data into Table - * @param data data - */ - protected void loadTableOIS (Vector data) - { - // 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_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_InOut_ID", false)); - columnNames.add(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); - - // Remove previous listeners - dataTable.getModel().removeTableModelListener(this); - // Set Model - DefaultTableModel model = new DefaultTableModel(data, columnNames); - model.addTableModelListener(this); - dataTable.setModel(model); - // - dataTable.setColumnClass(0, Boolean.class, false); // 0-Selection - dataTable.setColumnClass(1, BigDecimal.class, true); // 1-Qty - dataTable.setColumnClass(2, String.class, true); // 2-UOM - dataTable.setColumnClass(3, String.class, true); // 3-Product - dataTable.setColumnClass(4, String.class, true); // 4-VendorProductNo - dataTable.setColumnClass(5, String.class, true); // 5-Order - dataTable.setColumnClass(6, String.class, true); // 6-Ship - dataTable.setColumnClass(7, String.class, true); // 7-Invoice - // Table UI - dataTable.autoSize(); - } // loadOrder - - /** - * Set form status line. - * Please note, will enable/disable the OK button if the selectedRowCount > 0. - * @param selectedRowCount number of selected lines - * @param text additional text - */ - protected void setStatusLine(int selectedRowCount, String text) { - StringBuffer sb = new StringBuffer(String.valueOf(selectedRowCount)); - if (text != null && text.trim().length() > 0) { - sb.append(" - ").append(text); - } - statusBar.setStatusLine(sb.toString()); - // - confirmPanel.getOKButton().setEnabled(selectedRowCount > 0); - } - - public void showWindow() - { - setVisible(true); - } - - public void closeWindow() - { - dispose(); - } -} // VCreateFrom diff --git a/client/src/org/compiere/grid/VCreateFromFactory.java b/client/src/org/compiere/grid/VCreateFromFactory.java index ff8e4bd401..6612eaad22 100644 --- a/client/src/org/compiere/grid/VCreateFromFactory.java +++ b/client/src/org/compiere/grid/VCreateFromFactory.java @@ -51,7 +51,7 @@ public class VCreateFromFactory s_registeredClasses.put(I_C_BankStatement.Table_ID, VCreateFromStatementUI.class); s_registeredClasses.put(I_M_InOut.Table_ID, VCreateFromShipmentUI.class); - s_registeredClasses.put(I_M_RMA.Table_ID, VCreateFromRMA.class); + s_registeredClasses.put(I_M_RMA.Table_ID, VCreateFromRMAUI.class); } /** diff --git a/client/src/org/compiere/grid/VCreateFromRMAUI.java b/client/src/org/compiere/grid/VCreateFromRMAUI.java new file mode 100644 index 0000000000..72aea94213 --- /dev/null +++ b/client/src/org/compiere/grid/VCreateFromRMAUI.java @@ -0,0 +1,197 @@ +/****************************************************************************** + * 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.beans.PropertyChangeEvent; +import java.beans.VetoableChangeListener; +import java.util.Vector; +import java.util.logging.Level; + +import javax.swing.JLabel; +import javax.swing.table.DefaultTableModel; + +import org.compiere.apps.AEnv; +import org.compiere.grid.ed.VLookup; +import org.compiere.model.GridTab; +import org.compiere.model.MLookup; +import org.compiere.model.MLookupFactory; +import org.compiere.swing.CPanel; +import org.compiere.util.CLogger; +import org.compiere.util.DisplayType; +import org.compiere.util.Env; +import org.compiere.util.Msg; + +public class VCreateFromRMAUI extends CreateFromRMA implements VetoableChangeListener +{ + private static final long serialVersionUID = 1L; + + private VCreateFromDialog dialog; + + public VCreateFromRMAUI(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; + + /** + * 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()); + + initBPartner(true); + bPartnerField.addVetoableChangeListener(this); + + loadRMA(); + + 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")); + + 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)); + } // jbInit + + /*************************************************************************/ + /** + * 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")) + { + loadRMA(); + } + 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)); + } // initBPartner + + protected void loadRMA() + { + loadTableOIS(getRMAData()); + } + + /** + * 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(); + } +} diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java deleted file mode 100644 index d2861f33ea..0000000000 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java +++ /dev/null @@ -1,634 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * 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. * - * 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.adempiere.webui.apps.form; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Vector; -import java.util.logging.Level; - -import org.adempiere.webui.apps.AEnv; -import org.adempiere.webui.component.Button; -import org.adempiere.webui.component.Checkbox; -import org.adempiere.webui.component.Combobox; -import org.adempiere.webui.component.ConfirmPanel; -import org.adempiere.webui.component.Grid; -import org.adempiere.webui.component.GridFactory; -import org.adempiere.webui.component.Label; -import org.adempiere.webui.component.ListModelTable; -import org.adempiere.webui.component.Listbox; -import org.adempiere.webui.component.ListboxFactory; -import org.adempiere.webui.component.Panel; -import org.adempiere.webui.component.Row; -import org.adempiere.webui.component.Rows; -import org.adempiere.webui.component.WAppsAction; -import org.adempiere.webui.component.WListbox; -import org.adempiere.webui.component.Window; -import org.adempiere.webui.editor.WEditor; -import org.adempiere.webui.editor.WLocatorEditor; -import org.adempiere.webui.editor.WSearchEditor; -import org.adempiere.webui.editor.WStringEditor; -import org.adempiere.webui.event.WTableModelEvent; -import org.adempiere.webui.event.WTableModelListener; -import org.adempiere.webui.panel.StatusBarPanel; -import org.compiere.grid.ICreateFrom; -import org.compiere.model.GridTab; -import org.compiere.model.MLookup; -import org.compiere.model.MLookupFactory; -import org.compiere.model.MOrder; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Msg; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.EventListener; -import org.zkoss.zkex.zul.Borderlayout; -import org.zkoss.zkex.zul.Center; -import org.zkoss.zkex.zul.North; -import org.zkoss.zkex.zul.South; -import org.zkoss.zul.Separator; -import org.zkoss.zul.Space; - -/** - * CreateFrom (Called from GridController.startProcess) - * - * @author Jorg Janke - * @version $Id: VCreateFrom.java,v 1.4 2006/10/11 09:52:23 comdivision Exp $ - * - * @author Teo Sarca, SC ARHIPAC SERVICE SRL - *
  • FR [ 1794050 ] Usability: VCreateFrom OK button always enabled - * @author Victor Perez, e-Evolucion - *
  • RF [1811114] http://sourceforge.net/tracker/index.php?func=detail&aid=1811114&group_id=176962&atid=879335 - * @author Karsten Thiemann, Schaeffer AG - *
  • Bug [ 1759431 ] Problems with VCreateFrom - */ -public abstract class WCreateFrom extends Window - implements ICreateFrom, EventListener, WTableModelListener -{ - /** - * - */ - private static final long serialVersionUID = 15158515174358003L; - /** - * Factory - called from APanel - * @param mTab Model Tab for the trx - * @return JDialog - */ - public static WCreateFrom create (GridTab mTab) - { - // dynamic init preparation - int AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), "BaseTable_ID"); - - WCreateFrom retValue = null; - if (AD_Table_ID == 319) // M_InOut - retValue = new WCreateFromShipment (mTab); - else if (AD_Table_ID == 426) // C_PaySelection - return null; // ignore - will call process C_PaySelection_CreateFrom - /** - * Modification to support create Lines from for RMA - * @author ashley - */ - else if (AD_Table_ID == 661) - retValue = new WCreateFromRMA(mTab); // RMA - else // Not supported CreateFrom - { - s_log.info("Unsupported AD_Table_ID=" + AD_Table_ID); - return null; - } - return retValue; - } // create - - - /************************************************************************** - * Protected super class Constructor - * @param mTab MTab - */ - WCreateFrom (GridTab mTab) - { - super(); - this.setAttribute("mode", "modal"); - log.info(mTab.toString()); - p_WindowNo = mTab.getWindowNo(); - p_mTab = mTab; - - try - { - if (!dynInit()) - return; - zkInit(); - confirmPanel.addActionListener(this); - // Set status - statusBar.setStatusDB(""); - tableChanged(null); - p_initOK = true; - } - catch(Exception e) - { - log.log(Level.SEVERE, "", e); - p_initOK = false; - } - AEnv.showWindow(this); - } // VCreateFrom - - /** Window No */ - protected int p_WindowNo; - /** Model Tab */ - protected GridTab p_mTab; - - private boolean p_initOK = false; - - /** Loaded Order */ - protected MOrder p_order = null; - /** Logger */ - protected CLogger log = CLogger.getCLogger(getClass()); - /** Static Logger */ - private static CLogger s_log = CLogger.getCLogger (WCreateFrom.class); - - // - protected Borderlayout contentPane = new Borderlayout(); - protected Panel parameterPanel = new Panel(); - protected Panel parameterBankPanel = new Panel(); - protected Borderlayout parameterLayout = new Borderlayout(); - protected Label bankAccountLabel = new Label(); - protected Panel parameterStdPanel = new Panel(); - protected Label bPartnerLabel = new Label(); - protected Combobox bankAccountField; - //RF [1811114] - protected Label authorizationLabel = new Label(); - protected WStringEditor authorizationField = new WStringEditor(); - protected Grid parameterStdLayout = GridFactory.newGridLayout(); - protected Grid parameterBankLayout = GridFactory.newGridLayout(); - // Bug [1759431] - protected Checkbox sameWarehouseCb = new Checkbox(); - protected WEditor bPartnerField; - protected Label orderLabel = new Label(); - protected Listbox orderField = ListboxFactory.newDropdownListbox(); - protected Label invoiceLabel = new Label(); - protected Listbox invoiceField = ListboxFactory.newDropdownListbox(); - protected Label shipmentLabel = new Label(); - protected Listbox shipmentField = ListboxFactory.newDropdownListbox(); -// private JScrollPane dataPane = new JScrollPane(); - protected Panel southPanel = new Panel(); -// private Borderlayout southLayout = new Borderlayout(); - protected ConfirmPanel confirmPanel = new ConfirmPanel(true); - protected StatusBarPanel statusBar = new StatusBarPanel(); - protected WListbox dataTable = ListboxFactory.newDataTable(); - protected Label locatorLabel = new Label(); - protected WLocatorEditor locatorField = new WLocatorEditor(); - public static final String SELECT_ALL = "SelectAll"; -// public static final String SELECT_ALL_TOOLTIP = "Select all records"; - - /** Label for the rma selection */ - protected Label rmaLabel = new Label(); - /** Combo box for selecting RMA document */ - protected Listbox rmaField = ListboxFactory.newDropdownListbox(); - /** - * Static Init. - *
    -	 *  parameterPanel
    -	 *      parameterBankPanel
    -	 *      parameterStdPanel
    -	 *          bPartner/order/invoice/shopment/licator Label/Field
    -	 *  dataPane
    -	 *  southPanel
    -	 *      confirmPanel
    -	 *      statusBar
    -	 *  
    - * @throws Exception - */ - protected void zkInit() throws Exception - { - parameterPanel.appendChild(parameterLayout); - parameterStdPanel.appendChild(parameterStdLayout); - parameterBankPanel.appendChild(parameterBankLayout); - // - bankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); - //RF [1811114] - authorizationLabel.setText(Msg.translate(Env.getCtx(), "R_AuthCode")); - bPartnerLabel.setText(Msg.getElement(Env.getCtx(), "C_BPartner_ID")); - orderLabel.setText(Msg.getElement(Env.getCtx(), "C_Order_ID", false)); - invoiceLabel.setText(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); - shipmentLabel.setText(Msg.getElement(Env.getCtx(), "M_InOut_ID", false)); - locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID")); - rmaLabel.setText(Msg.translate(Env.getCtx(), "M_RMA_ID")); - sameWarehouseCb.setText(Msg.getMsg(Env.getCtx(), "FromSameWarehouseOnly", true)); - sameWarehouseCb.setTooltiptext(Msg.getMsg(Env.getCtx(), "FromSameWarehouseOnly", false)); - - // - North north = new North(); - this.appendChild(contentPane); - contentPane.appendChild(north); - north.appendChild(parameterPanel); - parameterPanel.appendChild(parameterLayout); - north = new North(); - parameterLayout.appendChild(north); - north.appendChild(parameterBankPanel); - - parameterLayout.setHeight("110px"); - parameterLayout.setWidth("100%"); - - parameterBankPanel.appendChild(parameterBankLayout); - //RF [1811114] - Rows rows = (Rows) parameterBankLayout.newRows(); - Row row = rows.newRow(); - row.appendChild(bankAccountLabel.rightAlign()); - if (bankAccountField != null) - row.appendChild(bankAccountField); - row.appendChild(authorizationLabel.rightAlign()); - row.appendChild(authorizationField.getComponent()); - - Center center = new Center(); - parameterLayout.appendChild(center); - center.appendChild(parameterStdPanel); - - parameterStdPanel.appendChild(parameterStdLayout); - rows = (Rows) parameterStdLayout.newRows(); - row = rows.newRow(); - row.appendChild(bPartnerLabel.rightAlign()); - if (bPartnerField != null) - row.appendChild(bPartnerField.getComponent()); - row.appendChild(orderLabel.rightAlign()); - row.appendChild(orderField); - - row = rows.newRow(); - row.appendChild(locatorLabel.rightAlign()); - row.appendChild(locatorField.getComponent()); - row.appendChild(invoiceLabel.rightAlign()); - row.appendChild(invoiceField); - - row = rows.newRow(); - row.appendChild(new Space()); - row.appendChild(sameWarehouseCb); - row.appendChild(shipmentLabel.rightAlign()); - row.appendChild(shipmentField); - - // Add RMA document selection to panel - row = rows.newRow(); - row.appendChild(new Space()); - row.appendChild(new Space()); - row.appendChild(rmaLabel.rightAlign()); - row.appendChild(rmaField); - - center = new Center(); - contentPane.appendChild(center); - center.appendChild(dataTable); - // - // - // @Trifon - WAppsAction selectAllAction = new WAppsAction (SELECT_ALL, null, null); - - Button selectAllButton = selectAllAction.getButton(); - confirmPanel.addComponentsLeft(selectAllButton); - selectAllButton.addActionListener(this); - // - South south = new South(); - contentPane.appendChild(south); - south.appendChild(southPanel); - southPanel.appendChild(new Separator()); - southPanel.appendChild(confirmPanel); - // Trifon End - southPanel.appendChild(new Separator()); - southPanel.appendChild(statusBar); - - this.setWidth("750px"); - this.setHeight("550px"); - this.setSizable(true); - this.setBorder("normal"); - contentPane.setWidth("100%"); - contentPane.setHeight("100%"); - } // jbInit - - /** - * Init OK to be able to make changes? - * @return on if initialized - */ - public boolean isInitOK() - { - return p_initOK; - } // isInitOK - - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - abstract boolean dynInit() throws Exception; - - /** - * Init Business Partner Details - * @param C_BPartner_ID BPartner - */ - abstract void initBPDetails(int C_BPartner_ID); - - /** - * Add Info - */ - abstract void info(); - - /** - * Save & Insert Data - * @return true if saved - */ - abstract boolean save(); - - /*************************************************************************/ - - /** - * Action Listener - * @param e event - * @throws Exception - */ - public void onEvent(Event e) throws Exception - { - log.config("Action=" + e.getTarget().getId()); - // if (m_action) - // return; - // m_action = true; - - // OK - Save - if (e.getTarget().getId().equals(ConfirmPanel.A_OK)) - { - if (save()) - dispose(); - } - // Cancel - else if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) - { - dispose(); - } - // Select All - // Trifon - else if (e.getTarget().getId().equals(SELECT_ALL)) { - ListModelTable model = dataTable.getModel(); - int rows = model.getSize(); - for (int i = 0; i < rows; i++) - { - model.setValueAt(new Boolean(true), i, 0); - } - //refresh - dataTable.setModel(model); - info(); - } - // m_action = false; - } // actionPerformed - - /** - * Table Model Listener - * @param e event - */ - public void tableChanged (WTableModelEvent e) - { - int type = -1; - if (e != null) - { - type = e.getType(); - if (type != WTableModelEvent.CONTENTS_CHANGED) - return; - } - log.config("Type=" + type); - info(); - } // tableChanged - - - /************************************************************************** - * 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 WSearchEditor ("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 - initBPartnerOIS(C_BPartner_ID, forInvoice); - } // initBPartner - - /** - * Load PBartner dependent Order/Invoice/Shipment Field. - * @param C_BPartner_ID BPartner - * @param forInvoice for invoice - */ - protected void initBPartnerOIS (int C_BPartner_ID, boolean forInvoice) - { - log.config("C_BPartner_ID=" + C_BPartner_ID); - KeyNamePair pp = new KeyNamePair(0,""); - boolean sameWarehouseOnly = sameWarehouseCb.isVisible() && sameWarehouseCb.isSelected(); - // load PO Orders - Closed, Completed - orderField.removeActionListener(this); - orderField.removeAllItems(); - orderField.addItem(pp); - // Display - StringBuffer display = new StringBuffer("o.DocumentNo||' - ' ||") - .append(DB.TO_CHAR("o.DateOrdered", DisplayType.Date, Env.getAD_Language(Env.getCtx()))) - .append("||' - '||") - .append(DB.TO_CHAR("o.GrandTotal", DisplayType.Amount, Env.getAD_Language(Env.getCtx()))); - // - String column = "ol.QtyDelivered"; - if (forInvoice) - column = "ol.QtyInvoiced"; - StringBuffer sql = new StringBuffer("SELECT o.C_Order_ID,").append(display) - .append(" FROM C_Order o " - + "WHERE o.C_BPartner_ID=? AND o.IsSOTrx='N' AND o.DocStatus IN ('CL','CO')" - + " AND o.C_Order_ID IN " - + "(SELECT ol.C_Order_ID FROM C_OrderLine ol" - + " WHERE ol.QtyOrdered - ").append(column).append(" != 0) "); - if(sameWarehouseOnly) { - sql = sql.append(" AND o.M_Warehouse_ID=? "); - } - sql = sql.append("ORDER BY o.DateOrdered"); - try - { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); - pstmt.setInt(1, C_BPartner_ID); - if(sameWarehouseOnly) { - //only active for material receipts - pstmt.setInt(2, Env.getContextAsInt(Env.getCtx(), p_WindowNo, "M_Warehouse_ID")); - } - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - orderField.addItem(pp); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql.toString(), e); - } - orderField.setSelectedIndex(0); - orderField.addActionListener(this); - - initBPDetails(C_BPartner_ID); - } // initBPartnerOIS - - /** - * 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) - { - /** - * Selected - 0 - * Qty - 1 - * C_UOM_ID - 2 - * M_Product_ID - 3 - * VendorProductNo - 4 - * OrderLine - 5 - * ShipmentLine - 6 - * InvoiceLine - 7 - */ - log.config("C_Order_ID=" + C_Order_ID); - p_order = new MOrder (Env.getCtx(), C_Order_ID, null); // save - - 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 - + " l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name)," // 3..4 - + " COALESCE(l.M_Product_ID,0),COALESCE(p.Name,c.Name),po.VendorProductNo," // 5..7 - + " l.C_OrderLine_ID,l.Line " // 8..9 - + "FROM C_OrderLine l" - + " LEFT OUTER JOIN M_Product_PO po ON (l.M_Product_ID = po.M_Product_ID AND l.C_BPartner_ID = po.C_BPartner_ID) " - + " LEFT OUTER JOIN M_MatchPO m ON (l.C_OrderLine_ID=m.C_OrderLine_ID AND "); - sql.append(forInvoice ? "m.C_InvoiceLine_ID" : "m.M_InOutLine_ID"); - sql.append(" IS NOT NULL)") - .append(" LEFT OUTER JOIN M_Product p ON (l.M_Product_ID=p.M_Product_ID)" - + " LEFT OUTER JOIN C_Charge c ON (l.C_Charge_ID=c.C_Charge_ID)"); - if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) - sql.append(" LEFT OUTER JOIN C_UOM uom ON (l.C_UOM_ID=uom.C_UOM_ID)"); - else - sql.append(" LEFT OUTER JOIN C_UOM_Trl uom ON (l.C_UOM_ID=uom.C_UOM_ID AND uom.AD_Language='") - .append(Env.getAD_Language(Env.getCtx())).append("')"); - // - sql.append(" WHERE l.C_Order_ID=? " // #1 - + "GROUP BY l.QtyOrdered,CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END, " - + "l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name),po.VendorProductNo, " - + "l.M_Product_ID,COALESCE(p.Name,c.Name), l.Line,l.C_OrderLine_ID " - + "ORDER BY l.Line"); - // - log.finer(sql.toString()); - try - { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); - pstmt.setInt(1, C_Order_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - Vector line = new Vector(); - line.add(new Boolean(false)); // 0-Selection - BigDecimal qtyOrdered = rs.getBigDecimal(1); - BigDecimal multiplier = rs.getBigDecimal(2); - BigDecimal qtyEntered = qtyOrdered.multiply(multiplier); - line.add(new Double(qtyEntered.doubleValue())); // 1-Qty - KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(4).trim()); - line.add(pp); // 2-UOM - pp = new KeyNamePair(rs.getInt(5), rs.getString(6)); - line.add(pp); // 3-Product - line.add(rs.getString(7)); // 4-VendorProductNo - pp = new KeyNamePair(rs.getInt(8), rs.getString(9)); - line.add(pp); // 5-OrderLine - line.add(null); // 6-Ship - line.add(null); // 7-Invoice - data.add(line); - } - rs.close(); - pstmt.close(); - } - catch (Exception e) - { - log.log(Level.SEVERE, sql.toString(), e); - } - loadTableOIS (data); - } // LoadOrder - - - /** - * Load Order/Invoice/Shipment data into Table - * @param data data - */ - protected void loadTableOIS (Vector> data) - { - dataTable.clear(); - // 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_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_InOut_ID", false)); - columnNames.add(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); - - // Remove previous listeners - dataTable.getModel().removeTableModelListener(this); - // Set Model - ListModelTable model = new ListModelTable(data); - model.addTableModelListener(this); - dataTable.setData(model, columnNames); - // - dataTable.setColumnClass(0, Boolean.class, false); // 0-Selection - dataTable.setColumnClass(1, Double.class, true); // 1-Qty - dataTable.setColumnClass(2, String.class, true); // 2-UOM - dataTable.setColumnClass(3, String.class, true); // 3-Product - dataTable.setColumnClass(4, String.class, true); // 4-VendorProductNo - dataTable.setColumnClass(5, String.class, true); // 5-Order - dataTable.setColumnClass(6, String.class, true); // 6-Ship - dataTable.setColumnClass(7, String.class, true); // 7-Invoice - // Table UI - dataTable.autoSize(); - } // loadOrder - - /** - * Set form status line. - * Please note, will enable/disable the OK button if the selectedRowCount > 0. - * @param selectedRowCount number of selected lines - * @param text additional text - */ - protected void setStatusLine(int selectedRowCount, String text) { - StringBuffer sb = new StringBuffer(String.valueOf(selectedRowCount)); - if (text != null && text.trim().length() > 0) { - sb.append(" - ").append(text); - } - statusBar.setStatusLine(sb.toString()); - // - confirmPanel.getOKButton().setEnabled(selectedRowCount > 0); - } - - public void showWindow() - { - setVisible(true); - } - - public void closeWindow() - { - dispose(); - } -} // VCreateFrom diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java index 45a42f8287..320b697aa2 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java @@ -52,7 +52,7 @@ public class WCreateFromFactory s_registeredClasses.put(I_C_BankStatement.Table_ID, WCreateFromStatementUI.class); s_registeredClasses.put(I_M_InOut.Table_ID, WCreateFromShipmentUI.class); - s_registeredClasses.put(I_M_RMA.Table_ID, WCreateFromRMA.class); + s_registeredClasses.put(I_M_RMA.Table_ID, WCreateFromRMAUI.class); } /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMA.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMA.java deleted file mode 100644 index eccba96b49..0000000000 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMA.java +++ /dev/null @@ -1,243 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 2007 Adempiere, Inc. All Rights Reserved. * - * 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.adempiere.webui.apps.form; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Vector; -import java.util.logging.Level; - -import org.adempiere.webui.component.ListModelTable; -import org.compiere.model.GridTab; -import org.compiere.model.MRMA; -import org.compiere.model.MRMALine; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Msg; - -/** - * @author ashley - */ -public class WCreateFromRMA extends WCreateFrom -{ - /** - * - */ - private static final long serialVersionUID = 485406606040533083L; - - /** - * - * @param mTab - */ - public WCreateFromRMA(GridTab mTab) - { - super(mTab); - log.info(mTab.toString()); - } - - protected boolean dynInit() throws Exception - { - log.config(""); - setTitle("Customer RMA - Create Lines From"); - - parameterBankPanel.setVisible(false); - - invoiceLabel.setVisible(false); - invoiceField.setVisible(false); - - locatorLabel.setVisible(false); - locatorField.setVisible(false); - - orderLabel.setVisible(false); - orderField.setVisible(false); - - shipmentLabel.setVisible(false); - shipmentField.setVisible(false); - - sameWarehouseCb.setVisible(false); - - rmaLabel.setVisible(false); - rmaField.setVisible(false); - - initBPartner(true); - - bPartnerField.setReadWrite(false); - - int inOutId = Env.getContextAsInt(Env.getCtx(), p_mTab.getWindowNo(), "InOut_ID"); - - loadShipment(inOutId); - - return true; - } - - /** - * Load Order/Invoice/Shipment data into Table - * @param data data - */ - protected void loadTableOIS (Vector data) - { - dataTable.clear(); - // Header Info - Vector columnNames = new Vector(7); - columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); - columnNames.add("Line"); - columnNames.add(Msg.translate(Env.getCtx(), "M_Product_ID")); - columnNames.add("ASI"); - columnNames.add(Msg.translate(Env.getCtx(), "Quantity")); - columnNames.add(Msg.getElement(Env.getCtx(), "QtyDelivered", false)); - - - // Remove previous listeners - dataTable.getModel().removeTableModelListener(this); - // Set Model - ListModelTable model = new ListModelTable(data); - model.addTableModelListener(this); - dataTable.setData(model, columnNames); - // - dataTable.setColumnClass(0, Boolean.class, false); // 0-Selection - dataTable.setColumnClass(1, String.class, true); // 1-Line - dataTable.setColumnClass(2, String.class, true); // 2-Product - dataTable.setColumnClass(3, String.class, true); // 3-ASI - dataTable.setColumnClass(4, Double.class, true); // 4-Qty - dataTable.setColumnClass(5, Double.class, true); // 5-Delivered Qty - - // Table UI - dataTable.autoSize(); - } // loadOrder - - /** - * Load Data - Shipment not invoiced - * @param M_InOut_ID InOut - */ - private void loadShipment (int M_InOut_ID) - { - int m_rma_id = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "M_RMA_ID"); - log.config("M_InOut_ID=" + M_InOut_ID); - log.config("M_RMA_ID=" + m_rma_id); - // - Vector> data = new Vector>(); - - /** - * 1 M_InOutLine_ID - * 2 Line - * 3 Product Name - * 4 Qty Entered - * 5 Movement Qty - * 6 ASI - */ - StringBuffer sqlStmt = new StringBuffer(); - - sqlStmt.append("SELECT iol.M_InOutLine_ID, iol.Line, "); - sqlStmt.append("CASE WHEN iol.M_Product_ID IS NOT NULL THEN (Select p.Name from M_Product p where p.M_Product_ID = iol.M_Product_ID) END as ProductName, "); - sqlStmt.append("iol.QtyEntered, "); - sqlStmt.append("iol.movementQty, "); - sqlStmt.append("CASE WHEN iol.M_AttributeSetInstance_ID IS NOT NULL THEN (SELECT SerNo FROM M_AttributeSetInstance asi where asi.M_AttributeSetInstance_ID=iol.M_AttributeSetInstance_ID) END as ASI "); - sqlStmt.append("from M_InOutLine iol where M_InOut_ID=? "); - sqlStmt.append("and iol.M_InOutLine_ID not in (select rmal.M_InOutLine_ID from M_RMALine rmal where rmal.M_RMA_ID=?)"); - - - try - { - PreparedStatement pstmt = DB.prepareStatement(sqlStmt.toString(), null); - pstmt.setInt(1, M_InOut_ID); - pstmt.setInt(2, m_rma_id); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - Vector line = new Vector(7); - line.add(new Boolean(false)); // 0-Selection - - KeyNamePair lineKNPair = new KeyNamePair(rs.getInt(1), rs.getString(2)); // 1-Line - line.add(lineKNPair); - line.add(rs.getString(3)); //2-Product - line.add(rs.getString(6)); //3-ASI - - BigDecimal qtyEntered = rs.getBigDecimal(4); - BigDecimal movementQty = rs.getBigDecimal(5); - - line.add(qtyEntered.doubleValue()); //4-Qty - line.add(movementQty.doubleValue()); //5-Movement Qty - - - data.add(line); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sqlStmt.toString(), e); - } - loadTableOIS (data); - } // loadShipment - - protected void initBPDetails(int C_BPartner_ID) - { - - } - - protected void info() - { - - } - - protected boolean save() - { - log.config(""); - int m_rma_id = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "M_RMA_ID"); - ListModelTable model = dataTable.getModel(); - int rows = model.getSize(); - if (rows == 0) - { - return false; - } - -// Integer bpId = (Integer)bPartnerField.getValue(); - MRMA rma = new MRMA(Env.getCtx(), m_rma_id, null); - //update BP -// rma.setC_BPartner_ID(bpId); - - for (int i = 0; i < rows; i++) - { - if (((Boolean)model.getValueAt(i, 0)).booleanValue()) - { - Double d = (Double)model.getValueAt(i, 5); // 5-Movement Qty - KeyNamePair pp = (KeyNamePair)model.getValueAt(i, 1); // 1-Line - - int inOutLineId = pp.getKey(); - - MRMALine rmaLine = new MRMALine(Env.getCtx(), 0, null); - rmaLine.setM_RMA_ID(m_rma_id); - rmaLine.setM_InOutLine_ID(inOutLineId); - rmaLine.setQty(new BigDecimal(d)); - rmaLine.setAD_Org_ID(rma.getAD_Org_ID()); - if (!rmaLine.save()) - { - throw new IllegalStateException("Could not create RMA Line"); - } - } - } - - if (!rma.save()) - { - throw new IllegalStateException("Could not update RMA"); - } - - return true; - } - -} diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMAUI.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMAUI.java new file mode 100644 index 0000000000..fcfe17b076 --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMAUI.java @@ -0,0 +1,192 @@ +/****************************************************************************** + * 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.adempiere.webui.apps.form; + +import java.util.Vector; +import java.util.logging.Level; + +import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.component.Grid; +import org.adempiere.webui.component.GridFactory; +import org.adempiere.webui.component.Label; +import org.adempiere.webui.component.ListModelTable; +import org.adempiere.webui.component.Panel; +import org.adempiere.webui.component.Row; +import org.adempiere.webui.component.Rows; +import org.adempiere.webui.editor.WEditor; +import org.adempiere.webui.editor.WSearchEditor; +import org.adempiere.webui.event.ValueChangeEvent; +import org.adempiere.webui.event.ValueChangeListener; +import org.compiere.grid.CreateFromRMA; +import org.compiere.model.GridTab; +import org.compiere.model.MLookup; +import org.compiere.model.MLookupFactory; +import org.compiere.util.CLogger; +import org.compiere.util.DisplayType; +import org.compiere.util.Env; +import org.compiere.util.Msg; +import org.zkoss.zkex.zul.Borderlayout; +import org.zkoss.zkex.zul.Center; + +public class WCreateFromRMAUI extends CreateFromRMA implements ValueChangeListener +{ + private static final long serialVersionUID = 1L; + + private WCreateFromWindow window; + + public WCreateFromRMAUI(GridTab tab) + { + super(tab); + log.info(getGridTab().toString()); + + window = new WCreateFromWindow(this, getGridTab().getWindowNo()); + + p_WindowNo = getGridTab().getWindowNo(); + + try + { + if (!dynInit()) + return; + zkInit(); + setInitOK(true); + } + catch(Exception e) + { + log.log(Level.SEVERE, "", e); + setInitOK(false); + } + AEnv.showWindow(window); + } + + /** Window No */ + private int p_WindowNo; + + /** Logger */ + private CLogger log = CLogger.getCLogger(getClass()); + + protected Label bPartnerLabel = new Label(); + protected WEditor bPartnerField; + + /** + * Dynamic Init + * @throws Exception if Lookups cannot be initialized + * @return true if initialized + */ + public boolean dynInit() throws Exception + { + log.config(""); + + super.dynInit(); + + window.setTitle(getTitle()); + + initBPartner(true); + bPartnerField.addValueChangeListener(this); + + loadRMA(); + + return true; + } // dynInit + + protected void zkInit() throws Exception + { + bPartnerLabel.setText(Msg.getElement(Env.getCtx(), "C_BPartner_ID")); + + Borderlayout parameterLayout = new Borderlayout(); + parameterLayout.setHeight("110px"); + parameterLayout.setWidth("100%"); + Panel parameterPanel = window.getParameterPanel(); + parameterPanel.appendChild(parameterLayout); + + Grid parameterStdLayout = GridFactory.newGridLayout(); + Panel parameterStdPanel = new Panel(); + parameterStdPanel.appendChild(parameterStdLayout); + + Center center = new Center(); + parameterLayout.appendChild(center); + center.appendChild(parameterStdPanel); + + Rows rows = (Rows) parameterStdLayout.newRows(); + Row row = rows.newRow(); + row.appendChild(bPartnerLabel.rightAlign()); + if (bPartnerField != null) + row.appendChild(bPartnerField.getComponent()); + } + + /** + * Change Listener + * @param e event + */ + public void valueChange (ValueChangeEvent e) + { + log.config(e.getPropertyName() + "=" + e.getNewValue()); + + // BPartner - load Order/Invoice/Shipment + if (e.getPropertyName().equals("C_BPartner_ID")) + { + loadRMA(); + } + window.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 WSearchEditor ("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)); + } // initBPartner + + protected void loadRMA() + { + loadTableOIS(getRMAData()); + } + + /** + * 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/apps/form/WCreateFromShipment.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipment.java deleted file mode 100644 index 601f261829..0000000000 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipment.java +++ /dev/null @@ -1,723 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * 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. * - * 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.adempiere.webui.apps.form; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Vector; -import java.util.logging.Level; - -import org.adempiere.webui.component.Label; -import org.adempiere.webui.component.ListModelTable; -import org.adempiere.webui.editor.WLocatorEditor; -import org.adempiere.webui.event.ValueChangeEvent; -import org.adempiere.webui.event.ValueChangeListener; -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.MLocatorLookup; -import org.compiere.model.MOrderLine; -import org.compiere.model.MProduct; -import org.compiere.model.MRMA; -import org.compiere.model.MRMALine; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Msg; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zul.Popup; - -/** - * Create Shipments Transactions - from PO Orders or AP Invoices - * - * @author Jorg Janke - * @version $Id: VCreateFromShipment.java,v 1.4 2006/07/30 00:51:28 jjanke Exp $ - */ -public class WCreateFromShipment extends WCreateFrom implements ValueChangeListener -{ - /** - * - */ - private static final long serialVersionUID = 1097942250809500954L; - - /** - * Protected Constructor - * @param mTab MTab - */ - public WCreateFromShipment(GridTab mTab) - { - super (mTab); - // log.info( "VCreateFromShipment"); - } // VCreateFromShipment - - /** Loaded Invoice */ - private MInvoice m_invoice = null; - /** Loaded RMA */ - private MRMA m_rma = null; - - /** - * Load Order/Invoice/RMA data into Table - * @param data data - */ - protected void loadTableOIS (Vector data) - { - dataTable.clear(); - // 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_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)); - - // Remove previous listeners - dataTable.getModel().removeTableModelListener(this); - // Set Model - ListModelTable model = new ListModelTable(data); - model.addTableModelListener(this); - dataTable.setData(model, columnNames); - // - dataTable.setColumnClass(0, Boolean.class, false); // 0-Selection - dataTable.setColumnClass(1, Double.class, true); // 1-Qty - dataTable.setColumnClass(2, String.class, true); // 2-UOM - dataTable.setColumnClass(3, String.class, true); // 3-Product - dataTable.setColumnClass(4, String.class, true); // 4-VendorProductNo - dataTable.setColumnClass(5, String.class, true); // 5-Order - dataTable.setColumnClass(6, String.class, true); // 6-RMA - dataTable.setColumnClass(7, String.class, true); // 7-Invoice - // Table UI - dataTable.autoSize(); - } // loadOrder - - /** - * Dynamic Init - * @throws Exception if Lookups cannot be initialized - * @return true if initialized - */ - protected boolean dynInit() throws Exception - { - log.config(""); - setTitle(Msg.getElement(Env.getCtx(), "M_InOut_ID", false) + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); - - parameterBankPanel.setVisible(false); - shipmentLabel.setVisible(false); - shipmentField.setVisible(false); - sameWarehouseCb.setSelected(true); - sameWarehouseCb.addActionListener(this); - - // load Locator - int AD_Column_ID = 3537; // M_InOut.M_Locator_ID - MLocatorLookup locator = new MLocatorLookup(Env.getCtx(), p_WindowNo); - locatorField = new WLocatorEditor ("M_Locator_ID", true, false, true, locator, p_WindowNo); - - initBPartner(false); - bPartnerField.addValueChangeListener(this); - - locatorLabel.setMandatory(true); - return true; - } // dynInit - - /** - * Init Details - load invoices not shipped and RMA candidates for Shipment - * @param C_BPartner_ID BPartner - */ - protected void initBPDetails(int C_BPartner_ID) - { - log.config("C_BPartner_ID=" + C_BPartner_ID); - - initBPInvoiceDetails(C_BPartner_ID); - initBPRMADetails(C_BPartner_ID); - } // initBPDetails - - /** - * Init Details - load invoices not shipped - * @param C_BPartner_ID BPartner - */ - private void initBPInvoiceDetails(int C_BPartner_ID) - { -// load AP Invoice closed or complete - invoiceField.removeActionListener(this); - invoiceField.removeAllItems(); - // None - KeyNamePair pp = new KeyNamePair(0,""); - invoiceField.addItem(pp); - StringBuffer display = new StringBuffer("i.DocumentNo||' - '||") - .append(DB.TO_CHAR("DateInvoiced", DisplayType.Date, Env.getAD_Language(Env.getCtx()))) - .append("|| ' - ' ||") - .append(DB.TO_CHAR("GrandTotal", DisplayType.Amount, Env.getAD_Language(Env.getCtx()))); - // - StringBuffer sql = new StringBuffer("SELECT i.C_Invoice_ID,").append(display) - .append(" FROM C_Invoice i " - + "WHERE i.C_BPartner_ID=? AND i.IsSOTrx='N' AND i.DocStatus IN ('CL','CO')" - + " AND i.C_Invoice_ID IN " - + "(SELECT il.C_Invoice_ID FROM C_InvoiceLine il" - + " LEFT OUTER JOIN M_MatchInv mi ON (il.C_InvoiceLine_ID=mi.C_InvoiceLine_ID) " - + "GROUP BY il.C_Invoice_ID,mi.C_InvoiceLine_ID,il.QtyInvoiced " - + "HAVING (il.QtyInvoiced<>SUM(mi.Qty) AND mi.C_InvoiceLine_ID IS NOT NULL)" - + " OR mi.C_InvoiceLine_ID IS NULL) " - + "ORDER BY i.DateInvoiced"); - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); - pstmt.setInt(1, C_BPartner_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - invoiceField.addItem(pp); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql.toString(), e); - } - invoiceField.setSelectedIndex(0); - invoiceField.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); - - 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()) - { - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - rmaField.addItem(pp); - } - 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"); - } - } - } - rmaField.setSelectedIndex(0); - rmaField.addActionListener(this); - } - - - /** - * Action Listener - * @param e event - * @throws Exception - */ - public void onEvent(Event e) throws Exception - { - super.onEvent(e); - log.config("Action=" + e.getTarget().getId()); - - // Order - if (e.getTarget().equals(orderField)) - { - KeyNamePair pp = orderField.getSelectedItem().toKeyNamePair(); - 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.getTarget().equals(invoiceField)) - { - KeyNamePair pp = invoiceField.getSelectedItem().toKeyNamePair(); - 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.getTarget().equals(rmaField)) - { - KeyNamePair pp = rmaField.getSelectedItem().toKeyNamePair(); - 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.getTarget().equals(sameWarehouseCb)) - { - initBPartnerOIS(((Integer)bPartnerField.getValue()).intValue(), false); - } - } // actionPerformed - - - /** - * Change Listener - * @param e event - */ - public void valueChange (ValueChangeEvent 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(); - initBPartnerOIS (C_BPartner_ID, false); - } - tableChanged(null); - } // vetoableChange - - - /** - * Load Data - Invoice - * @param C_Invoice_ID Invoice - */ - private void loadInvoice(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(); - 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 - + " l.M_Product_ID,p.Name, po.VendorProductNo, l.C_InvoiceLine_ID,l.Line," // 5..9 - + " l.C_OrderLine_ID " - + " FROM C_InvoiceLine l "); // 10 - if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) - sql.append(" LEFT OUTER JOIN C_UOM uom ON (l.C_UOM_ID=uom.C_UOM_ID)"); - else - sql.append(" LEFT OUTER JOIN C_UOM_Trl uom ON (l.C_UOM_ID=uom.C_UOM_ID AND uom.AD_Language='") - .append(Env.getAD_Language(Env.getCtx())).append("')"); - - sql.append(" LEFT OUTER JOIN M_Product p ON (l.M_Product_ID=p.M_Product_ID)") - .append(" INNER JOIN C_Invoice inv ON (l.C_Invoice_ID=inv.C_Invoice_ID)") - .append(" LEFT OUTER JOIN M_Product_PO po ON (l.M_Product_ID = po.M_Product_ID AND inv.C_BPartner_ID = po.C_BPartner_ID)") - .append(" LEFT OUTER JOIN M_MatchInv mi ON (l.C_InvoiceLine_ID=mi.C_InvoiceLine_ID)") - - .append(" WHERE l.C_Invoice_ID=? ") - .append("GROUP BY l.QtyInvoiced,l.QtyEntered/l.QtyInvoiced," - + "l.C_UOM_ID,COALESCE(uom.UOMSymbol,uom.Name)," - + "l.M_Product_ID,p.Name, po.VendorProductNo, l.C_InvoiceLine_ID,l.Line,l.C_OrderLine_ID ") - .append("ORDER BY l.Line"); - - try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); - pstmt.setInt(1, C_Invoice_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - Vector line = new Vector(7); - line.add(new Boolean(false)); // 0-Selection - BigDecimal qtyInvoiced = rs.getBigDecimal(1); - BigDecimal multiplier = rs.getBigDecimal(2); - BigDecimal qtyEntered = qtyInvoiced.multiply(multiplier); - line.add(new Double(qtyEntered.doubleValue())); // 1-Qty - KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(4).trim()); - line.add(pp); // 2-UOM - pp = new KeyNamePair(rs.getInt(5), rs.getString(6)); - line.add(pp); // 3-Product - line.add(rs.getString(7)); // 4-VendorProductNo - int C_OrderLine_ID = rs.getInt(10); - if (rs.wasNull()) - line.add(null); // 5-Order - else - line.add(new KeyNamePair(C_OrderLine_ID, ".")); - line.add(null); // 6-Ship - pp = new KeyNamePair(rs.getInt(8), rs.getString(9)); - line.add(pp); // 7-Invoice - data.add(line); - } - rs.close(); - pstmt.close(); - } catch (SQLException e) { - log.log(Level.SEVERE, sql.toString(), e); - } - loadTableOIS(data); - } // loadInvoice - - /** - * Load RMA details - * @param M_RMA_ID RMA - */ - private void loadRMA(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; - - try - { - pstmt = DB.prepareStatement(sqlStmt.toString(), null); - pstmt.setInt(1, M_RMA_ID); - pstmt.setInt(2, M_RMA_ID); - ResultSet rs = pstmt.executeQuery(); - - while (rs.next()) - { - Vector line = new Vector(7); - line.add(new Boolean(false)); // 0-Selection - line.add(rs.getBigDecimal(3).doubleValue()); // 1-Qty - KeyNamePair pp = new KeyNamePair(rs.getInt(6), rs.getString(7)); - line.add(pp); // 2-UOM - pp = new KeyNamePair(rs.getInt(4), rs.getString(5)); - line.add(pp); // 3-Product - line.add(null); //4-Vendor Product No - line.add(null); //5-Order - pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); - line.add(pp); //6-RMA - line.add(null); //7-invoice - data.add(line); - } - rs.close(); - } - catch (Exception ex) - { - log.log(Level.SEVERE, sqlStmt.toString(), ex); - } - finally - { - if (pstmt != null) - { - try - { - pstmt.close(); - } - catch (Exception ex) - { - log.severe("Could not close prepared statement"); - } - } - } - loadTableOIS(data); - } - - /** - * List number of rows selected - */ - protected void info() { - ListModelTable 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() { - log.config(""); - ListModelTable model = dataTable.getModel(); - int rows = model.getRowCount(); - if (rows == 0) - return false; - // - Integer loc = locatorField.getM_Locator_ID(); - if (loc == null || loc.intValue() == 0) { - Popup popup = new Popup(); - Label label = new Label(Msg.getMsg(Env.getCtx(), "FillMandatory") + locatorLabel.getValue()); - popup.appendChild(label); - popup.setPage(locatorField.getComponent().getPage()); - popup.open(locatorField.getComponent()); - return false; - } - int M_Locator_ID = loc.intValue(); - // Get Shipment - int M_InOut_ID = ((Integer) p_mTab.getValue("M_InOut_ID")).intValue(); - MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, null); - log.config(inout + ", C_Locator_ID=" + M_Locator_ID); - - // Lines - for (int i = 0; i < rows; i++) { - if (((Boolean) model.getValueAt(i, 0)).booleanValue()) { - // variable values - Double d = (Double) model.getValueAt(i, 1); // 1-Qty - BigDecimal QtyEntered = new BigDecimal(d.doubleValue()); - KeyNamePair pp = (KeyNamePair) model.getValueAt(i, 2); // 2-UOM - int C_UOM_ID = pp.getKey(); - pp = (KeyNamePair) model.getValueAt(i, 3); // 3-Product - int M_Product_ID = pp.getKey(); - int C_OrderLine_ID = 0; - pp = (KeyNamePair) model.getValueAt(i, 5); // 5-OrderLine - if (pp != null) - C_OrderLine_ID = pp.getKey(); - int M_RMALine_ID = 0; - pp = (KeyNamePair) model.getValueAt(i, 6); // 6-RMA - if (pp != null) - M_RMALine_ID = pp.getKey(); - int C_InvoiceLine_ID = 0; - MInvoiceLine il = null; - pp = (KeyNamePair) model.getValueAt(i, 7); // 7-InvoiceLine - if (pp != null) - C_InvoiceLine_ID = pp.getKey(); - if (C_InvoiceLine_ID != 0) - il = new MInvoiceLine (Env.getCtx(), C_InvoiceLine_ID, null); - boolean isInvoiced = (C_InvoiceLine_ID != 0); - // Precision of Qty UOM - int precision = 2; - if (M_Product_ID != 0) - { - MProduct product = MProduct.get(Env.getCtx(), M_Product_ID); - precision = product.getUOMPrecision(); - } - QtyEntered = QtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN); - // - log.fine("Line QtyEntered=" + QtyEntered - + ", Product=" + M_Product_ID - + ", OrderLine=" + C_OrderLine_ID + ", InvoiceLine=" + C_InvoiceLine_ID); - - // Credit Memo - negative Qty - if (m_invoice != null && m_invoice.isCreditMemo() ) - QtyEntered = QtyEntered.negate(); - - // Create new InOut Line - MInOutLine iol = new MInOutLine (inout); - iol.setM_Product_ID(M_Product_ID, C_UOM_ID); // Line UOM - iol.setQty(QtyEntered); // Movement/Entered - // - MOrderLine ol = null; - MRMALine rmal = null; - if (C_OrderLine_ID != 0) - { - iol.setC_OrderLine_ID(C_OrderLine_ID); - ol = new MOrderLine (Env.getCtx(), C_OrderLine_ID, null); - // iol.setOrderLine(ol, M_Locator_ID, QtyEntered); - if (ol.getQtyEntered().compareTo(ol.getQtyOrdered()) != 0) - { - iol.setMovementQty(QtyEntered - .multiply(ol.getQtyOrdered()) - .divide(ol.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); - iol.setC_UOM_ID(ol.getC_UOM_ID()); - } - iol.setM_AttributeSetInstance_ID(ol.getM_AttributeSetInstance_ID()); - iol.setDescription(ol.getDescription()); - // - iol.setC_Project_ID(ol.getC_Project_ID()); - iol.setC_ProjectPhase_ID(ol.getC_ProjectPhase_ID()); - iol.setC_ProjectTask_ID(ol.getC_ProjectTask_ID()); - iol.setC_Activity_ID(ol.getC_Activity_ID()); - iol.setC_Campaign_ID(ol.getC_Campaign_ID()); - iol.setAD_OrgTrx_ID(ol.getAD_OrgTrx_ID()); - iol.setUser1_ID(ol.getUser1_ID()); - iol.setUser2_ID(ol.getUser2_ID()); - } - else if (il != null) - { - // iol.setInvoiceLine(il, M_Locator_ID, QtyEntered); - if (il.getQtyEntered().compareTo(il.getQtyInvoiced()) != 0) - { - iol.setQtyEntered(QtyEntered - .multiply(il.getQtyInvoiced()) - .divide(il.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); - iol.setC_UOM_ID(il.getC_UOM_ID()); - } - iol.setDescription(il.getDescription()); - iol.setC_Project_ID(il.getC_Project_ID()); - iol.setC_ProjectPhase_ID(il.getC_ProjectPhase_ID()); - iol.setC_ProjectTask_ID(il.getC_ProjectTask_ID()); - iol.setC_Activity_ID(il.getC_Activity_ID()); - iol.setC_Campaign_ID(il.getC_Campaign_ID()); - iol.setAD_OrgTrx_ID(il.getAD_OrgTrx_ID()); - iol.setUser1_ID(il.getUser1_ID()); - iol.setUser2_ID(il.getUser2_ID()); - } - else if (M_RMALine_ID != 0) - { - rmal = new MRMALine(Env.getCtx(), M_RMALine_ID, null); - iol.setM_RMALine_ID(M_RMALine_ID); - iol.setQtyEntered(QtyEntered); - iol.setDescription(rmal.getDescription()); - iol.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID()); - iol.setC_Project_ID(rmal.getC_Project_ID()); - iol.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID()); - iol.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID()); - iol.setC_Activity_ID(rmal.getC_Activity_ID()); - iol.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID()); - iol.setUser1_ID(rmal.getUser1_ID()); - iol.setUser2_ID(rmal.getUser2_ID()); - } - - // Charge - if (M_Product_ID == 0) - { - if (ol != null && ol.getC_Charge_ID() != 0) // from order - iol.setC_Charge_ID(ol.getC_Charge_ID()); - else if (il != null && il.getC_Charge_ID() != 0) // from invoice - iol.setC_Charge_ID(il.getC_Charge_ID()); - else if (rmal != null && rmal.getC_Charge_ID() != 0) // from rma - iol.setC_Charge_ID(rmal.getC_Charge_ID()); - } - // - iol.setM_Locator_ID(M_Locator_ID); - if (!iol.save()) - log.log(Level.SEVERE, "Line NOT created #" + i); - // Create Invoice Line Link - else if (il != null) - { - il.setM_InOutLine_ID(iol.getM_InOutLine_ID()); - il.save(); - } - } // if selected - } // for all rows - - /** - * Update Header - * - if linked to another order/invoice/rma - remove link - * - if no link set it - */ - if (p_order != null && p_order.getC_Order_ID() != 0) - { - inout.setC_Order_ID (p_order.getC_Order_ID()); - inout.setAD_OrgTrx_ID(p_order.getAD_OrgTrx_ID()); - inout.setC_Project_ID(p_order.getC_Project_ID()); - inout.setC_Campaign_ID(p_order.getC_Campaign_ID()); - inout.setC_Activity_ID(p_order.getC_Activity_ID()); - inout.setUser1_ID(p_order.getUser1_ID()); - inout.setUser2_ID(p_order.getUser2_ID()); - } - if (m_invoice != null && m_invoice.getC_Invoice_ID() != 0) - { - if (inout.getC_Order_ID() == 0) - inout.setC_Order_ID (m_invoice.getC_Order_ID()); - inout.setC_Invoice_ID (m_invoice.getC_Invoice_ID()); - inout.setAD_OrgTrx_ID(m_invoice.getAD_OrgTrx_ID()); - inout.setC_Project_ID(m_invoice.getC_Project_ID()); - inout.setC_Campaign_ID(m_invoice.getC_Campaign_ID()); - inout.setC_Activity_ID(m_invoice.getC_Activity_ID()); - inout.setUser1_ID(m_invoice.getUser1_ID()); - inout.setUser2_ID(m_invoice.getUser2_ID()); - } - if (m_rma != null && m_rma.getM_RMA_ID() != 0) - { - MInOut originalIO = m_rma.getShipment(); - inout.setIsSOTrx(m_rma.isSOTrx()); - inout.setC_Order_ID(0); - inout.setC_Invoice_ID(0); - inout.setM_RMA_ID(m_rma.getM_RMA_ID()); - inout.setAD_OrgTrx_ID(originalIO.getAD_OrgTrx_ID()); - inout.setC_Project_ID(originalIO.getC_Project_ID()); - inout.setC_Campaign_ID(originalIO.getC_Campaign_ID()); - inout.setC_Activity_ID(originalIO.getC_Activity_ID()); - inout.setUser1_ID(originalIO.getUser1_ID()); - inout.setUser2_ID(originalIO.getUser2_ID()); - } - inout.save(); - return true; - } // save - -} // VCreateFromShipment