KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > search > InfoProduct


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps.search;
15
16 import java.awt.*;
17 import java.awt.event.ActionEvent JavaDoc;
18 import java.awt.event.ActionListener JavaDoc;
19 import java.math.BigDecimal JavaDoc;
20 import java.sql.PreparedStatement JavaDoc;
21 import java.sql.ResultSet JavaDoc;
22 import java.sql.SQLException JavaDoc;
23 import java.sql.Timestamp JavaDoc;
24
25 import org.compiere.apps.AEnv;
26 import org.compiere.apps.*;
27 import org.compiere.grid.ed.VComboBox;
28 import org.compiere.minigrid.IDColumn;
29 import org.compiere.model.*;
30 import org.compiere.plaf.CompierePLAF;
31 import org.compiere.swing.CButton;
32 import org.compiere.swing.CLabel;
33 import org.compiere.swing.CTextField;
34 import org.compiere.util.Access;
35 import org.compiere.util.DB;
36 import org.compiere.util.Env;
37 import org.compiere.util.KeyNamePair;
38 import org.compiere.util.Log;
39 import org.compiere.util.Msg;
40 import org.compiere.util.Util;
41
42 /**
43  * Search Product and return selection
44  *
45  * @author Jorg Janke
46  * @version $Id: InfoProduct.java,v 1.20 2003/10/27 15:22:03 jjanke Exp $
47  */

48 public final class InfoProduct extends Info implements ActionListener JavaDoc
49 {
50     /**
51      * Standard Constructor
52
53      * @param frame frame
54      * @param modal modal
55      * @param WindowNo window no
56      * @param M_Warehouse_ID warehouse
57      * @param M_PriceList_ID price list
58      * @param value Query Value or Name if enclosed in @
59      * @param multiSelection multiple selections
60      * @param whereClause where clause
61      */

62     public InfoProduct(Frame frame, boolean modal, int WindowNo,
63         int M_Warehouse_ID, int M_PriceList_ID, String JavaDoc value,
64         boolean multiSelection, String JavaDoc whereClause)
65     {
66         super (frame, modal, WindowNo, "p", "M_Product_ID", multiSelection, whereClause);
67         Log.trace(Log.l1_User, "InfoProduct", value + ", Wh=" + M_Warehouse_ID + ", PL=" + M_PriceList_ID + ", WHERE=" + whereClause);
68         setTitle(Msg.getMsg(Env.getCtx(), "InfoProduct"));
69         //
70
statInit();
71         initInfo (value, M_Warehouse_ID, M_PriceList_ID);
72         //
73
int no = p_table.getRowCount();
74         setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
75         setStatusDB(Integer.toString(no));
76         // AutoQuery
77
if (value != null && value.length() > 0)
78             executeQuery();
79         p_loadedOK = true;
80         // Focus
81
fieldValue.requestFocus();
82
83         AEnv.positionCenterWindow(frame, this);
84     } // InfoProduct
85

86     private static final String JavaDoc s_productFrom =
87         "M_Product p"
88         + " INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID)"
89         + " LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID)";
90
91     /** Array of Column Info */
92     private static final Info_Column[] s_productLayout = {
93         new Info_Column(" ", "p.M_Product_ID", IDColumn.class),
94         new Info_Column(Msg.translate(Env.getCtx(), "Discontinued").substring(0, 1), "p.Discontinued", Boolean JavaDoc.class),
95         new Info_Column(Msg.translate(Env.getCtx(), "Value"), "p.Value", String JavaDoc.class),
96         new Info_Column(Msg.translate(Env.getCtx(), "Name"), "p.Name", String JavaDoc.class),
97         new Info_Column(Msg.translate(Env.getCtx(), "QtyAvailable"), "BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable", Double JavaDoc.class, true, true, null),
98         new Info_Column(Msg.translate(Env.getCtx(), "PriceList"), "BOM_PriceList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList", BigDecimal JavaDoc.class),
99         new Info_Column(Msg.translate(Env.getCtx(), "PriceStd"), "BOM_PriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd", BigDecimal JavaDoc.class),
100         new Info_Column(Msg.translate(Env.getCtx(), "QtyOnHand"), "BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand", Double JavaDoc.class),
101         new Info_Column(Msg.translate(Env.getCtx(), "QtyReserved"), "BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved", Double JavaDoc.class),
102         new Info_Column(Msg.translate(Env.getCtx(), "QtyOrdered"), "BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered", Double JavaDoc.class),
103         new Info_Column(Msg.translate(Env.getCtx(), "Margin"), "BOM_PriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-BOM_PriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin", BigDecimal JavaDoc.class),
104         new Info_Column(Msg.translate(Env.getCtx(), "PriceLimit"), "BOM_PriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit", BigDecimal JavaDoc.class),
105         new Info_Column(Msg.translate(Env.getCtx(), "IsInstanceAttribute"), "pa.IsInstanceAttribute", Boolean JavaDoc.class)
106     };
107     static int INDEX_NAME = 3;
108     static int INDEX_PATTRIBUTE = 12;
109
110     //
111
private CLabel labelValue = new CLabel();
112     private CTextField fieldValue = new CTextField(10);
113     private CLabel labelName = new CLabel();
114     private CTextField fieldName = new CTextField(10);
115     private CLabel labelUPC = new CLabel();
116     private CTextField fieldUPC = new CTextField(10);
117     private CLabel labelSKU = new CLabel();
118     private CTextField fieldSKU = new CTextField(10);
119     private CLabel labelPriceList = new CLabel();
120     private VComboBox pickPriceList = new VComboBox();
121     private CLabel labelWarehouse = new CLabel();
122     private VComboBox pickWarehouse = new VComboBox();
123
124     /** Search Button */
125     private CButton m_InfoPAttributeButton = new CButton(Env.getImageIcon("PAttribute16.gif"));
126     /** Instance Button */
127     private CButton m_PAttributeButton = null;
128     private int m_M_AttributeSetInstance_ID = -1;
129
130     private String JavaDoc m_pAttributeWhere = null;
131
132     /**
133      * Static Setup - add fields to parameterPanel
134      */

135     private void statInit()
136     {
137         labelValue.setText(Msg.getMsg(Env.getCtx(), "Value"));
138         fieldValue.setBackground(CompierePLAF.getInfoBackground());
139         fieldValue.addActionListener(this);
140         
141         labelName.setText(Msg.getMsg(Env.getCtx(), "Name"));
142         fieldName.setBackground(CompierePLAF.getInfoBackground());
143         fieldName.addActionListener(this);
144
145         labelUPC.setText(Msg.translate(Env.getCtx(), "UPC"));
146         fieldUPC.setBackground(CompierePLAF.getInfoBackground());
147         fieldUPC.addActionListener(this);
148
149         labelSKU.setText(Msg.translate(Env.getCtx(), "SKU"));
150         fieldSKU.setBackground(CompierePLAF.getInfoBackground());
151         fieldSKU.addActionListener(this);
152         
153         labelWarehouse.setText(Msg.getMsg(Env.getCtx(), "Warehouse"));
154         pickWarehouse.setBackground(CompierePLAF.getInfoBackground());
155         
156         labelPriceList.setText(Msg.getMsg(Env.getCtx(), "PriceListVersion"));
157         pickPriceList.setBackground(CompierePLAF.getInfoBackground());
158
159         m_InfoPAttributeButton.setMargin(new Insets(2,2,2,2));
160         m_InfoPAttributeButton.setToolTipText(Msg.getMsg(Env.getCtx(), "InfoPAttribute"));
161         m_InfoPAttributeButton.addActionListener(this);
162
163         // Line 1
164
parameterPanel.setLayout(new ALayout());
165         parameterPanel.add(labelValue, new ALayoutConstraint(0,0));
166         parameterPanel.add(fieldValue, null);
167         parameterPanel.add(labelUPC, null);
168         parameterPanel.add(fieldUPC, null);
169         parameterPanel.add(labelWarehouse, null);
170         parameterPanel.add(pickWarehouse, null);
171         parameterPanel.add(m_InfoPAttributeButton);
172         // Line 2
173
parameterPanel.add(labelName, new ALayoutConstraint(1,0));
174         parameterPanel.add(fieldName, null);
175         parameterPanel.add(labelSKU, null);
176         parameterPanel.add(fieldSKU, null);
177         parameterPanel.add(labelPriceList, null);
178         parameterPanel.add(pickPriceList, null);
179         
180         // Product Attribute Instance
181
m_PAttributeButton = ConfirmPanel.createPAttributeButton(true);
182         confirmPanel.addButton(m_PAttributeButton);
183         m_PAttributeButton.addActionListener(this);
184         m_PAttributeButton.setEnabled(false);
185     } // statInit
186

187     /**
188      * Dynamic Init
189      *
190      * @param value value
191      * @param M_Warehouse_ID warehouse
192      * @param M_PriceList_ID price list
193      */

194     private void initInfo (String JavaDoc value, int M_Warehouse_ID, int M_PriceList_ID)
195     {
196         // Pick init
197
fillPicks(M_PriceList_ID);
198         int M_PriceList_Version_ID = findPLV (M_PriceList_ID);
199         // Set Value or Name
200
if (value.startsWith("@") && value.endsWith("@"))
201             fieldName.setText(value.substring(1,value.length()-1));
202         else
203             fieldValue.setText(value);
204         // Set Warehouse
205
if (M_Warehouse_ID == 0)
206             M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), "#M_Warehouse_ID");
207         if (M_Warehouse_ID != 0)
208             setWarehouse (M_Warehouse_ID);
209         // Set PriceList Version
210
if (M_PriceList_Version_ID != 0)
211             setPriceListVersion (M_PriceList_Version_ID);
212
213         // Create Grid
214
StringBuffer JavaDoc where = new StringBuffer JavaDoc();
215         where.append("p.IsSummary='N' AND p.IsActive='Y' AND pr.IsActive='Y'");
216         // dynamic Where Clause
217
if (p_whereClause != null && p_whereClause.length() > 0)
218             where.append(" AND ") // replace fully qalified name with alias
219
.append(Util.replace(p_whereClause, "M_Product.", "p."));
220         //
221
prepareTable(getProductLayout(),
222             s_productFrom,
223             where.toString(),
224             "QtyAvailable DESC, Margin DESC");
225
226         //
227
pickWarehouse.addActionListener(this);
228         pickPriceList.addActionListener(this);
229     } // initInfo
230

231     /**
232      * Fill Picks with values
233      *
234      * @param M_PriceList_ID price list
235      */

236     private void fillPicks (int M_PriceList_ID)
237     {
238         // Price List
239
String JavaDoc SQL = "SELECT M_PriceList_Version.M_PriceList_Version_ID,"
240             + " M_PriceList_Version.Name || ' (' || c.Iso_Code || ')' AS ValueName "
241             + "FROM M_PriceList_Version, M_PriceList pl, C_Currency c "
242             + "WHERE M_PriceList_Version.M_PriceList_ID=pl.M_PriceList_ID"
243             + " AND pl.C_Currency_ID=c.C_Currency_ID"
244             + " AND M_PriceList_Version.IsActive='Y' AND pl.IsActive='Y'";
245         // Same PL currency as original one
246
if (M_PriceList_ID != 0)
247             SQL += " AND EXISTS (SELECT * FROM M_PriceList xp WHERE xp.M_PriceList_ID=" + M_PriceList_ID
248                 + " AND pl.C_Currency_ID=xp.C_Currency_ID)";
249         // Add Access & Order
250
SQL = MRole.getDefault().addAccessSQL (SQL, "M_PriceList_Version", true, false) // fully qualidfied - RO
251
+ " ORDER BY M_PriceList_Version.Name";
252         try
253         {
254             PreparedStatement JavaDoc pstmt = DB.prepareStatement(SQL);
255             ResultSet JavaDoc rs = pstmt.executeQuery();
256             while (rs.next())
257             {
258                 KeyNamePair kn = new KeyNamePair (rs.getInt(1), rs.getString(2));
259                 pickPriceList.addItem(kn);
260             }
261             rs.close();
262             pstmt.close();
263
264             // Warehouse
265
SQL = MRole.getDefault().addAccessSQL (
266                 "SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName "
267                 + "FROM M_Warehouse "
268                 + "WHERE IsActive='Y'",
269                     "M_Warehouse", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO)
270                 + " ORDER BY Value";
271             pstmt = DB.prepareStatement(SQL);
272             rs = pstmt.executeQuery();
273             while (rs.next())
274             {
275                 KeyNamePair kn = new KeyNamePair
276                     (rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
277                 pickWarehouse.addItem(kn);
278             }
279             rs.close();
280             pstmt.close();
281         }
282         catch (SQLException JavaDoc e)
283         {
284             Log.error ("InfoProduct.fillPicks", e);
285             setStatusLine(e.getLocalizedMessage(), true);
286         }
287     } // fillPicks
288

289     /**
290      * Set Warehouse
291      *
292      * @param M_Warehouse_ID warehouse
293      */

294     private void setWarehouse(int M_Warehouse_ID)
295     {
296         for (int i = 0; i < pickWarehouse.getItemCount(); i++)
297         {
298             KeyNamePair kn = (KeyNamePair)pickWarehouse.getItemAt(i);
299             if (kn.getKey() == M_Warehouse_ID)
300             {
301                 pickWarehouse.setSelectedIndex(i);
302                 return;
303             }
304         }
305     } // setWarehouse
306

307     /**
308      * Set PriceList
309      *
310      * @param M_PriceList_Version_ID price list
311      */

312     private void setPriceListVersion(int M_PriceList_Version_ID)
313     {
314         Log.trace(Log.l3_Util, "InfoProduct.setPriceListVersion - " + M_PriceList_Version_ID);
315         for (int i = 0; i < pickPriceList.getItemCount(); i++)
316         {
317             KeyNamePair kn = (KeyNamePair)pickPriceList.getItemAt(i);
318             if (kn.getKey() == M_PriceList_Version_ID)
319             {
320                 pickPriceList.setSelectedIndex(i);
321                 return;
322             }
323         }
324         Log.trace(Log.l5_DData, "NOT found");
325     } // setPriceList
326

327     /**
328      * Find Price List Version and update context
329      *
330      * @param M_PriceList_ID price list
331      * @return M_PriceList_Version_ID price list version
332      */

333     private int findPLV (int M_PriceList_ID)
334     {
335         Log.trace(Log.l3_Util, "InfoProduct.findPLV - " + M_PriceList_ID);
336         int retValue = 0;
337         String JavaDoc SQL = "SELECT plv.M_PriceList_Version_ID, plv.ValidFrom "
338             + "FROM M_PriceList pl, M_PriceList_Version plv "
339             + "WHERE pl.M_PriceList_ID=plv.M_PriceList_ID"
340             + " AND plv.IsActive='Y'"
341             + " AND pl.M_PriceList_ID=? " // 1
342
+ "ORDER BY plv.ValidFrom DESC";
343         // find newest one
344
try
345         {
346             PreparedStatement JavaDoc pstmt = DB.prepareStatement(SQL);
347             pstmt.setInt(1, M_PriceList_ID);
348             ResultSet JavaDoc rs = pstmt.executeQuery();
349             Timestamp JavaDoc docDate = new Timestamp JavaDoc(System.currentTimeMillis());
350             while (rs.next() && retValue == 0)
351             {
352                 Timestamp JavaDoc vf = rs.getTimestamp(2);
353                 if (!vf.after(docDate))
354                     retValue = rs.getInt(1);
355             }
356             rs.close();
357             pstmt.close();
358         }
359         catch (SQLException JavaDoc e)
360         {
361             Log.error ("InfoProduct.findPLV", e);
362         }
363         Env.setContext(Env.getCtx(), p_WindowNo, "M_PriceList_Version_ID", retValue);
364         return retValue;
365     } // findPLV
366

367     /*************************************************************************/
368
369     /**
370      * Construct SQL Where Clause and define parameters
371      * (setParameters needs to set parameters)
372      * Includes first AND
373      * @return SQL WHERE clause
374      */

375     String JavaDoc getSQLWhere()
376     {
377         StringBuffer JavaDoc where = new StringBuffer JavaDoc(" AND pr.M_PriceList_Version_ID=?");
378         // Product Attribute Search
379
if (m_pAttributeWhere != null)
380         {
381             where.append(m_pAttributeWhere);
382             return where.toString();
383         }
384
385         // => Value
386
String JavaDoc value = fieldValue.getText().toUpperCase();
387         if (!(value.equals("") || value.equals("%")))
388             where.append(" AND UPPER(p.Value) LIKE ?");
389
390         // => Name
391
String JavaDoc name = fieldName.getText().toUpperCase();
392         if (!(name.equals("") || name.equals("%")))
393             where.append(" AND UPPER(p.Name) LIKE ?");
394
395         // => UPC
396
String JavaDoc upc = fieldUPC.getText().toUpperCase();
397         if (!(upc.equals("") || upc.equals("%")))
398             where.append(" AND UPPER(p.UPC) LIKE ?");
399
400         // => SKU
401
String JavaDoc sku = fieldSKU.getText().toUpperCase();
402         if (!(sku.equals("") || sku.equals("%")))
403             where.append(" AND UPPER(p.SKU) LIKE ?");
404
405         return where.toString();
406     } // getSQLWhere
407

408     /**
409      * Set Parameters for Query
410      * (as defined in getSQLWhere)
411      *
412      * @param pstmt pstmt
413      * @throws SQLException
414      * @see org.compiere.apps.search.Info#setParameters(java.sql.PreparedStatement)
415      */

416     void setParameters(PreparedStatement JavaDoc pstmt) throws SQLException JavaDoc
417     {
418         int index = 1;
419
420         // => Warehouse
421
int M_Warehouse_ID = 0;
422         KeyNamePair wh = (KeyNamePair)pickWarehouse.getSelectedItem();
423         if (wh != null)
424             M_Warehouse_ID = wh.getKey();
425         for (int i = 0; i < p_layout.length; i++)
426         {
427             if (p_layout[i].getColSQL().indexOf("?") != -1)
428                 pstmt.setInt(index++, M_Warehouse_ID);
429         }
430         Log.trace(Log.l5_DData, "InfoProduct.setParameters", "M_Warehouse_ID=" + M_Warehouse_ID + " (" + (index-1) + "*)");
431
432         // => PriceList
433
int M_PriceList_Version_ID = 0;
434         KeyNamePair pl = (KeyNamePair)pickPriceList.getSelectedItem();
435         if (pl != null)
436             M_PriceList_Version_ID = pl.getKey();
437         pstmt.setInt(index++, M_PriceList_Version_ID);
438         Log.trace(Log.l5_DData, "InfoProduct.setParameters", "M_PriceList_Version_ID=" + M_PriceList_Version_ID);
439
440         // Rest of Parameter in Query for Attribute Search
441
if (m_pAttributeWhere != null)
442             return;
443
444         // => Value
445
String JavaDoc value = fieldValue.getText().toUpperCase();
446         if (!(value.equals("") || value.equals("%")))
447         {
448             if (!value.endsWith("%"))
449                 value += "%";
450             pstmt.setString(index++, value);
451             Log.trace(Log.l5_DData, "InfoProduct.setParameters", "Value: " + value);
452         }
453
454         // => Name
455
String JavaDoc name = fieldName.getText().toUpperCase();
456         if (!(name.equals("") || name.equals("%")))
457         {
458             if (!name.endsWith("%"))
459                 name += "%";
460             pstmt.setString(index++, name);
461             Log.trace(Log.l5_DData, "InfoProduct.setParameters", "Name: " + name);
462         }
463
464         // => UPC
465
String JavaDoc upc = fieldUPC.getText().toUpperCase();
466         if (!(upc.equals("") || upc.equals("%")))
467         {
468             if (!upc.endsWith("%"))
469                 upc += "%";
470             pstmt.setString(index++, upc);
471             Log.trace(Log.l5_DData, "InfoProduct.setParameters", "UPC: " + upc);
472         }
473
474         // => SKU
475
String JavaDoc sku = fieldSKU.getText().toUpperCase();
476         if (!(sku.equals("") || sku.equals("%")))
477         {
478             if (!sku.endsWith("%"))
479                 sku += "%";
480             pstmt.setString(index++, sku);
481             Log.trace(Log.l5_DData, "InfoProduct.setParameters", "SKU: " + sku);
482         }
483
484     } // setParameters
485

486     /*************************************************************************/
487
488     /**
489      * Action Listner
490      *
491      * @param e event
492      */

493     public void actionPerformed (ActionEvent JavaDoc e)
494     {
495         // don't requery if fieldValue and fieldName are empty
496
if ((e.getSource() == pickWarehouse || e.getSource() == pickPriceList)
497             && (fieldValue.getText().length() == 0 && fieldName.getText().length() == 0))
498             return;
499             
500         // Product Attribute Search
501
if (e.getSource().equals(m_InfoPAttributeButton))
502         {
503             cmd_InfoPAttribute();
504             return;
505         }
506         m_pAttributeWhere = null;
507         
508         // Query Product Attribure Instance
509
int row = p_table.getSelectedRow();
510         if (e.getSource().equals(m_PAttributeButton) && row != -1)
511         {
512             Integer JavaDoc productInteger = getSelectedRowKey();
513             String JavaDoc productName = (String JavaDoc)p_table.getValueAt(row, INDEX_NAME);
514             KeyNamePair product = new KeyNamePair (productInteger.intValue(), productName);
515             KeyNamePair warehouse = (KeyNamePair)pickWarehouse.getSelectedItem();
516             if (product == null || warehouse == null)
517                 return;
518             PAttributeInstance pai = new PAttributeInstance (this, warehouse, product);
519             m_M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
520             if (m_M_AttributeSetInstance_ID != -1)
521                 dispose(true);
522             return;
523         }
524         //
525
super.actionPerformed(e);
526     } // actionPerformed
527

528     /**
529      * Enable PAttribute if row selected/changed
530      */

531     void enableButtons ()
532     {
533         m_M_AttributeSetInstance_ID = -1;
534         if (m_PAttributeButton != null)
535         {
536             int row = p_table.getSelectedRow();
537             boolean enabled = false;
538             if (row >= 0)
539             {
540                 Object JavaDoc value = p_table.getValueAt(row, INDEX_PATTRIBUTE);
541                 enabled = Boolean.TRUE.equals(value);
542             }
543             m_PAttributeButton.setEnabled(enabled);
544         }
545         super.enableButtons();
546     } // enableButtons
547

548     /**
549      * Query per Product Attribute.
550      * <code>
551      * Available synonyms:
552      * M_Product p
553      * M_ProductPrice pr
554      * M_AttributeSet pa
555      * </code>
556      */

557     private void cmd_InfoPAttribute()
558     {
559         InfoPAttribute ia = new InfoPAttribute(this);
560         m_pAttributeWhere = ia.getWhereClause();
561         if (m_pAttributeWhere != null)
562             executeQuery();
563     } // cmdInfoAttribute
564

565     /**
566      * Show History
567      */

568     void showHistory()
569     {
570         Log.trace(Log.l1_User, "InfoProduct.showHistory");
571         Integer JavaDoc M_Product_ID = getSelectedRowKey();
572         if (M_Product_ID == null)
573             return;
574
575         InvoiceHistory ih = new InvoiceHistory (this, 0, M_Product_ID.intValue());
576         ih.setVisible(true);
577         ih = null;
578     } // showHistory
579

580     /**
581      * Has History
582      *
583      * @return true (has history)
584      */

585     boolean hasHistory()
586     {
587         return true;
588     } // hasHistory
589

590     /**
591      * Zoom
592      */

593     void zoom()
594     {
595         Log.trace(Log.l1_User, "InfoProduct.zoom");
596         Integer JavaDoc M_Product_ID = getSelectedRowKey();
597         if (M_Product_ID == null)
598             return;
599         MQuery query = new MQuery("M_Product");
600         query.addRestriction("M_Product_ID", MQuery.EQUAL, M_Product_ID);
601         zoom (140, query); // HARDCODED
602
} // zoom
603

604     /**
605      * Has Zoom
606      * @return (has zoom)
607      */

608     boolean hasZoom()
609     {
610         return true;
611     } // hasZoom
612

613     /**
614      * Customize
615      */

616     void customize()
617     {
618         Log.trace(Log.l1_User, "InfoProduct.customize");
619     } // customize
620

621     /**
622      * Has Customize
623      * @return false (no customize)
624      */

625     boolean hasCustomize()
626     {
627         return false; // for now
628
} // hasCustomize
629

630     /**
631      * Save Selection Settings for PriceList
632      */

633     void saveSelectionDetail()
634     {
635         // publish for Callout to read
636
Integer JavaDoc ID = getSelectedRowKey();
637         Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "M_Product_ID", ID == null ? "0" : ID.toString());
638         KeyNamePair kn = (KeyNamePair)pickPriceList.getSelectedItem();
639         Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "M_PriceList_Version_ID", kn.getID());
640         kn = (KeyNamePair)pickWarehouse.getSelectedItem();
641         Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "M_Warehouse_ID", kn.getID());
642         //
643
if (m_M_AttributeSetInstance_ID == -1) // not selected
644
Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID", "0");
645         else
646             Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID", String.valueOf(m_M_AttributeSetInstance_ID));
647     } // saveSelectionDetail
648

649     /**
650      * Get Product Layout
651      *
652      * @return array of Column_Info
653      */

654     private Info_Column[] getProductLayout()
655     {
656         // Euro 13
657
if (Env.getContext(Env.getCtx(), "#Client_Value").equals("FRIE"))
658         {
659             final Info_Column[] frieLayout = {
660                 new Info_Column(" ", "p.M_Product_ID", IDColumn.class),
661         // new Info_Column(Msg.translate(Env.getCtx(), "Value"), "p.Value", String.class),
662
new Info_Column(Msg.translate(Env.getCtx(), "Name"), "p.Name", String JavaDoc.class),
663                 new Info_Column(Msg.translate(Env.getCtx(), "QtyAvailable"), "BOM_Qty_Available(p.M_Product_ID,?) AS QtyAvailable", Double JavaDoc.class, true, true, null),
664                 new Info_Column(Msg.translate(Env.getCtx(), "PriceList"), "BOM_PriceList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList", BigDecimal JavaDoc.class),
665                 new Info_Column(Msg.translate(Env.getCtx(), "PriceStd"), "BOM_PriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd", BigDecimal JavaDoc.class),
666                 new Info_Column("Einzel MWSt", "pr.PriceStd * 1.16", BigDecimal JavaDoc.class),
667                 new Info_Column("Einzel kompl", "(pr.PriceStd+13) * 1.16", BigDecimal JavaDoc.class),
668                 new Info_Column("Satz kompl", "(pr.PriceStd+13) * 4 * 1.16", BigDecimal JavaDoc.class),
669                 new Info_Column(Msg.translate(Env.getCtx(), "QtyOnHand"), "BOM_Qty_OnHand(p.M_Product_ID,?) AS QtyOnHand", Double JavaDoc.class),
670                 new Info_Column(Msg.translate(Env.getCtx(), "QtyReserved"), "BOM_Qty_Reserved(p.M_Product_ID,?) AS QtyReserved", Double JavaDoc.class),
671                 new Info_Column(Msg.translate(Env.getCtx(), "QtyOrdered"), "BOM_Qty_Ordered(p.M_Product_ID,?) AS QtyOrdered", Double JavaDoc.class),
672                 new Info_Column(Msg.translate(Env.getCtx(), "Discontinued").substring(0, 1), "p.Discontinued", Boolean JavaDoc.class),
673                 new Info_Column(Msg.translate(Env.getCtx(), "Margin"), "BOM_PriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-BOM_PriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin", BigDecimal JavaDoc.class),
674                 new Info_Column(Msg.translate(Env.getCtx(), "PriceLimit"), "BOM_PriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit", BigDecimal JavaDoc.class),
675                 new Info_Column(Msg.translate(Env.getCtx(), "IsInstanceAttribute"), "pa.IsInstanceAttribute", Boolean JavaDoc.class)
676             };
677             INDEX_NAME = 2;
678             INDEX_PATTRIBUTE = 14;
679             return frieLayout;
680         }
681         return s_productLayout;
682     } // getProductLayout
683

684 } // InfoProduct
685
Popular Tags