From 079d5b2cbcb18307313cf182215dcf3276e4a512 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 11 May 2009 02:38:55 +0000 Subject: [PATCH] Improved CreateFrom codes for both SwingUI and WebUI --- client/src/org/compiere/apps/APanel.java | 18 +- client/src/org/compiere/grid/CreateFrom.java | 285 ++++++++++ .../org/compiere/grid/CreateFromInvoice.java | 487 ++++++++++++++++++ client/src/org/compiere/grid/ICreateFrom.java | 10 + client/src/org/compiere/grid/VCreateFrom.java | 12 +- .../org/compiere/grid/VCreateFromDialog.java | 185 +++++++ .../org/compiere/grid/VCreateFromFactory.java | 76 +++ .../compiere/grid/VCreateFromInvoiceUI.java | 372 +++++++++++++ .../src/org/compiere/minigrid/IMiniTable.java | 52 ++ .../src/org/compiere/minigrid/MiniTable.java | 6 +- .../webui/apps/form/WCreateFrom.java | 12 +- .../webui/apps/form/WCreateFromFactory.java | 80 +++ .../webui/apps/form/WCreateFromInvoice.java | 2 +- .../webui/apps/form/WCreateFromInvoiceUI.java | 369 +++++++++++++ .../webui/apps/form/WCreateFromRMA.java | 2 +- .../webui/apps/form/WCreateFromShipment.java | 2 +- .../webui/apps/form/WCreateFromStatement.java | 2 +- .../webui/apps/form/WCreateFromWindow.java | 198 +++++++ .../adempiere/webui/component/WListbox.java | 3 +- .../webui/panel/AbstractADWindowPanel.java | 12 +- 20 files changed, 2160 insertions(+), 25 deletions(-) create mode 100644 client/src/org/compiere/grid/CreateFrom.java create mode 100644 client/src/org/compiere/grid/CreateFromInvoice.java create mode 100644 client/src/org/compiere/grid/ICreateFrom.java create mode 100644 client/src/org/compiere/grid/VCreateFromDialog.java create mode 100644 client/src/org/compiere/grid/VCreateFromFactory.java create mode 100644 client/src/org/compiere/grid/VCreateFromInvoiceUI.java create mode 100644 client/src/org/compiere/minigrid/IMiniTable.java create mode 100644 zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java create mode 100644 zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoiceUI.java create mode 100644 zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromWindow.java diff --git a/client/src/org/compiere/apps/APanel.java b/client/src/org/compiere/apps/APanel.java index 3bc0d49a5f..d360580f1b 100644 --- a/client/src/org/compiere/apps/APanel.java +++ b/client/src/org/compiere/apps/APanel.java @@ -62,8 +62,9 @@ import org.compiere.apps.search.Find; import org.compiere.grid.APanelTab; import org.compiere.grid.GridController; import org.compiere.grid.GridSynchronizer; +import org.compiere.grid.ICreateFrom; import org.compiere.grid.RecordAccessDialog; -import org.compiere.grid.VCreateFrom; +import org.compiere.grid.VCreateFromFactory; import org.compiere.grid.VOnlyCurrentDays; import org.compiere.grid.VPayment; import org.compiere.grid.VSortTab; @@ -2350,20 +2351,19 @@ public final class APanel extends CPanel // Run form only if the button has no process defined - teo_sarca [ 1974354 ] if (vButton.getProcess_ID() <= 0) { - // m_curWindowNo - VCreateFrom vcf = VCreateFrom.create (m_curTab); - if (vcf != null) + ICreateFrom cf = VCreateFromFactory.create(m_curTab); + if(cf != null) { - if (vcf.isInitOK()) + if(cf.isInitOK()) { - vcf.setVisible(true); - vcf.dispose(); + cf.showWindow(); + cf.closeWindow(); m_curTab.dataRefresh(); } else - vcf.dispose(); + cf.closeWindow(); return; - } + } // else may start process } } // CreateFrom diff --git a/client/src/org/compiere/grid/CreateFrom.java b/client/src/org/compiere/grid/CreateFrom.java new file mode 100644 index 0000000000..ecaf032d8d --- /dev/null +++ b/client/src/org/compiere/grid/CreateFrom.java @@ -0,0 +1,285 @@ +package org.compiere.grid; + +import java.math.BigDecimal; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Vector; +import java.util.logging.Level; + +import org.compiere.minigrid.IMiniTable; +import org.compiere.model.GridTab; +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; + +public abstract class CreateFrom implements ICreateFrom +{ + /** Logger */ + protected CLogger log = CLogger.getCLogger(getClass()); + + /** Loaded Order */ + protected MOrder p_order = null; + + private GridTab gridTab; + + private String title; + + private boolean initOK = false; + + public CreateFrom(GridTab gridTab) { + this.gridTab = gridTab; + } + + public abstract boolean dynInit() throws Exception; + + public abstract void info(); + + public abstract boolean save(IMiniTable miniTable, String trxName); + + /** + * Init OK to be able to make changes? + * @return on if initialized + */ + public boolean isInitOK() + { + return initOK; + } + + public void setInitOK(boolean initOK) + { + this.initOK = initOK; + } + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID BPartner + * @param forInvoice for invoice + */ + protected ArrayList loadOrderData (int C_BPartner_ID, boolean forInvoice, boolean sameWarehouseOnly) + { + ArrayList list = new ArrayList(); + + // 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()) + { + list.add(new KeyNamePair(rs.getInt(1), rs.getString(2))); + } + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql.toString(), e); + } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } + + 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 + * @param forInvoice true if for invoice vs. delivery qty + */ + protected Vector> getOrderData (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; + } + + 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() + { + + } + + public void closeWindow() + { + + } + + public GridTab getGridTab() + { + return gridTab; + } + + /** + * Get Warehouse from window's context + * @return warehouse id + */ + public int getM_Warehouse_ID() + { + return Env.getContextAsInt(Env.getCtx(), gridTab.getWindowNo(), "M_Warehouse_ID"); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/client/src/org/compiere/grid/CreateFromInvoice.java b/client/src/org/compiere/grid/CreateFromInvoice.java new file mode 100644 index 0000000000..9c2acf0172 --- /dev/null +++ b/client/src/org/compiere/grid/CreateFromInvoice.java @@ -0,0 +1,487 @@ +package org.compiere.grid; + +import java.math.BigDecimal; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Vector; +import java.util.logging.Level; + +import org.compiere.minigrid.IMiniTable; +import org.compiere.model.GridTab; +import org.compiere.model.MInOut; +import org.compiere.model.MInOutLine; +import org.compiere.model.MInvoice; +import org.compiere.model.MInvoiceLine; +import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; +import org.compiere.model.MProduct; +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; + +/** + * Create Invoice Transactions from PO Orders or Receipt + * + * @author Jorg Janke + * @version $Id: VCreateFromInvoice.java,v 1.4 2006/07/30 00:51:28 jjanke Exp $ + * + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + *
  • BF [ 1896947 ] Generate invoice from Order error + *
  • BF [ 2007837 ] VCreateFrom.save() should run in trx + */ +public class CreateFromInvoice extends CreateFrom +{ + /** + * Protected Constructor + * @param mTab MTab + */ + public CreateFromInvoice(GridTab mTab) + { + super(mTab); + log.info(mTab.toString()); + } // VCreateFromInvoice + + /** + * Dynamic Init + * @return true if initialized + */ + public boolean dynInit() throws Exception + { + log.config(""); + setTitle(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false) + " .. " + Msg.translate(Env.getCtx(), "CreateFrom")); + + return true; + } // dynInit + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID + */ + protected ArrayList loadShipmentData (int C_BPartner_ID) + { + ArrayList list = new ArrayList(); + + // Display + StringBuffer display = new StringBuffer("s.DocumentNo||' - '||") + .append(DB.TO_CHAR("s.MovementDate", DisplayType.Date, Env.getAD_Language(Env.getCtx()))); + // + StringBuffer sql = new StringBuffer("SELECT s.M_InOut_ID,").append(display) + .append(" FROM M_InOut s " + + "WHERE s.C_BPartner_ID=? AND s.IsSOTrx='N' AND s.DocStatus IN ('CL','CO')" + + " AND s.M_InOut_ID IN " + + "(SELECT sl.M_InOut_ID FROM M_InOutLine sl" + + " LEFT OUTER JOIN M_MatchInv mi ON (sl.M_InOutLine_ID=mi.M_InOutLine_ID) " + + " JOIN M_InOut s2 ON (sl.M_InOut_ID=s2.M_InOut_ID) " + + " WHERE s2.C_BPartner_ID=? AND s2.IsSOTrx='N' AND s2.DocStatus IN ('CL','CO') " + + "GROUP BY sl.M_InOut_ID,mi.M_InOutLine_ID,sl.MovementQty " + + "HAVING (sl.MovementQty<>SUM(mi.Qty) AND mi.M_InOutLine_ID IS NOT NULL)" + + " OR mi.M_InOutLine_ID IS NULL) " + + "ORDER BY s.MovementDate"); + try + { + PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt.setInt(1, C_BPartner_ID); + pstmt.setInt(2, C_BPartner_ID); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + { + list.add(new KeyNamePair(rs.getInt(1), rs.getString(2))); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql.toString(), e); + } + + return list; + } + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID BPartner + */ + protected ArrayList loadRMAData(int C_BPartner_ID) { + ArrayList list = new ArrayList(); + + String sqlStmt = "SELECT r.M_RMA_ID, r.DocumentNo || '-' || r.Amt from M_RMA r " + + "WHERE ISSOTRX='N' AND r.DocStatus in ('CO', 'CL') " + + "AND r.C_BPartner_ID=? " + + "AND NOT EXISTS (SELECT * FROM C_Invoice inv " + + "WHERE inv.M_RMA_ID=r.M_RMA_ID AND inv.DocStatus IN ('CO', 'CL'))"; + + PreparedStatement pstmt = null; + try { + pstmt = DB.prepareStatement(sqlStmt, null); + pstmt.setInt(1, C_BPartner_ID); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + list.add(new KeyNamePair(rs.getInt(1), rs.getString(2))); + } + rs.close(); + } catch (SQLException e) { + log.log(Level.SEVERE, sqlStmt.toString(), e); + } finally { + if (pstmt != null) { + try { + pstmt.close(); + } catch (Exception ex) { + log.severe("Could not close prepared statement"); + } + } + } + + return list; + } + + /** + * Load Data - Shipment not invoiced + * @param M_InOut_ID InOut + */ + protected Vector> getShipmentData(int M_InOut_ID) + { + log.config("M_InOut_ID=" + M_InOut_ID); + MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, null); + p_order = null; + if (inout.getC_Order_ID() != 0) + p_order = new MOrder (Env.getCtx(), inout.getC_Order_ID(), null); + + // + Vector> data = new Vector>(); + StringBuffer sql = new StringBuffer("SELECT " // QtyEntered + + "l.MovementQty-SUM(NVL(mi.Qty, 0)), l.QtyEntered/l.MovementQty," + + " l.C_UOM_ID, COALESCE(uom.UOMSymbol, uom.Name)," // 3..4 + + " l.M_Product_ID, p.Name, po.VendorProductNo, l.M_InOutLine_ID, l.Line," // 5..9 + + " l.C_OrderLine_ID " // 10 + + " FROM M_InOutLine l " + ); + 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 M_InOut io ON (l.M_InOut_ID=io.M_InOut_ID)") + .append(" LEFT OUTER JOIN M_Product_PO po ON (l.M_Product_ID = po.M_Product_ID AND io.C_BPartner_ID = po.C_BPartner_ID)") + .append(" LEFT OUTER JOIN M_MatchInv mi ON (l.M_InOutLine_ID=mi.M_InOutLine_ID)") + + .append(" WHERE l.M_InOut_ID=? AND l.MovementQty<>0 ") + .append("GROUP BY l.MovementQty, l.QtyEntered/l.MovementQty, " + + "l.C_UOM_ID, COALESCE(uom.UOMSymbol, uom.Name), " + + "l.M_Product_ID, p.Name, po.VendorProductNo, l.M_InOutLine_ID, l.Line, l.C_OrderLine_ID ") + .append("ORDER BY l.Line"); + + try + { + PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt.setInt(1, M_InOut_ID); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + { + Vector line = new Vector(7); + line.add(new Boolean(false)); // 0-Selection + BigDecimal qtyMovement = rs.getBigDecimal(1); + BigDecimal multiplier = rs.getBigDecimal(2); + BigDecimal qtyEntered = qtyMovement.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 + int C_OrderLine_ID = rs.getInt(10); + if (rs.wasNull()) + line.add(null); // 5-Order + else + line.add(new KeyNamePair(C_OrderLine_ID,".")); + pp = new KeyNamePair(rs.getInt(8), rs.getString(9)); + line.add(pp); // 6-Ship + line.add(null); // 7-RMA + data.add(line); + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql.toString(), e); + } + + return data; + } // loadShipment + + /** + * Load RMA details + * @param M_RMA_ID RMA + */ + protected Vector> getRMAData(int M_RMA_ID) + { + p_order = null; + +// MRMA m_rma = new MRMA(Env.getCtx(), M_RMA_ID, null); + + Vector> data = new Vector>(); + StringBuffer sqlStmt = new StringBuffer(); + sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - rl.QtyDelivered, iol.M_Product_ID, p.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) "); + sqlStmt.append("FROM M_RMALine rl INNER JOIN M_InOutLine iol ON rl.M_InOutLine_ID=iol.M_InOutLine_ID "); + + if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) + { + sqlStmt.append("LEFT OUTER JOIN C_UOM uom ON (uom.C_UOM_ID=iol.C_UOM_ID) "); + } + else + { + sqlStmt.append("LEFT OUTER JOIN C_UOM_Trl uom ON (uom.C_UOM_ID=iol.C_UOM_ID AND uom.AD_Language='"); + sqlStmt.append(Env.getAD_Language(Env.getCtx())).append("') "); + } + sqlStmt.append("LEFT OUTER JOIN M_Product p ON p.M_Product_ID=iol.M_Product_ID "); + sqlStmt.append("WHERE rl.M_RMA_ID=? "); + sqlStmt.append("AND rl.M_INOUTLINE_ID IS NOT NULL"); + + sqlStmt.append(" UNION "); + + sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - rl.QtyDelivered, 0, c.Name, uom.C_UOM_ID, COALESCE(uom.UOMSymbol,uom.Name) "); + sqlStmt.append("FROM M_RMALine rl INNER JOIN C_Charge c ON c.C_Charge_ID = rl.C_Charge_ID "); + if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) + { + sqlStmt.append("LEFT OUTER JOIN C_UOM uom ON (uom.C_UOM_ID=100) "); + } + else + { + sqlStmt.append("LEFT OUTER JOIN C_UOM_Trl uom ON (uom.C_UOM_ID=100 AND uom.AD_Language='"); + sqlStmt.append(Env.getAD_Language(Env.getCtx())).append("') "); + } + sqlStmt.append("WHERE rl.M_RMA_ID=? "); + sqlStmt.append("AND rl.C_Charge_ID IS NOT NULL"); + + PreparedStatement pstmt = null; + ResultSet rs = null; + try + { + pstmt = DB.prepareStatement(sqlStmt.toString(), null); + pstmt.setInt(1, M_RMA_ID); + pstmt.setInt(2, M_RMA_ID); + rs = pstmt.executeQuery(); + + while (rs.next()) + { + Vector line = new Vector(7); + line.add(new Boolean(false)); // 0-Selection + line.add(rs.getBigDecimal(3)); // 1-Qty + KeyNamePair pp = new KeyNamePair(rs.getInt(6), rs.getString(7)); + line.add(pp); // 2-UOM + 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(null); //6-Ship + line.add(pp); //7-RMA + data.add(line); + } + rs.close(); + } + catch (Exception ex) + { + log.log(Level.SEVERE, sqlStmt.toString(), ex); + } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } + + return data; + } + + /** + * List number of rows selected + */ + public void info() + { + + } // infoInvoice + + protected void configureMiniTable (IMiniTable miniTable) + { + miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection + miniTable.setColumnClass(1, BigDecimal.class, true); // 1-Qty + miniTable.setColumnClass(2, String.class, true); // 2-UOM + miniTable.setColumnClass(3, String.class, true); // 3-Product + miniTable.setColumnClass(4, String.class, true); // 4-VendorProductNo + miniTable.setColumnClass(5, String.class, true); // 5-Order + miniTable.setColumnClass(6, String.class, true); // 6-Ship + miniTable.setColumnClass(7, String.class, true); // 7-Invoice + // Table UI + miniTable.autoSize(); + } + + /** + * Save - Create Invoice Lines + * @return true if saved + */ + public boolean save(IMiniTable miniTable, String trxName) + { + // Invoice + int C_Invoice_ID = ((Integer)getGridTab().getValue("C_Invoice_ID")).intValue(); + MInvoice invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, trxName); + log.config(invoice.toString()); + + if (p_order != null) + { + invoice.setOrder(p_order); // overwrite header values + invoice.saveEx(); + } + + MInOut inout = null; +// if (m_M_InOut_ID > 0) +// { +// inout = new MInOut(Env.getCtx(), m_M_InOut_ID, trxName); +// } + if (inout != null && inout.getM_InOut_ID() != 0 + && inout.getC_Invoice_ID() == 0) // only first time + { + inout.setC_Invoice_ID(C_Invoice_ID); + inout.saveEx(); + } + + // Lines + for (int i = 0; i < miniTable.getRowCount(); i++) + { + if (((Boolean)miniTable.getValueAt(i, 0)).booleanValue()) + { + // variable values + BigDecimal QtyEntered = (BigDecimal)miniTable.getValueAt(i, 1); // 1-Qty + + KeyNamePair pp = (KeyNamePair)miniTable.getValueAt(i, 2); // 2-UOM + int C_UOM_ID = pp.getKey(); + // + pp = (KeyNamePair)miniTable.getValueAt(i, 3); // 3-Product + int M_Product_ID = 0; + if (pp != null) + M_Product_ID = pp.getKey(); + // + int C_OrderLine_ID = 0; + pp = (KeyNamePair)miniTable.getValueAt(i, 5); // 5-OrderLine + if (pp != null) + C_OrderLine_ID = pp.getKey(); + int M_InOutLine_ID = 0; + pp = (KeyNamePair)miniTable.getValueAt(i, 6); // 6-Shipment + if (pp != null) + M_InOutLine_ID = pp.getKey(); + // 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_ID=" + M_Product_ID + + ", OrderLine_ID=" + C_OrderLine_ID + ", InOutLine_ID=" + M_InOutLine_ID); + + // Create new Invoice Line + MInvoiceLine invoiceLine = new MInvoiceLine (invoice); + invoiceLine.setM_Product_ID(M_Product_ID, C_UOM_ID); // Line UOM + invoiceLine.setQty(QtyEntered); // Invoiced/Entered + + // Info + MOrderLine orderLine = null; + if (C_OrderLine_ID != 0) + orderLine = new MOrderLine (Env.getCtx(), C_OrderLine_ID, trxName); + MInOutLine inoutLine = null; + if (M_InOutLine_ID != 0) + { + inoutLine = new MInOutLine (Env.getCtx(), M_InOutLine_ID, trxName); + if (orderLine == null && inoutLine.getC_OrderLine_ID() != 0) + { + C_OrderLine_ID = inoutLine.getC_OrderLine_ID(); + orderLine = new MOrderLine (Env.getCtx(), C_OrderLine_ID, trxName); + } + } + else + { + String whereClause = "EXISTS (SELECT 1 FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('CO','CL'))"; + MInOutLine[] lines = MInOutLine.getOfOrderLine(Env.getCtx(), + C_OrderLine_ID, whereClause, trxName); + log.fine ("Receipt Lines with OrderLine = #" + lines.length); + if (lines.length > 0) + { + for (int j = 0; j < lines.length; j++) + { + MInOutLine line = lines[j]; + if (line.getQtyEntered().compareTo(QtyEntered) == 0) + { + inoutLine = line; + M_InOutLine_ID = inoutLine.getM_InOutLine_ID(); + break; + } + } + if (inoutLine == null) + { + inoutLine = lines[0]; // first as default + M_InOutLine_ID = inoutLine.getM_InOutLine_ID(); + } + } + } // get Ship info + + // Shipment Info + if (inoutLine != null) + { + invoiceLine.setShipLine(inoutLine); // overwrites + if (inoutLine.sameOrderLineUOM()) + invoiceLine.setQtyInvoiced(QtyEntered); + else + invoiceLine.setQtyInvoiced(inoutLine.getMovementQty()); + } + else { + log.fine("No Receipt Line"); + // Order Info + if (orderLine != null) + { + invoiceLine.setOrderLine(orderLine); // overwrites + if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) + invoiceLine.setQtyInvoiced(QtyEntered + .multiply(orderLine.getQtyOrdered()) + .divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); + } + else + { + log.fine("No Order Line"); + invoiceLine.setPrice(); + invoiceLine.setTax(); + } + } + invoiceLine.saveEx(); + } // if selected + } // for all rows + + return true; + } // saveInvoice + + @Override + 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(), "M_RMA_ID", false)); + + return columnNames; + } + +} diff --git a/client/src/org/compiere/grid/ICreateFrom.java b/client/src/org/compiere/grid/ICreateFrom.java new file mode 100644 index 0000000000..22d624d8ac --- /dev/null +++ b/client/src/org/compiere/grid/ICreateFrom.java @@ -0,0 +1,10 @@ +package org.compiere.grid; + +public interface ICreateFrom +{ + public boolean isInitOK(); + + public void showWindow(); + + public void closeWindow(); +} diff --git a/client/src/org/compiere/grid/VCreateFrom.java b/client/src/org/compiere/grid/VCreateFrom.java index cca4d4dbb3..d4defde334 100644 --- a/client/src/org/compiere/grid/VCreateFrom.java +++ b/client/src/org/compiere/grid/VCreateFrom.java @@ -92,7 +92,7 @@ import org.compiere.util.TrxRunnable; *
  • Bug [ 1759431 ] Problems with VCreateFrom */ public abstract class VCreateFrom extends CDialog - implements ActionListener, TableModelListener + implements ICreateFrom, ActionListener, TableModelListener { /** * @@ -779,4 +779,14 @@ public abstract class VCreateFrom extends CDialog // confirmPanel.getOKButton().setEnabled(selectedRowCount > 0); } + + public void showWindow() + { + setVisible(true); + } + + public void closeWindow() + { + dispose(); + } } // VCreateFrom diff --git a/client/src/org/compiere/grid/VCreateFromDialog.java b/client/src/org/compiere/grid/VCreateFromDialog.java new file mode 100644 index 0000000000..a8b966ce03 --- /dev/null +++ b/client/src/org/compiere/grid/VCreateFromDialog.java @@ -0,0 +1,185 @@ +package org.compiere.grid; + +import java.awt.BorderLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; + +import javax.swing.JScrollPane; +import javax.swing.KeyStroke; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.table.TableModel; + +import org.compiere.apps.ADialog; +import org.compiere.apps.AppsAction; +import org.compiere.apps.ConfirmPanel; +import org.compiere.apps.StatusBar; +import org.compiere.minigrid.MiniTable; +import org.compiere.swing.CButton; +import org.compiere.swing.CDialog; +import org.compiere.swing.CPanel; +import org.compiere.util.Env; +import org.compiere.util.Trx; +import org.compiere.util.TrxRunnable; + +public class VCreateFromDialog extends CDialog implements ActionListener, TableModelListener +{ + private static final long serialVersionUID = 1L; + + private CreateFrom createFrom; + private int windowNo; + + private CPanel parameterPanel = new CPanel(); + private ConfirmPanel confirmPanel = new ConfirmPanel(true); + private StatusBar statusBar = new StatusBar(); + private MiniTable dataTable = new MiniTable(); + + private static final String SELECT_ALL = "SelectAll"; + + public VCreateFromDialog(CreateFrom createFrom, int windowNo, boolean modal) + { + super(Env.getWindow(windowNo), modal); + + this.createFrom = createFrom; + this.windowNo = windowNo; + + try + { + jbInit(); + confirmPanel.addActionListener(this); + + statusBar.setStatusDB(""); + tableChanged(null); + createFrom.setInitOK(true); + } + catch(Exception e) + { + createFrom.setInitOK(false); + } + } + + protected void jbInit() throws Exception + { + getContentPane().add(parameterPanel, BorderLayout.NORTH); + + JScrollPane dataPane = new JScrollPane(); + getContentPane().add(dataPane, BorderLayout.CENTER); + dataPane.getViewport().add(dataTable, null); + + 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); + confirmPanel.addButton(selectAllButton); + + CPanel southPanel = new CPanel(); + getContentPane().add(southPanel, BorderLayout.SOUTH); + BorderLayout southLayout = new BorderLayout(); + southPanel.setLayout(southLayout); + southPanel.add(confirmPanel, BorderLayout.CENTER); + southPanel.add(statusBar, BorderLayout.SOUTH); + } + + public void actionPerformed(ActionEvent e) + { + 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(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(); + } + } + + public boolean save(String trxName) + { + dataTable.stopEditor(true); + + TableModel model = dataTable.getModel(); + int rows = model.getRowCount(); + if (rows == 0) + return false; + + return createFrom.save(dataTable, trxName); + } + + public void tableChanged (TableModelEvent e) + { + int type = -1; + if (e != null) + { + type = e.getType(); + if (type != TableModelEvent.UPDATE) + return; + } + info(); + dataTable.repaint(); + } + + public void info() + { + TableModel model = dataTable.getModel(); + int rows = model.getRowCount(); + int count = 0; + for (int i = 0; i < rows; i++) + { + if (((Boolean)model.getValueAt(i, 0)).booleanValue()) + count++; + } + setStatusLine(count, null); + } + + 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 MiniTable getMiniTable() + { + return dataTable; + } + + public CPanel getParameterPanel() + { + return parameterPanel; + } +} \ No newline at end of file diff --git a/client/src/org/compiere/grid/VCreateFromFactory.java b/client/src/org/compiere/grid/VCreateFromFactory.java new file mode 100644 index 0000000000..732740ef57 --- /dev/null +++ b/client/src/org/compiere/grid/VCreateFromFactory.java @@ -0,0 +1,76 @@ +package org.compiere.grid; + +import java.util.HashMap; +import java.util.logging.Level; + +import org.compiere.model.GridTab; +import org.compiere.model.I_C_BankStatement; +import org.compiere.model.I_C_Invoice; +import org.compiere.model.I_M_InOut; +import org.compiere.model.I_M_RMA; +import org.compiere.util.CLogger; +import org.compiere.util.Env; + +public class VCreateFromFactory +{ + /** Static Logger */ + private static CLogger s_log = CLogger.getCLogger (VCreateFromFactory.class); + + /** Registered classes map (AD_Table_ID -> Class) */ + private static HashMap> s_registeredClasses = null; + + /** + * 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); + } + + static + { + // Register defaults: + s_registeredClasses = new HashMap>(); + s_registeredClasses.put(I_C_Invoice.Table_ID, VCreateFromInvoiceUI.class); + + s_registeredClasses.put(I_C_BankStatement.Table_ID, VCreateFromStatement.class); + s_registeredClasses.put(I_M_InOut.Table_ID, VCreateFromShipment.class); + 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 ICreateFrom create (GridTab mTab) + { + // dynamic init preparation + int AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), "BaseTable_ID"); + + ICreateFrom 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 +} \ No newline at end of file diff --git a/client/src/org/compiere/grid/VCreateFromInvoiceUI.java b/client/src/org/compiere/grid/VCreateFromInvoiceUI.java new file mode 100644 index 0000000000..36f23f2122 --- /dev/null +++ b/client/src/org/compiere/grid/VCreateFromInvoiceUI.java @@ -0,0 +1,372 @@ +package org.compiere.grid; + +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.VetoableChangeListener; +import java.util.ArrayList; +import java.util.Vector; +import java.util.logging.Level; + +import javax.swing.JComboBox; +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.MDocType; +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.KeyNamePair; +import org.compiere.util.Msg; + +public class VCreateFromInvoiceUI extends CreateFromInvoice implements ActionListener, VetoableChangeListener +{ + private static final long serialVersionUID = 1L; + + private VCreateFromDialog dialog; + + public VCreateFromInvoiceUI(GridTab mTab) + { + super(mTab); + log.info(getGridTab().toString()); + + dialog = new VCreateFromDialog(this, getGridTab().getWindowNo(), true); + + p_WindowNo = getGridTab().getWindowNo(); + + try + { + if (!dynInit()) + return; + jbInit(); + + setInitOK(true); + } + catch(Exception e) + { + log.log(Level.SEVERE, "", e); + setInitOK(false); + } + AEnv.positionCenterWindow(Env.getWindow(p_WindowNo), dialog); + } // VCreateFrom + + /** Window No */ + private int p_WindowNo; + + /** Logger */ + private CLogger log = CLogger.getCLogger(getClass()); + + // + private JLabel bPartnerLabel = new JLabel(); + private VLookup bPartnerField; + + private JLabel orderLabel = new JLabel(); + private JComboBox orderField = new JComboBox(); + + private JLabel shipmentLabel = new JLabel(); + private JComboBox shipmentField = new JComboBox(); + + /** Label for the rma selection */ + private JLabel rmaLabel = new JLabel(); + /** Combo box for selecting RMA document */ + private JComboBox rmaField = new JComboBox(); + + /** + * 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()); + + // RMA Selection option should only be available for AP Credit Memo + Integer docTypeId = (Integer)getGridTab().getValue("C_DocTypeTarget_ID"); + MDocType docType = MDocType.get(Env.getCtx(), docTypeId); + if (!MDocType.DOCBASETYPE_APCreditMemo.equals(docType.getDocBaseType())) + { + rmaLabel.setVisible(false); + rmaField.setVisible(false); + } + + initBPartner(true); + bPartnerField.addVetoableChangeListener(this); + + return true; + } // dynInit + + /** + * Static Init. + *
    +	 *  parameterPanel
    +	 *      parameterBankPanel
    +	 *      parameterStdPanel
    +	 *          bPartner/order/invoice/shopment/licator Label/Field
    +	 *  dataPane
    +	 *  southPanel
    +	 *      confirmPanel
    +	 *      statusBar
    +	 *  
    + * @throws Exception + */ + private void jbInit() throws Exception + { + bPartnerLabel.setText(Msg.getElement(Env.getCtx(), "C_BPartner_ID")); + orderLabel.setText(Msg.getElement(Env.getCtx(), "C_Order_ID", false)); + shipmentLabel.setText(Msg.getElement(Env.getCtx(), "M_InOut_ID", false)); + rmaLabel.setText(Msg.translate(Env.getCtx(), "M_RMA_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)); + + 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(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)); + // 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)); + } // jbInit + + /*************************************************************************/ + + private boolean m_actionActive = false; + + /** + * Action Listener + * @param e event + */ + public void actionPerformed(ActionEvent e) + { + log.config("Action=" + e.getActionCommand()); + + if (m_actionActive) + return; + m_actionActive = true; + log.config("Action=" + e.getActionCommand()); + // Order + if (e.getSource().equals(orderField)) + { + KeyNamePair pp = (KeyNamePair)orderField.getSelectedItem(); + int C_Order_ID = 0; + if (pp != null) + C_Order_ID = pp.getKey(); + // set Invoice, RMA and Shipment to Null + rmaField.setSelectedIndex(-1); + shipmentField.setSelectedIndex(-1); + loadOrder(C_Order_ID, true); + } + // Shipment + else if (e.getSource().equals(shipmentField)) + { + KeyNamePair pp = (KeyNamePair)shipmentField.getSelectedItem(); + int M_InOut_ID = 0; + if (pp != null) + M_InOut_ID = pp.getKey(); + // set Order, RMA and Invoice to Null + orderField.setSelectedIndex(-1); + rmaField.setSelectedIndex(-1); + loadShipment(M_InOut_ID); + } + // RMA + else if (e.getSource().equals(rmaField)) + { + KeyNamePair pp = (KeyNamePair)rmaField.getSelectedItem(); + int M_RMA_ID = 0; + if (pp != null) + M_RMA_ID = pp.getKey(); + // set Order and Invoice to Null + orderField.setSelectedIndex(-1); + shipmentField.setSelectedIndex(-1); + loadRMA(M_RMA_ID); + } + m_actionActive = false; + } // actionPerformed + + /** + * Change Listener + * @param e event + */ + public void vetoableChange (PropertyChangeEvent e) + { + log.config(e.getPropertyName() + "=" + e.getNewValue()); + + // BPartner - load Order/Invoice/Shipment + if (e.getPropertyName().equals("C_BPartner_ID")) + { + int C_BPartner_ID = ((Integer)e.getNewValue()).intValue(); + initBPOrderDetails (C_BPartner_ID, true); + } + dialog.tableChanged(null); + } // vetoableChange + + /************************************************************************** + * Load BPartner Field + * @param forInvoice true if Invoices are to be created, false receipts + * @throws Exception if Lookups cannot be initialized + */ + protected void initBPartner (boolean forInvoice) throws Exception + { + // load BPartner + int AD_Column_ID = 3499; // C_Invoice.C_BPartner_ID + MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.Search); + bPartnerField = new VLookup ("C_BPartner_ID", true, false, true, lookup); + // + int C_BPartner_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BPartner_ID"); + bPartnerField.setValue(new Integer(C_BPartner_ID)); + + // initial loading + initBPOrderDetails(C_BPartner_ID, forInvoice); + } // initBPartner + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID BPartner + * @param forInvoice for invoice + */ + protected void initBPOrderDetails (int C_BPartner_ID, boolean forInvoice) + { + log.config("C_BPartner_ID=" + C_BPartner_ID); + KeyNamePair pp = new KeyNamePair(0,""); + // load PO Orders - Closed, Completed + orderField.removeActionListener(this); + orderField.removeAllItems(); + orderField.addItem(pp); + + ArrayList list = loadOrderData(C_BPartner_ID, forInvoice, false); + for(KeyNamePair knp : list) + orderField.addItem(knp); + + orderField.setSelectedIndex(0); + orderField.addActionListener(this); + dialog.pack(); + + initBPDetails(C_BPartner_ID); + } // initBPartnerOIS + + public void initBPDetails(int C_BPartner_ID) + { + initBPShipmentDetails(C_BPartner_ID); + initBPRMADetails(C_BPartner_ID); + } + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID + */ + private void initBPShipmentDetails(int C_BPartner_ID) + { + log.config("C_BPartner_ID" + C_BPartner_ID); + + // load Shipments (Receipts) - Completed, Closed + shipmentField.removeActionListener(this); + shipmentField.removeAllItems(); + // None + KeyNamePair pp = new KeyNamePair(0,""); + shipmentField.addItem(pp); + + ArrayList list = loadShipmentData(C_BPartner_ID); + for(KeyNamePair knp : list) + shipmentField.addItem(knp); + + shipmentField.setSelectedIndex(0); + shipmentField.addActionListener(this); + } + + /** + * Load RMA that are candidates for shipment + * @param C_BPartner_ID BPartner + */ + private void initBPRMADetails(int C_BPartner_ID) + { + rmaField.removeActionListener(this); + rmaField.removeAllItems(); + // None + KeyNamePair pp = new KeyNamePair(0,""); + rmaField.addItem(pp); + + ArrayList list = loadRMAData(C_BPartner_ID); + for(KeyNamePair knp : list) + rmaField.addItem(knp); + + rmaField.setSelectedIndex(0); + rmaField.addActionListener(this); + } + + /** + * Load Data - Order + * @param C_Order_ID Order + * @param forInvoice true if for invoice vs. delivery qty + */ + protected void loadOrder (int C_Order_ID, boolean forInvoice) + { + loadTableOIS(getOrderData(C_Order_ID, forInvoice)); + } // LoadOrder + + protected void loadRMA (int M_RMA_ID) + { + loadTableOIS(getRMAData(M_RMA_ID)); + } + + protected void loadShipment (int M_InOut_ID) + { + loadTableOIS(getShipmentData(M_InOut_ID)); + } + + /** + * Load 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/client/src/org/compiere/minigrid/IMiniTable.java b/client/src/org/compiere/minigrid/IMiniTable.java new file mode 100644 index 0000000000..ca9a68dd91 --- /dev/null +++ b/client/src/org/compiere/minigrid/IMiniTable.java @@ -0,0 +1,52 @@ +package org.compiere.minigrid; + +import java.sql.ResultSet; + +import org.compiere.model.PO; + +public interface IMiniTable +{ + public boolean isCellEditable(int row, int column); + + public Object getValueAt(int row, int column); + + public void setValueAt(Object value, int row, int column); + + public int convertColumnIndexToModel(int viewColumnIndex); + + public void setColumnReadOnly (int index, boolean readOnly); + + public String prepareTable(ColumnInfo[] layout, String from, String where, boolean multiSelection, String tableName); + + public void addColumn (String header); + + public void setColumnClass (int index, Class classType, boolean readOnly, String header); + + public void setColumnClass (int index, Class classType, boolean readOnly); + + public void loadTable(ResultSet rs); + + public void loadTable(PO[] pos); + + public Integer getSelectedRowKey(); + + public int getSelectedRow(); + + public void setRowCount (int rowCount); + + public ColumnInfo[] getLayoutInfo(); + + public int getRowCount(); + + public void setMultiSelection(boolean multiSelection); + + public boolean isMultiSelection(); + + public int getColorCode (int row); + + public void setColorCompare (Object dataCompare); + + public void repaint(); + + public void autoSize(); +} diff --git a/client/src/org/compiere/minigrid/MiniTable.java b/client/src/org/compiere/minigrid/MiniTable.java index 834b98a4bf..73742102b7 100644 --- a/client/src/org/compiere/minigrid/MiniTable.java +++ b/client/src/org/compiere/minigrid/MiniTable.java @@ -68,7 +68,7 @@ import org.compiere.util.Util; *
  • BF [ 1891082 ] NPE on MiniTable when you hide some columns *
  • FR [ 1974299 ] Add MiniTable.getSelectedKeys method */ -public class MiniTable extends CTable +public class MiniTable extends CTable implements IMiniTable { /** * @@ -291,7 +291,7 @@ public class MiniTable extends CTable * @param c class of column - determines renderere * @param readOnly read only flag */ - public void setColumnClass (int index, Class c, boolean readOnly) + public void setColumnClass (int index, Class c, boolean readOnly) { setColumnClass(index, c, readOnly, null); } // setColumnClass @@ -306,7 +306,7 @@ public class MiniTable extends CTable * @param readOnly read only flag * @param header optional header value */ - public void setColumnClass (int index, Class c, boolean readOnly, String header) + public void setColumnClass (int index, Class c, boolean readOnly, String header) { // log.config( "MiniTable.setColumnClass - " + index, c.getName() + ", r/o=" + readOnly); TableColumn tc = getColumnModel().getColumn(index); 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 index 45e655f0d2..6641ab3478 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFrom.java @@ -47,6 +47,7 @@ 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; @@ -80,7 +81,7 @@ import org.zkoss.zul.Space; *
  • Bug [ 1759431 ] Problems with VCreateFrom */ public abstract class WCreateFrom extends Window - implements EventListener, WTableModelListener + implements ICreateFrom, EventListener, WTableModelListener { /** * @@ -625,4 +626,13 @@ public abstract class WCreateFrom extends Window 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 new file mode 100644 index 0000000000..15d93fb5d2 --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromFactory.java @@ -0,0 +1,80 @@ +package org.adempiere.webui.apps.form; + +import java.util.HashMap; +import java.util.logging.Level; + +import org.compiere.grid.ICreateFrom; +import org.compiere.grid.VCreateFromRMA; +import org.compiere.grid.VCreateFromShipment; +import org.compiere.grid.VCreateFromStatement; +import org.compiere.model.GridTab; +import org.compiere.model.I_C_BankStatement; +import org.compiere.model.I_C_Invoice; +import org.compiere.model.I_M_InOut; +import org.compiere.model.I_M_RMA; +import org.compiere.util.CLogger; +import org.compiere.util.Env; + +public class WCreateFromFactory +{ + /** Static Logger */ + private static CLogger s_log = CLogger.getCLogger (WCreateFromFactory.class); + + /** Registered classes map (AD_Table_ID -> Class) */ + private static HashMap> s_registeredClasses = null; + + /** + * 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); + } + + static + { + // Register defaults: + s_registeredClasses = new HashMap>(); + s_registeredClasses.put(I_C_Invoice.Table_ID, WCreateFromInvoiceUI.class); + + s_registeredClasses.put(I_C_BankStatement.Table_ID, WCreateFromStatement.class); + s_registeredClasses.put(I_M_InOut.Table_ID, WCreateFromShipment.class); + s_registeredClasses.put(I_M_RMA.Table_ID, WCreateFromRMA.class); + } + + /** + * Factory - called from APanel + * @param mTab Model Tab for the trx + * @return JDialog + */ + public static ICreateFrom create (GridTab mTab) + { + // dynamic init preparation + int AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), "BaseTable_ID"); + + ICreateFrom 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 +} diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoice.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoice.java index 023f903d5a..afbd9ac5e6 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoice.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoice.java @@ -60,7 +60,7 @@ public class WCreateFromInvoice extends WCreateFrom implements ValueChangeListen * Protected Constructor * @param mTab MTab */ - WCreateFromInvoice(GridTab mTab) + public WCreateFromInvoice(GridTab mTab) { super (mTab); log.info(mTab.toString()); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoiceUI.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoiceUI.java new file mode 100644 index 0000000000..8e56b947a6 --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoiceUI.java @@ -0,0 +1,369 @@ +package org.adempiere.webui.apps.form; + +import java.util.ArrayList; +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.ListItem; +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.editor.WEditor; +import org.adempiere.webui.editor.WSearchEditor; +import org.adempiere.webui.event.ValueChangeEvent; +import org.adempiere.webui.event.ValueChangeListener; +import org.compiere.grid.CreateFromInvoice; +import org.compiere.model.GridTab; +import org.compiere.model.MDocType; +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.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.zul.Space; + +public class WCreateFromInvoiceUI extends CreateFromInvoice implements EventListener, ValueChangeListener +{ + private static final long serialVersionUID = 1L; + + private WCreateFromWindow window; + + public WCreateFromInvoiceUI(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; + + protected Label orderLabel = new Label(); + protected Listbox orderField = ListboxFactory.newDropdownListbox(); + + protected Label shipmentLabel = new Label(); + protected Listbox shipmentField = ListboxFactory.newDropdownListbox(); + + /** Label for the rma selection */ + protected Label rmaLabel = new Label(); + /** Combo box for selecting RMA document */ + protected Listbox rmaField = ListboxFactory.newDropdownListbox(); + + /** + * 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()); + + // RMA Selection option should only be available for AP Credit Memo + Integer docTypeId = (Integer)getGridTab().getValue("C_DocTypeTarget_ID"); + MDocType docType = MDocType.get(Env.getCtx(), docTypeId); + if (!MDocType.DOCBASETYPE_APCreditMemo.equals(docType.getDocBaseType())) + { + rmaLabel.setVisible(false); + rmaField.setVisible(false); + } + + initBPartner(true); + bPartnerField.addValueChangeListener(this); + + return true; + } // dynInit + + protected void zkInit() throws Exception + { + bPartnerLabel.setText(Msg.getElement(Env.getCtx(), "C_BPartner_ID")); + orderLabel.setText(Msg.getElement(Env.getCtx(), "C_Order_ID", false)); + shipmentLabel.setText(Msg.getElement(Env.getCtx(), "M_InOut_ID", false)); + rmaLabel.setText(Msg.translate(Env.getCtx(), "M_RMA_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); + + parameterStdPanel.appendChild(parameterStdLayout); + Rows rows = (Rows) parameterStdLayout.newRows(); + Row 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(new Space()); + row.appendChild(new Space()); + 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); + } + + private boolean m_actionActive = false; + + /** + * Action Listener + * @param e event + * @throws Exception + */ + public void onEvent(Event e) throws Exception + { + if (m_actionActive) + return; + m_actionActive = true; + + // Order + if (e.getTarget().equals(orderField)) + { + ListItem li = orderField.getSelectedItem(); + int C_Order_ID = 0; + if (li != null && li.getValue() != null) + C_Order_ID = ((Integer) li.getValue()).intValue(); + // set Invoice, RMA and Shipment to Null + rmaField.setSelectedIndex(-1); + shipmentField.setSelectedIndex(-1); + loadOrder(C_Order_ID, true); + } + // Shipment + else if (e.getTarget().equals(shipmentField)) + { + ListItem li = shipmentField.getSelectedItem(); + int M_InOut_ID = 0; + if (li != null && li.getValue() != null) + M_InOut_ID = ((Integer) li.getValue()).intValue(); + // set Order, RMA and Invoice to Null + orderField.setSelectedIndex(-1); + rmaField.setSelectedIndex(-1); + loadShipment(M_InOut_ID); + } + // RMA + else if (e.getTarget().equals(rmaField)) + { + ListItem li = rmaField.getSelectedItem(); + int M_RMA_ID = 0; + if (li != null && li.getValue() != null) + M_RMA_ID = ((Integer) li.getValue()).intValue(); + // set Order and Invoice to Null + orderField.setSelectedIndex(-1); + shipmentField.setSelectedIndex(-1); + loadRMA(M_RMA_ID); + } + m_actionActive = false; + } + + /** + * 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(); + initBPOrderDetails (C_BPartner_ID, true); + } + 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)); + + // initial loading + initBPOrderDetails(C_BPartner_ID, forInvoice); + } // initBPartner + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID BPartner + * @param forInvoice for invoice + */ + protected void initBPOrderDetails (int C_BPartner_ID, boolean forInvoice) + { + log.config("C_BPartner_ID=" + C_BPartner_ID); + KeyNamePair pp = new KeyNamePair(0,""); + // load PO Orders - Closed, Completed + orderField.removeActionListener(this); + orderField.removeAllItems(); + orderField.addItem(pp); + + ArrayList list = loadOrderData(C_BPartner_ID, forInvoice, false); + for(KeyNamePair knp : list) + orderField.addItem(knp); + + orderField.setSelectedIndex(0); + orderField.addActionListener(this); + + initBPDetails(C_BPartner_ID); + } // initBPartnerOIS + + public void initBPDetails(int C_BPartner_ID) + { + initBPShipmentDetails(C_BPartner_ID); + initBPRMADetails(C_BPartner_ID); + } + + /** + * Load PBartner dependent Order/Invoice/Shipment Field. + * @param C_BPartner_ID + */ + private void initBPShipmentDetails(int C_BPartner_ID) + { + log.config("C_BPartner_ID" + C_BPartner_ID); + + // load Shipments (Receipts) - Completed, Closed + shipmentField.removeActionListener(this); + shipmentField.removeAllItems(); + // None + KeyNamePair pp = new KeyNamePair(0,""); + shipmentField.addItem(pp); + + ArrayList list = loadShipmentData(C_BPartner_ID); + for(KeyNamePair knp : list) + shipmentField.addItem(knp); + + shipmentField.setSelectedIndex(0); + shipmentField.addActionListener(this); + } + + /** + * Load RMA that are candidates for shipment + * @param C_BPartner_ID BPartner + */ + private void initBPRMADetails(int C_BPartner_ID) + { + rmaField.removeActionListener(this); + rmaField.removeAllItems(); + // None + KeyNamePair pp = new KeyNamePair(0,""); + rmaField.addItem(pp); + + ArrayList list = loadRMAData(C_BPartner_ID); + for(KeyNamePair knp : list) + rmaField.addItem(knp); + + rmaField.setSelectedIndex(0); + rmaField.addActionListener(this); + } + + /** + * Load Data - Order + * @param C_Order_ID Order + * @param forInvoice true if for invoice vs. delivery qty + */ + protected void loadOrder (int C_Order_ID, boolean forInvoice) + { + loadTableOIS(getOrderData(C_Order_ID, forInvoice)); + } // LoadOrder + + protected void loadRMA (int M_RMA_ID) + { + loadTableOIS(getRMAData(M_RMA_ID)); + } + + protected void loadShipment (int M_InOut_ID) + { + loadTableOIS(getShipmentData(M_InOut_ID)); + } + + /** + * Load 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.getWListbox()); + // Set Model + ListModelTable model = new ListModelTable(data); + model.addTableModelListener(window.getWListbox()); + 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/WCreateFromRMA.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMA.java index 5c1025c9cc..eccba96b49 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMA.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromRMA.java @@ -43,7 +43,7 @@ public class WCreateFromRMA extends WCreateFrom * * @param mTab */ - WCreateFromRMA(GridTab mTab) + public WCreateFromRMA(GridTab mTab) { super(mTab); log.info(mTab.toString()); 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 index 281fc26a43..601f261829 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipment.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipment.java @@ -63,7 +63,7 @@ public class WCreateFromShipment extends WCreateFrom implements ValueChangeListe * Protected Constructor * @param mTab MTab */ - WCreateFromShipment(GridTab mTab) + public WCreateFromShipment(GridTab mTab) { super (mTab); // log.info( "VCreateFromShipment"); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatement.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatement.java index 43925f838a..5885ad5911 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatement.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromStatement.java @@ -64,7 +64,7 @@ public class WCreateFromStatement extends WCreateFrom implements ValueChangeList * Protected Constructor * @param mTab MTab */ - WCreateFromStatement(GridTab mTab) + public WCreateFromStatement(GridTab mTab) { super (mTab); log.info(""); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromWindow.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromWindow.java new file mode 100644 index 0000000000..900870031a --- /dev/null +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromWindow.java @@ -0,0 +1,198 @@ +package org.adempiere.webui.apps.form; + +import org.adempiere.webui.component.Button; +import org.adempiere.webui.component.ConfirmPanel; +import org.adempiere.webui.component.ListModelTable; +import org.adempiere.webui.component.ListboxFactory; +import org.adempiere.webui.component.Panel; +import org.adempiere.webui.component.WAppsAction; +import org.adempiere.webui.component.WListbox; +import org.adempiere.webui.component.Window; +import org.adempiere.webui.event.WTableModelEvent; +import org.adempiere.webui.event.WTableModelListener; +import org.adempiere.webui.panel.StatusBarPanel; +import org.adempiere.webui.window.FDialog; +import org.compiere.grid.CreateFrom; +import org.compiere.util.Trx; +import org.compiere.util.TrxRunnable; +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; + +public class WCreateFromWindow extends Window implements EventListener, WTableModelListener +{ + private static final long serialVersionUID = 1L; + + private CreateFrom createFrom; + private int windowNo; + + private Panel parameterPanel = new Panel(); + private ConfirmPanel confirmPanel = new ConfirmPanel(true); + private StatusBarPanel statusBar = new StatusBarPanel(); + private WListbox dataTable = ListboxFactory.newDataTable(); + + public static final String SELECT_ALL = "SelectAll"; + + + public WCreateFromWindow(CreateFrom createFrom, int windowNo) + { + super(); + setAttribute("mode", "modal"); + + this.createFrom = createFrom; + this.windowNo = windowNo; + + try + { + zkInit(); + confirmPanel.addActionListener(this); + + statusBar.setStatusDB(""); + tableChanged(null); + createFrom.setInitOK(true); + } + catch(Exception e) + { + createFrom.setInitOK(false); + } + } + + protected void zkInit() throws Exception + { + Borderlayout contentPane = new Borderlayout(); + appendChild(contentPane); + + North north = new North(); + contentPane.appendChild(north); + north.appendChild(parameterPanel); + + Center center = new Center(); + contentPane.appendChild(center); + center.appendChild(dataTable); + + 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); + Panel southPanel = new Panel(); + south.appendChild(southPanel); + southPanel.appendChild(new Separator()); + southPanel.appendChild(confirmPanel); + + southPanel.appendChild(new Separator()); + southPanel.appendChild(statusBar); + + setWidth("750px"); + setHeight("550px"); + setSizable(true); + setBorder("normal"); + contentPane.setWidth("100%"); + contentPane.setHeight("100%"); + } + + public void onEvent(Event e) throws Exception + { + // OK - Save + if (e.getTarget().getId().equals(ConfirmPanel.A_OK)) + { + try + { + Trx.run(new TrxRunnable() + { + public void run(String trxName) + { + if (save(trxName)) + { + dispose(); + } + } + }); + } + catch (Exception ex) + { + FDialog.error(windowNo, this, "Error", ex.getLocalizedMessage()); + } + } + // 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(); + } + } + + public void tableChanged (WTableModelEvent e) + { + int type = -1; + if (e != null) + { + type = e.getType(); + if (type != WTableModelEvent.CONTENTS_CHANGED) + return; + } + info(); + } + + public boolean save(String trxName) + { + ListModelTable model = dataTable.getModel(); + int rows = model.getSize(); + if (rows == 0) + return false; + + return createFrom.save(dataTable, trxName); + } + + public 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); + } + + 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 WListbox getWListbox() + { + return dataTable; + } + + public Panel getParameterPanel() + { + return parameterPanel; + } +} diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListbox.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListbox.java index 90efd8cb9f..c2e5928760 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListbox.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/WListbox.java @@ -32,6 +32,7 @@ import org.adempiere.webui.event.WTableModelListener; import org.adempiere.webui.exception.ApplicationException; import org.compiere.minigrid.ColumnInfo; import org.compiere.minigrid.IDColumn; +import org.compiere.minigrid.IMiniTable; import org.compiere.minigrid.MiniTable; import org.compiere.model.MRole; import org.compiere.model.PO; @@ -54,7 +55,7 @@ import org.zkoss.zul.ListModel; * @author Andrew Kimball * @author Sendy Yagambrum */ -public class WListbox extends Listbox implements TableValueChangeListener, WTableModelListener +public class WListbox extends Listbox implements IMiniTable, TableValueChangeListener, WTableModelListener { /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java b/zkwebui/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java index abc1b08c6c..7bc0d21870 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/panel/AbstractADWindowPanel.java @@ -33,7 +33,7 @@ import org.adempiere.webui.WZoomAcross; import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.ProcessModalDialog; import org.adempiere.webui.apps.WReport; -import org.adempiere.webui.apps.form.WCreateFrom; +import org.adempiere.webui.apps.form.WCreateFromFactory; import org.adempiere.webui.apps.form.WPayment; import org.adempiere.webui.component.CWindowToolbar; import org.adempiere.webui.component.IADTab; @@ -50,6 +50,7 @@ import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FindWindow; import org.adempiere.webui.window.WRecordAccessDialog; +import org.compiere.grid.ICreateFrom; import org.compiere.model.DataStatusEvent; import org.compiere.model.DataStatusListener; import org.compiere.model.GridField; @@ -1706,14 +1707,13 @@ public abstract class AbstractADWindowPanel extends AbstractUIPart implements To else if (col.equals("CreateFrom")) { - // curWindowNo - WCreateFrom wcf = WCreateFrom.create(curTab); + ICreateFrom cf = WCreateFromFactory.create(curTab); - if (wcf != null) + if(cf != null) { - if (wcf.isInitOK()) + if(cf.isInitOK()) { - wcf.setVisible(true); + cf.showWindow(); curTab.dataRefresh(); } return;