diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutInOut.java b/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutInOut.java new file mode 100644 index 0000000..bd80910 --- /dev/null +++ b/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutInOut.java @@ -0,0 +1,42 @@ +package andromedia.midsuit.callout; + +import java.util.Properties; + +import org.adempiere.base.IColumnCallout; +import org.compiere.model.CalloutEngine; +import org.compiere.model.GridField; +import org.compiere.model.GridTab; +import org.compiere.model.MInOut; +import org.compiere.model.MOrder; + +public class MID_CalloutInOut extends CalloutEngine implements IColumnCallout{ + + @Override + public String start(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) { + // TODO Auto-generated method stub + if(value == null) return null; + + if(mField.getColumnName().equals(MInOut.COLUMNNAME_MovementDate)) { + mTab.setValue(MInOut.COLUMNNAME_DateAcct, value); + } + + if(mField.getColumnName().equals(MInOut.COLUMNNAME_C_Order_ID)) { + setAJU(ctx, WindowNo, mTab, mField, value, oldValue); + } + return null; + } + + public String setAJU(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) { + MOrder order = new MOrder(ctx, (int)value, null); + + if(order != null) { + mTab.setValue("noaju1", order.get_ValueAsString("noaju1") == null ? null : order.get_ValueAsString("noaju1")); + mTab.setValue("noaju2", order.get_ValueAsString("noaju2") == null ? null : order.get_ValueAsString("noaju2")); + mTab.setValue("noaju3", order.get_ValueAsString("noaju3") == null ? null : order.get_ValueAsString("noaju3")); + mTab.setValue("noaju4", order.get_ValueAsString("noaju4") == null ? null : order.get_ValueAsString("noaju4")); + } + + return null; + } + +} diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutInOutLine.java b/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutInOutLine.java new file mode 100644 index 0000000..9dcb627 --- /dev/null +++ b/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutInOutLine.java @@ -0,0 +1,34 @@ +package andromedia.midsuit.callout; + +import java.util.Properties; + +import org.adempiere.base.IColumnCallout; +import org.compiere.model.CalloutEngine; +import org.compiere.model.GridField; +import org.compiere.model.GridTab; +import org.compiere.model.MInOutLine; +import org.compiere.model.MOrderLine; + +public class MID_CalloutInOutLine extends CalloutEngine implements IColumnCallout{ + + @Override + public String start(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) { + // TODO Auto-generated method stub + if(value == null) return null; + + if(mField.getColumnName().equals(MInOutLine.COLUMNNAME_C_OrderLine_ID)) { + this.setDescription(ctx, WindowNo, mTab, mField, value, oldValue); + } + + return null; + } + + public String setDescription(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) { + MOrderLine ol = new MOrderLine(ctx, (int)value, null); + + mTab.setValue(MInOutLine.COLUMNNAME_Description, ol.getDescription() != null ? ol.getDescription() : null); + + return null; + } + +} diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutOrder.java b/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutOrder.java index 8d9bc6b..79e5764 100644 --- a/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutOrder.java +++ b/andromeida.midsuit.project/src/andromedia/midsuit/callout/MID_CalloutOrder.java @@ -16,10 +16,14 @@ public class MID_CalloutOrder extends CalloutEngine implements IColumnCallout { @Override public String start(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) { // TODO Auto-generated method stub + if(value == null) return null; + if(mField.getColumnName().equals(MOrder.COLUMNNAME_AD_Org_ID)) { - if(value == null) return null; return setPricelistByOrg(ctx, WindowNo, mTab, mField, value, oldValue); } + if(mField.getColumnName().equals(MOrder.COLUMNNAME_DateOrdered)) { + mTab.setValue(MOrder.COLUMNNAME_DatePromised, value); + } return null; } diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_CalloutFactory.java b/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_CalloutFactory.java index 93eb971..4dd8915 100644 --- a/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_CalloutFactory.java +++ b/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_CalloutFactory.java @@ -5,11 +5,15 @@ import java.util.List; import org.adempiere.base.IColumnCallout; import org.adempiere.base.IColumnCalloutFactory; +import org.compiere.model.MInOut; +import org.compiere.model.MInOutLine; import org.compiere.model.MOrder; import org.compiere.model.MProduction; import org.compiere.model.MProductionLine; import andromedia.midsuit.callout.MID_CalloutAnalysisQC; +import andromedia.midsuit.callout.MID_CalloutInOut; +import andromedia.midsuit.callout.MID_CalloutInOutLine; import andromedia.midsuit.callout.MID_CalloutOrder; import andromedia.midsuit.callout.MID_CalloutProduction; import andromedia.midsuit.callout.MID_CalloutProductionLine; @@ -33,6 +37,10 @@ public class MID_CalloutFactory implements IColumnCalloutFactory{ list.add(new MID_CalloutProductionLine()); if(tableName.equals(MID_Analysis.Table_Name)) list.add(new MID_CalloutAnalysisQC()); + if(tableName.equals(MInOut.Table_Name)) + list.add(new MID_CalloutInOut()); + if(tableName.equals(MInOutLine.Table_Name)) + list.add(new MID_CalloutInOutLine()); return list != null ? list.toArray(new IColumnCallout[0]) : new IColumnCallout[0]; } diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_CreateFromFactory.java b/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_CreateFromFactory.java index 6571c84..de3e528 100644 --- a/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_CreateFromFactory.java +++ b/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_CreateFromFactory.java @@ -3,9 +3,13 @@ package andromedia.midsuit.factory; import org.compiere.grid.ICreateFrom; import org.compiere.grid.ICreateFromFactory; import org.compiere.model.GridTab; +import org.compiere.model.MInOut; +import org.compiere.model.MInvoice; +import org.compiere.model.X_C_Invoice; import org.compiere.model.X_C_Order; import org.compiere.model.X_M_InOut; +import andromedia.midsuit.form.MID_WCreateFromInvoice; import andromedia.midsuit.form.MID_WCreateFromOrder; import andromedia.midsuit.form.MID_WCreateFromShipment; @@ -17,6 +21,8 @@ public class MID_CreateFromFactory implements ICreateFromFactory{ return new MID_WCreateFromOrder(mTab); if (tableName.equals(X_M_InOut.Table_Name)) return new MID_WCreateFromShipment(mTab); + if (tableName.equals(X_C_Invoice.Table_Name)) + return new MID_WCreateFromInvoice(mTab); return null; } diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_DocFactory.java b/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_DocFactory.java index b7c5bbb..2c73211 100644 --- a/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_DocFactory.java +++ b/andromeida.midsuit.project/src/andromedia/midsuit/factory/MID_DocFactory.java @@ -63,7 +63,9 @@ public class MID_DocFactory implements IDocFactory{ return new MID_DocAnalysis(as, rs, trxName); if(tableName.equals(MInvoice.Table_Name)) { s_log.log(Level.SEVERE,"IN"); - return new MID_DocInvoice(as, rs, trxName);} + return new MID_DocInvoice(as, rs, trxName); + } + return null; } diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromInvoice.java b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromInvoice.java new file mode 100644 index 0000000..ba2dd96 --- /dev/null +++ b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromInvoice.java @@ -0,0 +1,619 @@ +package andromedia.midsuit.form; + +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.apps.IStatusBar; +import org.compiere.grid.CreateFrom; +import org.compiere.minigrid.IMiniTable; +import org.compiere.model.GridTab; +import org.compiere.model.MCurrency; +import org.compiere.model.MInOut; +import org.compiere.model.MInOutLine; +import org.compiere.model.MInvoice; +import org.compiere.model.MInvoiceLine; +import org.compiere.model.MInvoicePaySchedule; +import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; +import org.compiere.model.MOrderPaySchedule; +import org.compiere.model.MProduct; +import org.compiere.model.MRMA; +import org.compiere.model.MRMALine; +import org.compiere.model.MUOMConversion; +import org.compiere.model.PO; +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 MID_CreateFromInvoice extends CreateFrom { + + protected MInOut m_inout = null; + + /** + * Protected Constructor + * @param mTab MTab + */ + public MID_CreateFromInvoice(GridTab mTab) + { + super(mTab); + if (log.isLoggable(Level.INFO)) 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) + { + String isSOTrxParam = isSOTrx ? "Y":"N"; + 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=? AND s.DocStatus IN ('CL','CO')" + + " AND s.M_InOut_ID IN " + + "(SELECT sl.M_InOut_ID FROM M_InOutLine sl"); + if(!isSOTrx) + sql.append(" 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=? AND s2.DocStatus IN ('CL','CO') " + + " GROUP BY sl.M_InOut_ID,sl.MovementQty,mi.M_InOutLine_ID" + + " HAVING (sl.MovementQty<>SUM(mi.Qty) AND mi.M_InOutLine_ID IS NOT NULL)" + + " OR mi.M_InOutLine_ID IS NULL "); + else + sql.append(" INNER JOIN M_InOut s2 ON (sl.M_InOut_ID=s2.M_InOut_ID)" + + " LEFT JOIN C_InvoiceLine il ON sl.M_InOutLine_ID = il.M_InOutLine_ID" + + " WHERE s2.C_BPartner_ID=? AND s2.IsSOTrx=? AND s2.DocStatus IN ('CL','CO')" + + " GROUP BY sl.M_InOutLine_ID" + + " HAVING sl.MovementQty - sum(COALESCE(il.QtyInvoiced,0)) > 0"); + sql.append(") ORDER BY s.MovementDate"); + PreparedStatement pstmt = null; + ResultSet rs = null; + try + { + pstmt = DB.prepareStatement(sql.toString(), null); + pstmt.setInt(1, C_BPartner_ID); + pstmt.setString(2, isSOTrxParam); + pstmt.setInt(3, C_BPartner_ID); + pstmt.setString(4, isSOTrxParam); + 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; + } + + /** + * 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; + ResultSet rs = null; + try { + pstmt = DB.prepareStatement(sqlStmt, null); + pstmt.setInt(1, C_BPartner_ID); + rs = pstmt.executeQuery(); + while (rs.next()) { + list.add(new KeyNamePair(rs.getInt(1), rs.getString(2))); + } + } catch (SQLException e) { + log.log(Level.SEVERE, sqlStmt.toString(), e); + } finally{ + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } + + return list; + } + + /** + * Load Data - Shipment not invoiced + * @param M_InOut_ID InOut + */ + protected Vector> getShipmentData(int M_InOut_ID) + { + if (log.isLoggable(Level.CONFIG)) log.config("M_InOut_ID=" + M_InOut_ID); + MInOut inout = new MInOut(Env.getCtx(), M_InOut_ID, null); + p_order = null; + m_inout = inout; + if (inout.getC_Order_ID() != 0) + p_order = new MOrder (Env.getCtx(), inout.getC_Order_ID(), null); + + m_rma = null; + if (inout.getM_RMA_ID() != 0) + m_rma = new MRMA (Env.getCtx(), inout.getM_RMA_ID(), null); + + // + Vector> data = new Vector>(); + StringBuilder sql = new StringBuilder("SELECT "); // QtyEntered + if(!isSOTrx) + sql.append("l.MovementQty-SUM(COALESCE(mi.Qty, 0)),"); + else + sql.append("l.MovementQty-SUM(COALESCE(il.QtyInvoiced,0)),"); + sql.append(" 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)"); + if(!isSOTrx) + sql.append(" LEFT OUTER JOIN M_MatchInv mi ON (l.M_InOutLine_ID=mi.M_InOutLine_ID)"); + else + sql.append(" LEFT JOIN C_InvoiceLine il ON l.M_InOutLine_ID = il.M_InOutLine_ID"); + sql.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(" 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 "); + if(!isSOTrx) + sql.append(" HAVING l.MovementQty-SUM(COALESCE(mi.Qty, 0)) <>0"); + else + sql.append(" HAVING l.MovementQty-SUM(COALESCE(il.QtyInvoiced,0)) <>0"); + sql.append("ORDER BY l.Line"); + PreparedStatement pstmt = null; + ResultSet rs = null; + try + { + pstmt = DB.prepareStatement(sql.toString(), null); + pstmt.setInt(1, M_InOut_ID); + 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); + } + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql.toString(), e); + } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } + + 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>(); + StringBuilder sqlStmt = new StringBuilder(); + sqlStmt.append("SELECT rl.M_RMALine_ID, rl.line, rl.Qty - COALESCE(rl.QtyInvoiced, 0), 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); + } + } + 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(IMiniTable miniTable, IStatusBar statusBar) + { + + } // 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); + if (log.isLoggable(Level.CONFIG)) log.config(invoice.toString()); + + if (p_order != null) + { + invoice.setOrder(p_order); // overwrite header values + invoice.saveEx(); + } + + if (m_rma != null) + { + invoice.setM_RMA_ID(m_rma.getM_RMA_ID()); + invoice.saveEx(); + } + + if (m_inout != null) + { + invoice.set_ValueNoCheck("M_InOut_ID", (int)m_inout.getM_InOut_ID()); + 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()) + { + MProduct product = null; + // 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(); + // + int M_RMALine_ID = 0; + pp = (KeyNamePair)miniTable.getValueAt(i, 7); // 7-RMALine + if (pp != null) + M_RMALine_ID = pp.getKey(); + + // Precision of Qty UOM + int precision = 2; + if (M_Product_ID != 0) + { + product = MProduct.get(Env.getCtx(), M_Product_ID); + precision = product.getUOMPrecision(); + } + QtyEntered = QtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN); + // + if (log.isLoggable(Level.FINE)) 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 + BigDecimal QtyInvoiced = null; + if (M_Product_ID > 0 && product.getC_UOM_ID() != C_UOM_ID) { + QtyInvoiced = MUOMConversion.convertProductFrom(Env.getCtx(), M_Product_ID, C_UOM_ID, QtyEntered); + } + if (QtyInvoiced == null) + QtyInvoiced = QtyEntered; + invoiceLine.setQtyInvoiced(QtyInvoiced); + + // Info + MOrderLine orderLine = null; + if (C_OrderLine_ID != 0) + orderLine = new MOrderLine (Env.getCtx(), C_OrderLine_ID, trxName); + // + MRMALine rmaLine = null; + if (M_RMALine_ID > 0) + rmaLine = new MRMALine (Env.getCtx(), M_RMALine_ID, null); + // + 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 if (C_OrderLine_ID > 0) + { + 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); + if (log.isLoggable(Level.FINE)) 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(); +// } + } + } + else if (M_RMALine_ID != 0) + { + 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.getOfRMALine(Env.getCtx(), M_RMALine_ID, whereClause, null); + if (log.isLoggable(Level.FINE)) log.fine ("Receipt Lines with RMALine = #" + lines.length); + if (lines.length > 0) + { + for (int j = 0; j < lines.length; j++) + { + MInOutLine line = lines[j]; + if (rmaLine.getQty().compareTo(QtyEntered) == 0) + { + inoutLine = line; + M_InOutLine_ID = inoutLine.getM_InOutLine_ID(); + break; + } + } + if (rmaLine == 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 + } + else { + log.fine("No Receipt Line"); + // Order Info + if (orderLine != null) + { + invoiceLine.setOrderLine(orderLine); // overwrites + } + else + { + log.fine("No Order Line"); + invoiceLine.setPrice(); + invoiceLine.setTax(); + } + + //RMA Info + if (rmaLine != null) + { + invoiceLine.setRMALine(rmaLine); // overwrites + } + else + log.fine("No RMA Line"); + } + invoiceLine.saveEx(); + } // if selected + } // for all rows + + if (p_order != null) { + invoice.setPaymentRule(p_order.getPaymentRule()); + invoice.setC_PaymentTerm_ID(p_order.getC_PaymentTerm_ID()); + invoice.saveEx(); + invoice.load(invoice.get_TrxName()); // refresh from DB + // copy payment schedule from order if invoice doesn't have a current payment schedule + MOrderPaySchedule[] opss = MOrderPaySchedule.getOrderPaySchedule(invoice.getCtx(), p_order.getC_Order_ID(), 0, invoice.get_TrxName()); + MInvoicePaySchedule[] ipss = MInvoicePaySchedule.getInvoicePaySchedule(invoice.getCtx(), invoice.getC_Invoice_ID(), 0, invoice.get_TrxName()); + if (ipss.length == 0 && opss.length > 0) { + BigDecimal ogt = p_order.getGrandTotal(); + BigDecimal igt = invoice.getGrandTotal(); + BigDecimal percent = Env.ONE; + if (ogt.compareTo(igt) != 0) + percent = igt.divide(ogt, 10, BigDecimal.ROUND_HALF_UP); + MCurrency cur = MCurrency.get(p_order.getCtx(), p_order.getC_Currency_ID()); + int scale = cur.getStdPrecision(); + + for (MOrderPaySchedule ops : opss) { + MInvoicePaySchedule ips = new MInvoicePaySchedule(invoice.getCtx(), 0, invoice.get_TrxName()); + PO.copyValues(ops, ips); + if (percent != Env.ONE) { + BigDecimal propDueAmt = ops.getDueAmt().multiply(percent); + if (propDueAmt.scale() > scale) + propDueAmt = propDueAmt.setScale(scale, BigDecimal.ROUND_HALF_UP); + ips.setDueAmt(propDueAmt); + } + ips.setC_Invoice_ID(invoice.getC_Invoice_ID()); + ips.setAD_Org_ID(ops.getAD_Org_ID()); + ips.setProcessing(ops.isProcessing()); + ips.setIsActive(ops.isActive()); + ips.saveEx(); + } + invoice.validatePaySchedule(); + invoice.saveEx(); + } + + invoice.set_ValueOfColumn("noaju1", p_order.get_ValueAsString("noaju1") == null ? null : p_order.get_ValueAsString("noaju1")); + invoice.set_ValueOfColumn("noaju2", p_order.get_ValueAsString("noaju2") == null ? null : p_order.get_ValueAsString("noaju2")); + invoice.set_ValueOfColumn("noaju3", p_order.get_ValueAsString("noaju3") == null ? null : p_order.get_ValueAsString("noaju3")); + invoice.set_ValueOfColumn("noaju4", p_order.get_ValueAsString("noaju4") == null ? null : p_order.get_ValueAsString("noaju4")); + invoice.saveEx(); + } + + return true; + } // saveInvoice + + 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", isSOTrx)); + columnNames.add(Msg.getElement(Env.getCtx(), "C_Order_ID", isSOTrx)); + columnNames.add(Msg.getElement(Env.getCtx(), "M_InOut_ID", isSOTrx)); + columnNames.add(Msg.getElement(Env.getCtx(), "M_RMA_ID", isSOTrx)); + + return columnNames; + } + +} diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromOrder.java b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromOrder.java index eec958c..e7c5c13 100644 --- a/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromOrder.java +++ b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromOrder.java @@ -568,7 +568,7 @@ public class MID_CreateFromOrder extends CreateFrom { } } } - order.setDescription(order.getDescription()==null? desc : order.getDescription()+";"+desc); +// order.setDescription(order.getDescription()==null? desc : order.getDescription()+";"+desc); order.saveEx(); return true; } diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromShipment.java b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromShipment.java index 11e6d5f..5bd8356 100644 --- a/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromShipment.java +++ b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_CreateFromShipment.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Vector; import java.util.logging.Level; +import org.adempiere.webui.panel.InfoInOutPanel; import org.compiere.apps.IStatusBar; import org.compiere.grid.CreateFrom; import org.compiere.minigrid.IMiniTable; @@ -707,8 +708,11 @@ public abstract class MID_CreateFromShipment extends CreateFrom inout.setC_Activity_ID(p_order.getC_Activity_ID()); inout.setUser1_ID(p_order.getUser1_ID()); inout.setUser2_ID(p_order.getUser2_ID()); - inout.setDateOrdered(p_order.getDateOrdered()); - + inout.set_ValueOfColumn("noaju1", p_order.get_ValueAsString("noaju1") == null ? null : p_order.get_ValueAsString("noaju1")); + inout.set_ValueOfColumn("noaju2", p_order.get_ValueAsString("noaju2") == null ? null : p_order.get_ValueAsString("noaju2")); + inout.set_ValueOfColumn("noaju3", p_order.get_ValueAsString("noaju3") == null ? null : p_order.get_ValueAsString("noaju3")); + inout.set_ValueOfColumn("noaju4", p_order.get_ValueAsString("noaju4") == null ? null : p_order.get_ValueAsString("noaju4")); + if ( p_order.isDropShip() ) { inout.setM_Warehouse_ID( p_order.getM_Warehouse_ID() ); @@ -729,6 +733,10 @@ public abstract class MID_CreateFromShipment extends CreateFrom inout.setC_Activity_ID(m_invoice.getC_Activity_ID()); inout.setUser1_ID(m_invoice.getUser1_ID()); inout.setUser2_ID(m_invoice.getUser2_ID()); + inout.set_ValueOfColumn("noaju1", m_invoice.get_ValueAsString("noaju1") == null ? null : m_invoice.get_ValueAsString("noaju1")); + inout.set_ValueOfColumn("noaju2", m_invoice.get_ValueAsString("noaju2") == null ? null : m_invoice.get_ValueAsString("noaju2")); + inout.set_ValueOfColumn("noaju3", m_invoice.get_ValueAsString("noaju3") == null ? null : m_invoice.get_ValueAsString("noaju3")); + inout.set_ValueOfColumn("noaju4", m_invoice.get_ValueAsString("noaju4") == null ? null : m_invoice.get_ValueAsString("noaju4")); } if (m_rma != null && m_rma.getM_RMA_ID() != 0) { @@ -783,5 +791,4 @@ public abstract class MID_CreateFromShipment extends CreateFrom defaultLocator_ID = M_Locator_ID; return getInvoiceData (C_Invoice_ID); } - } diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_WCreateFromInvoice.java b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_WCreateFromInvoice.java new file mode 100644 index 0000000..317aac1 --- /dev/null +++ b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_WCreateFromInvoice.java @@ -0,0 +1,475 @@ +package andromedia.midsuit.form; + +import static org.compiere.model.SystemIDs.COLUMN_C_INVOICE_C_BPARTNER_ID; + +import java.util.ArrayList; +import java.util.Vector; +import java.util.logging.Level; + +import org.adempiere.webui.ClientInfo; +import org.adempiere.webui.LayoutUtils; +import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.apps.form.WCreateFromInvoiceUI; +import org.adempiere.webui.apps.form.WCreateFromWindow; +import org.adempiere.webui.component.Column; +import org.adempiere.webui.component.Columns; +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.adempiere.webui.util.ZKUpdateUtil; +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.Component; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zul.Space; + +public class MID_WCreateFromInvoice extends MID_CreateFromInvoice implements EventListener, ValueChangeListener +{ + private WCreateFromWindow window; + + public MID_WCreateFromInvoice(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(); + + private Grid parameterStdLayout; + + /** + * 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", isSOTrx)); + shipmentLabel.setText(Msg.getElement(Env.getCtx(), "M_InOut_ID", isSOTrx)); + rmaLabel.setText(Msg.translate(Env.getCtx(), "M_RMA_ID")); + + Panel parameterPanel = window.getParameterPanel(); + + parameterStdLayout = GridFactory.newGridLayout(); + Panel parameterStdPanel = new Panel(); + parameterStdPanel.appendChild(parameterStdLayout); + + setupColumns(parameterStdLayout); + + parameterPanel.appendChild(parameterStdPanel); + ZKUpdateUtil.setVflex(parameterStdLayout, "min"); + + Rows rows = (Rows) parameterStdLayout.newRows(); + Row row = rows.newRow(); + row.appendChild(bPartnerLabel.rightAlign()); + if (bPartnerField != null) + row.appendChild(bPartnerField.getComponent()); + row.appendChild(orderLabel.rightAlign()); + ZKUpdateUtil.setHflex(orderField, "1"); + row.appendChild(orderField); + + row = rows.newRow(); + row.appendChild(new Space()); + row.appendChild(new Space()); + row.appendChild(shipmentLabel.rightAlign()); + ZKUpdateUtil.setHflex(shipmentField, "1"); + row.appendChild(shipmentField); + + // Add RMA document selection to panel + row = rows.newRow(); + row.appendChild(new Space()); + row.appendChild(new Space()); + row.appendChild(rmaLabel.rightAlign()); + ZKUpdateUtil.setHflex(rmaField, "1"); + row.appendChild(rmaField); + + if (ClientInfo.isMobile()) { + if (noOfParameterColumn == 2) + LayoutUtils.compactTo(parameterStdLayout, 2); + ClientInfo.onClientInfo(window, this::onClientInfo); + } + + hideEmptyRow(rows); + } + + private void hideEmptyRow(org.zkoss.zul.Rows rows) { + for(Component a : rows.getChildren()) { + Row row = (Row) a; + boolean visible = false; + for(Component b : row.getChildren()) { + if (b instanceof Space) + continue; + else if (!b.isVisible()) { + continue; + } else { + if (!b.getChildren().isEmpty()) { + for (Component c : b.getChildren()) { + if (c.isVisible()) { + visible = true; + break; + } + } + } else { + visible = true; + break; + } + } + } + row.setVisible(visible); + } + } + + private boolean m_actionActive = false; + + private int noOfParameterColumn; + + /** + * 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) + { + if (log.isLoggable(Level.CONFIG)) 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 = COLUMN_C_INVOICE_C_BPARTNER_ID; // 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) + { + if (log.isLoggable(Level.CONFIG)) 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) + { + if (log.isLoggable(Level.CONFIG)) 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); + // 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(); + } + + @Override + public Object getWindow() { + return window; + } + + protected void setupColumns(Grid parameterGrid) { + noOfParameterColumn = ClientInfo.maxWidth((ClientInfo.EXTRA_SMALL_WIDTH+ClientInfo.SMALL_WIDTH)/2) ? 2 : 4; + Columns columns = new Columns(); + parameterGrid.appendChild(columns); + if (ClientInfo.maxWidth((ClientInfo.EXTRA_SMALL_WIDTH+ClientInfo.SMALL_WIDTH)/2)) + { + Column column = new Column(); + ZKUpdateUtil.setWidth(column, "35%"); + columns.appendChild(column); + column = new Column(); + ZKUpdateUtil.setWidth(column, "65%"); + columns.appendChild(column); + } + else + { + Column column = new Column(); + columns.appendChild(column); + column = new Column(); + ZKUpdateUtil.setWidth(column, "15%"); + columns.appendChild(column); + ZKUpdateUtil.setWidth(column, "35%"); + column = new Column(); + ZKUpdateUtil.setWidth(column, "15%"); + columns.appendChild(column); + column = new Column(); + ZKUpdateUtil.setWidth(column, "35%"); + columns.appendChild(column); + } + } + + protected void onClientInfo() + { + if (ClientInfo.isMobile() && parameterStdLayout != null && parameterStdLayout.getRows() != null) + { + int nc = ClientInfo.maxWidth((ClientInfo.EXTRA_SMALL_WIDTH+ClientInfo.SMALL_WIDTH)/2) ? 2 : 4; + int cc = noOfParameterColumn; + if (nc == cc) + return; + + parameterStdLayout.getColumns().detach(); + setupColumns(parameterStdLayout); + if (cc > nc) + { + LayoutUtils.compactTo(parameterStdLayout, nc); + } + else + { + LayoutUtils.expandTo(parameterStdLayout, nc, false); + } + hideEmptyRow(parameterStdLayout.getRows()); + + ZKUpdateUtil.setCSSHeight(window); + ZKUpdateUtil.setCSSWidth(window); + window.invalidate(); + } + } +} diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_WCreateFromShipment.java b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_WCreateFromShipment.java index f072d41..de22971 100644 --- a/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_WCreateFromShipment.java +++ b/andromeida.midsuit.project/src/andromedia/midsuit/form/MID_WCreateFromShipment.java @@ -64,7 +64,7 @@ import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Space; import org.zkoss.zul.Vlayout; -public class MID_WCreateFromShipment extends CreateFromShipment implements EventListener, ValueChangeListener +public class MID_WCreateFromShipment extends MID_CreateFromShipment implements EventListener, ValueChangeListener { private WCreateFromWindow window; @@ -221,7 +221,7 @@ public class MID_WCreateFromShipment extends CreateFromShipment implements Event } } - private boolean m_actionActive = false; + private boolean m_actionActive = false; /** * Action Listener