1 14 package org.compiere.grid; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 import javax.swing.table.*; 20 import javax.swing.event.*; 21 22 import java.sql.*; 23 import java.util.*; 24 import java.beans.*; 25 import java.math.*; 26 import java.text.*; 27 28 import org.compiere.util.*; 29 import org.compiere.model.*; 30 import org.compiere.apps.*; 31 import org.compiere.grid.ed.*; 32 import org.compiere.minigrid.*; 33 import org.compiere.plaf.*; 34 import org.compiere.swing.*; 35 36 42 public abstract class VCreateFrom extends JDialog 43 implements ActionListener, TableModelListener 44 { 45 50 public static VCreateFrom create (MTab mTab) 51 { 52 int AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), "BaseTable_ID"); 54 55 VCreateFrom retValue = null; 56 if (AD_Table_ID == 392) retValue = new VCreateFromStatement (mTab); 58 else if (AD_Table_ID == 318) retValue = new VCreateFromInvoice (mTab); 60 else if (AD_Table_ID == 319) retValue = new VCreateFromShipment (mTab); 62 else if (AD_Table_ID == 426) return null; else { 66 Log.error("VCreateFrom.create - Unsupported Table=" + AD_Table_ID); 67 return null; 68 } 69 return retValue; 70 } 72 73 74 78 VCreateFrom (MTab mTab) 79 { 80 super(Env.getWindow(mTab.getWindowNo()), true); 81 Log.trace(Log.l1_User, "VCreateFrom"); 82 p_WindowNo = mTab.getWindowNo(); 83 p_mTab = mTab; 84 85 try 86 { 87 if (!dynInit()) 88 return; 89 jbInit(); 90 confirmPanel.addActionListener(this); 91 statusBar.setStatusDB(""); 93 tableChanged(null); 94 p_initOK = true; 95 } 96 catch(Exception e) 97 { 98 Log.error("VCreateFrom", e); 99 p_initOK = false; 100 } 101 AEnv.positionCenterWindow(Env.getWindow(p_WindowNo), this); 102 } 104 105 protected int p_WindowNo; 106 107 protected MTab p_mTab; 108 109 private boolean p_initOK = false; 110 111 112 protected int p_C_Order_ID = 0; 113 114 private CPanel parameterPanel = new CPanel(); 116 protected CPanel parameterBankPanel = new CPanel(); 117 private BorderLayout parameterLayout = new BorderLayout(); 118 private JLabel bankAccountLabel = new JLabel(); 119 protected CPanel parameterStdPanel = new CPanel(); 120 private JLabel bPartnerLabel = new JLabel(); 121 protected VLookup bankAccountField; 122 private GridBagLayout parameterStdLayout = new GridBagLayout(); 123 private GridBagLayout parameterBankLayout = new GridBagLayout(); 124 protected VLookup bPartnerField; 125 private JLabel orderLabel = new JLabel(); 126 protected JComboBox orderField = new JComboBox(); 127 protected JLabel invoiceLabel = new JLabel(); 128 protected JComboBox invoiceField = new JComboBox(); 129 protected JLabel shipmentLabel = new JLabel(); 130 protected JComboBox shipmentField = new JComboBox(); 131 private JScrollPane dataPane = new JScrollPane(); 132 private CPanel southPanel = new CPanel(); 133 private BorderLayout southLayout = new BorderLayout(); 134 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 135 protected StatusBar statusBar = new StatusBar(); 136 protected MiniTable dataTable = new MiniTable(); 137 protected JLabel locatorLabel = new JLabel(); 138 protected VLocator locatorField = new VLocator(); 139 140 154 private void jbInit() throws Exception 155 { 156 CompiereColor.setBackground(this); 157 parameterPanel.setLayout(parameterLayout); 158 parameterStdPanel.setLayout(parameterStdLayout); 159 parameterBankPanel.setLayout(parameterBankLayout); 160 bankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); 162 bPartnerLabel.setText(Msg.getElement(Env.getCtx(), "C_BPartner_ID")); 163 orderLabel.setText(Msg.getElement(Env.getCtx(), "C_Order_ID", false)); 164 invoiceLabel.setText(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); 165 shipmentLabel.setText(Msg.getElement(Env.getCtx(), "M_InOut_ID", false)); 166 locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID")); 167 this.getContentPane().add(parameterPanel, BorderLayout.NORTH); 169 parameterPanel.add(parameterBankPanel, BorderLayout.NORTH); 170 parameterBankPanel.add(bankAccountLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 171 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 172 if (bankAccountField != null) 173 parameterBankPanel.add(bankAccountField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 174 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); 175 parameterPanel.add(parameterStdPanel, BorderLayout.CENTER); 176 parameterStdPanel.add(bPartnerLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 177 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 178 if (bPartnerField != null) 179 parameterStdPanel.add(bPartnerField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 180 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); 181 parameterStdPanel.add(orderLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0 182 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 183 parameterStdPanel.add(orderField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0 184 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); 185 parameterStdPanel.add(invoiceLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 186 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 187 parameterStdPanel.add(invoiceField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 188 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); 189 parameterStdPanel.add(shipmentLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 190 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 191 parameterStdPanel.add(shipmentField, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0 192 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); 193 parameterStdPanel.add(locatorLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 194 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 195 parameterStdPanel.add(locatorField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 196 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0)); 197 this.getContentPane().add(dataPane, BorderLayout.CENTER); 198 dataPane.getViewport().add(dataTable, null); 199 this.getContentPane().add(southPanel, BorderLayout.SOUTH); 201 southPanel.setLayout(southLayout); 202 southPanel.add(confirmPanel, BorderLayout.CENTER); 203 southPanel.add(statusBar, BorderLayout.SOUTH); 204 } 206 210 public boolean isInitOK() 211 { 212 return p_initOK; 213 } 215 220 abstract boolean dynInit() throws Exception ; 221 222 226 abstract void initBPDetails(int C_BPartner_ID); 227 228 231 abstract void info(); 232 233 237 abstract boolean save(); 238 239 240 241 245 public void actionPerformed(ActionEvent e) 246 { 247 Log.trace(Log.l3_Util, "VCreateFrom.actionPerformed " + e.getActionCommand()); 248 252 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 254 { 255 if (save()) 256 dispose(); 257 } 258 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 260 { 261 dispose(); 262 } 263 } 266 270 public void tableChanged (TableModelEvent e) 271 { 272 int type = -1; 273 if (e != null) 274 { 275 type = e.getType(); 276 if (type != TableModelEvent.UPDATE) 277 return; 278 } 279 Log.trace(Log.l3_Util, "VCreateFrom.tableChanged " + type); 280 info(); 281 } 283 284 285 290 protected void initBPartner (boolean forInvoice) throws Exception 291 { 292 int AD_Column_ID = 3499; MLookup lookup = MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.Search); 295 bPartnerField = new VLookup ("C_BPartner_ID", true, false, true, 296 lookup, DisplayType.Search, p_WindowNo); 297 int C_BPartner_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BPartner_ID"); 299 bPartnerField.setValue(new Integer (C_BPartner_ID)); 300 301 initBPartnerOIS(C_BPartner_ID, forInvoice); 303 } 305 310 protected void initBPartnerOIS (int C_BPartner_ID, boolean forInvoice) 311 { 312 Log.trace(Log.l3_Util, "VCreateFrom.initBPartnerOIS BPartner=" + C_BPartner_ID); 313 KeyNamePair pp = new KeyNamePair(0,""); 314 315 orderField.removeActionListener(this); 317 orderField.removeAllItems(); 318 orderField.addItem(pp); 319 StringBuffer display = new StringBuffer ("o.DocumentNo||' - ' ||") 321 .append(DB.TO_CHAR("o.DateOrdered", DisplayType.Date, Env.getAD_Language(Env.getCtx()))) 322 .append("||' - '||") 323 .append(DB.TO_CHAR("o.GrandTotal", DisplayType.Amount, Env.getAD_Language(Env.getCtx()))); 324 String column = "m.M_InOutLine_ID"; 326 if (forInvoice) 327 column = "m.C_InvoiceLine_ID"; 328 StringBuffer sql = new StringBuffer ("SELECT o.C_Order_ID,").append(display) 329 .append(" FROM C_Order o " 330 + "WHERE o.C_BPartner_ID=? AND o.IsSOTrx='N' AND o.DocStatus IN ('CL','CO')" 331 + " AND o.C_Order_ID IN " 332 + "(SELECT ol.C_Order_ID FROM C_OrderLine ol" 333 + " LEFT OUTER JOIN M_MatchPO m ON (ol.C_OrderLine_ID=m.C_OrderLine_ID) " 334 + "GROUP BY ol.C_Order_ID,ol.C_OrderLine_ID, ol.QtyOrdered,").append(column) 335 .append(" HAVING (ol.QtyOrdered <> SUM(m.Qty) AND ").append(column) 336 .append(" IS NOT NULL) OR ").append(column).append(" IS NULL) " 337 + "ORDER BY o.DateOrdered"); 338 try 339 { 340 PreparedStatement pstmt = DB.prepareStatement(sql.toString()); 341 pstmt.setInt(1, C_BPartner_ID); 342 ResultSet rs = pstmt.executeQuery(); 343 while (rs.next()) 344 { 345 pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); 346 orderField.addItem(pp); 347 } 348 rs.close(); 349 pstmt.close(); 350 } 351 catch (SQLException e) 352 { 353 Log.error ("VCreateFrom.initIOS - Order\nSQL=" + sql.toString(), e); 354 } 355 orderField.setSelectedIndex(0); 356 orderField.addActionListener(this); 357 358 initBPDetails(C_BPartner_ID); 359 } 361 366 protected void loadOrder (int C_Order_ID, boolean forInvoice) 367 { 368 377 Log.trace(Log.l3_Util, "VCreateFrom.loadOrder - " + C_Order_ID); 378 p_C_Order_ID = C_Order_ID; 380 Vector data = new Vector(); 381 StringBuffer sql = new StringBuffer ("SELECT l.QtyOrdered-SUM(NVL(m.Qty,0))," 382 + " l.C_UOM_ID, uom.UOMSymbol," + " COALESCE(l.M_Product_ID,0),COALESCE(p.Name,c.Name)," + " l.C_OrderLine_ID,l.Line " + "FROM C_OrderLine l" 386 + " LEFT OUTER JOIN M_MatchPO m ON (l.C_OrderLine_ID=m.C_OrderLine_ID AND "); 387 sql.append(forInvoice ? "m.C_InvoiceLine_ID" : "m.M_InOutLine_ID"); 388 sql.append(" IS NOT NULL)") 389 .append(" LEFT OUTER JOIN M_Product p ON (l.M_Product_ID=p.M_Product_ID)" 390 + " LEFT OUTER JOIN C_Charge c ON (l.C_Charge_ID=c.C_Charge_ID)"); 391 if (Env.isBaseLanguage(Env.getCtx(), "C_UOM")) 392 sql.append(" LEFT OUTER JOIN C_UOM uom ON (l.C_UOM_ID=uom.C_UOM_ID)"); 393 else 394 sql.append(" LEFT OUTER JOIN C_UOM_Trl uom ON (l.C_UOM_ID=uom.C_UOM_ID AND uom.AD_Language='") 395 .append(Env.getAD_Language(Env.getCtx())).append("')"); 396 sql.append(" WHERE l.C_Order_ID=? " + "GROUP BY l.QtyOrdered, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,p.Name,c.Name, l.Line,l.C_OrderLine_ID " 399 + "ORDER BY l.Line"); 400 Log.trace(Log.l6_Database, "VCreateFrom.loadOrder", sql); 402 try 403 { 404 PreparedStatement pstmt = DB.prepareStatement(sql.toString()); 405 pstmt.setInt(1, C_Order_ID); 406 ResultSet rs = pstmt.executeQuery(); 407 while (rs.next()) 408 { 409 Vector line = new Vector(); 410 line.add(new Boolean (false)); line.add(new Double (rs.getDouble(1))); KeyNamePair pp = new KeyNamePair(rs.getInt(2), rs.getString(3).trim()); 413 line.add(pp); pp = new KeyNamePair(rs.getInt(4), rs.getString(5)); 415 line.add(pp); pp = new KeyNamePair(rs.getInt(6), rs.getString(7)); 417 line.add(pp); line.add(null); line.add(null); data.add(line); 421 } 422 rs.close(); 423 pstmt.close(); 424 } 425 catch (SQLException e) 426 { 427 Log.error("VCreateFrom.loadOrder\nSQL=" + sql.toString(), e); 428 } 429 loadTableOIS (data); 430 } 432 433 437 protected void loadTableOIS (Vector data) 438 { 439 Vector columnNames = new Vector(7); 441 columnNames.add(Msg.getMsg(Env.getCtx(), "Select")); 442 columnNames.add(Msg.translate(Env.getCtx(), "Quantity")); 443 columnNames.add(Msg.translate(Env.getCtx(), "C_UOM_ID")); 444 columnNames.add(Msg.translate(Env.getCtx(), "M_Product_ID")); 445 columnNames.add(Msg.getElement(Env.getCtx(), "C_Order_ID", false)); 446 columnNames.add(Msg.getElement(Env.getCtx(), "M_InOut_ID", false)); 447 columnNames.add(Msg.getElement(Env.getCtx(), "C_Invoice_ID", false)); 448 449 dataTable.getModel().removeTableModelListener(this); 451 DefaultTableModel model = new DefaultTableModel(data, columnNames); 453 model.addTableModelListener(this); 454 dataTable.setModel(model); 455 dataTable.setColumnClass(0, Boolean .class, false); dataTable.setColumnClass(1, Double .class, true); dataTable.setColumnClass(2, String .class, true); dataTable.setColumnClass(3, String .class, true); dataTable.setColumnClass(4, String .class, true); dataTable.setColumnClass(5, String .class, true); dataTable.setColumnClass(6, String .class, true); dataTable.autoSize(); 465 } 467 } | Popular Tags |