KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
18
19 import javax.swing.*;
20 import javax.swing.event.*;
21 import javax.swing.table.*;
22
23 import java.sql.*;
24 import java.text.*;
25 import java.util.*;
26 import java.math.*;
27
28 import org.compiere.apps.*;
29 import org.compiere.grid.ed.*;
30 import org.compiere.minigrid.*;
31 import org.compiere.util.*;
32 import org.compiere.model.*;
33 import org.compiere.plaf.*;
34 import org.compiere.swing.*;
35
36 /**
37  * Info Order
38  *
39  * @author Jorg Janke
40  * @version $Id: InfoOrder.java,v 1.16 2003/10/17 06:15:56 jjanke Exp $
41  */

42 public class InfoOrder extends Info
43 {
44     /**
45      * Detail Protected Contructor
46      * @param frame parent frame
47      * @param modal modal
48      * @param WindowNo window no
49      * @param value query value
50      * @param multiSelection multiple selections
51      * @param whereClause where clause
52      */

53     protected InfoOrder(Frame frame, boolean modal, int WindowNo, String JavaDoc value,
54         boolean multiSelection, String JavaDoc whereClause)
55     {
56         super (frame, modal, WindowNo, "o", "C_Order_ID", multiSelection, whereClause);
57         Log.trace(Log.l1_User, "InfoOrder");
58         setTitle(Msg.getMsg(Env.getCtx(), "InfoOrder"));
59         //
60
try
61         {
62             statInit();
63             p_loadedOK = initInfo ();
64         }
65         catch (Exception JavaDoc e)
66         {
67             return;
68         }
69         //
70
int no = p_table.getRowCount();
71         setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
72         setStatusDB(Integer.toString(no));
73         if (value != null && value.length() > 0)
74         {
75             fDocumentNo.setValue(value);
76             executeQuery();
77         }
78         //
79
pack();
80         // Focus
81
fDocumentNo.requestFocus();
82     } // InfoOrder
83

84     /** String Array of Column Info */
85     private Info_Column[] m_generalLayout;
86     /** list of query columns */
87     private ArrayList m_queryColumns = new ArrayList();
88     /** Table Name */
89     private String JavaDoc m_tableName;
90     /** Key Column Name */
91     private String JavaDoc m_keyColumn;
92
93     // Static Info
94
private CLabel lDocumentNo = new CLabel(Msg.translate(Env.getCtx(), "DocumentNo"));
95     private CTextField fDocumentNo = new CTextField(10);
96     private CLabel lDescription = new CLabel(Msg.translate(Env.getCtx(), "Description"));
97     private CTextField fDescription = new CTextField(10);
98     private CLabel lPOReference = new CLabel(Msg.translate(Env.getCtx(), "POReference"));
99     private CTextField fPOReference = new CTextField(10);
100     //
101
// private CLabel lOrg_ID = new CLabel(Msg.translate(Env.getCtx(), "AD_Org_ID"));
102
// private VLookup fOrg_ID;
103
private CLabel lBPartner_ID = new CLabel(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
104     private VLookup fBPartner_ID;
105     //
106
private CLabel lDateFrom = new CLabel(Msg.translate(Env.getCtx(), "DateOrdered"));
107     private VDate fDateFrom = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom"));
108     private CLabel lDateTo = new CLabel("-");
109     private VDate fDateTo = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo"));
110     private CLabel lAmtFrom = new CLabel(Msg.translate(Env.getCtx(), "GrandTotal"));
111     private VNumber fAmtFrom = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom"));
112     private CLabel lAmtTo = new CLabel("-");
113     private VNumber fAmtTo = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo"));
114     private VCheckBox fIsSOTrx = new VCheckBox ("IsSOTrx", false, false, true, Msg.translate(Env.getCtx(), "IsSOTrx"), "", false);
115
116     /** Array of Column Info */
117     private static final Info_Column[] s_invoiceLayout = {
118         new Info_Column(" ", "o.C_Order_ID", IDColumn.class),
119         new Info_Column(Msg.translate(Env.getCtx(), "C_BPartner_ID"), "(SELECT Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=o.C_BPartner_ID)", String JavaDoc.class),
120         new Info_Column(Msg.translate(Env.getCtx(), "DateOrdered"), "o.DateOrdered", Timestamp.class),
121         new Info_Column(Msg.translate(Env.getCtx(), "DocumentNo"), "o.DocumentNo", String JavaDoc.class),
122         new Info_Column(Msg.translate(Env.getCtx(), "C_Currency_ID"), "(SELECT ISO_Code FROM C_Currency c WHERE c.C_Currency_ID=o.C_Currency_ID)", String JavaDoc.class),
123         new Info_Column(Msg.translate(Env.getCtx(), "GrandTotal"), "o.GrandTotal", BigDecimal.class),
124         new Info_Column(Msg.translate(Env.getCtx(), "ConvertedAmount"), "C_Base_Convert(o.GrandTotal,o.C_Currency_ID,o.AD_Client_ID,o.DateAcct, o.AD_Org_ID)", BigDecimal.class),
125         new Info_Column(Msg.translate(Env.getCtx(), "IsSOTrx"), "o.IsSOTrx", Boolean JavaDoc.class),
126         new Info_Column(Msg.translate(Env.getCtx(), "Description"), "o.Description", String JavaDoc.class),
127         new Info_Column(Msg.translate(Env.getCtx(), "POReference"), "o.POReference", String JavaDoc.class)
128     };
129
130     /**
131      * Static Setup - add fields to parameterPanel
132      * @throws Exception if Lookups cannot be initialized
133      */

134     private void statInit() throws Exception JavaDoc
135     {
136         lDocumentNo.setLabelFor(fDocumentNo);
137         fDocumentNo.setBackground(CompierePLAF.getInfoBackground());
138         fDocumentNo.addActionListener(this);
139         lDescription.setLabelFor(fDescription);
140         fDescription.setBackground(CompierePLAF.getInfoBackground());
141         fDescription.addActionListener(this);
142         lPOReference.setLabelFor(lPOReference);
143         fPOReference.setBackground(CompierePLAF.getInfoBackground());
144         fPOReference.addActionListener(this);
145         fIsSOTrx.setSelected(!"N".equals(Env.getContext(Env.getCtx(), p_WindowNo, "IsSOTrx")));
146         fIsSOTrx.addActionListener(this);
147         //
148
// fOrg_ID = new VLookup("AD_Org_ID", false, false, true,
149
// MLookupFactory.create(Env.getCtx(), 3486, m_WindowNo, DisplayType.TableDir, false),
150
// DisplayType.TableDir, m_WindowNo);
151
// lOrg_ID.setLabelFor(fOrg_ID);
152
// fOrg_ID.setBackground(CompierePLAF.getInfoBackground());
153
fBPartner_ID = new VLookup("C_BPartner_ID", false, false, true,
154             MLookupFactory.get (Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search),
155             DisplayType.Search, p_WindowNo);
156         lBPartner_ID.setLabelFor(fBPartner_ID);
157         fBPartner_ID.setBackground(CompierePLAF.getInfoBackground());
158         //
159
lDateFrom.setLabelFor(fDateFrom);
160         fDateFrom.setBackground(CompierePLAF.getInfoBackground());
161         fDateFrom.setToolTipText(Msg.translate(Env.getCtx(), "DateFrom"));
162         lDateTo.setLabelFor(fDateTo);
163         fDateTo.setBackground(CompierePLAF.getInfoBackground());
164         fDateTo.setToolTipText(Msg.translate(Env.getCtx(), "DateTo"));
165         lAmtFrom.setLabelFor(fAmtFrom);
166         fAmtFrom.setBackground(CompierePLAF.getInfoBackground());
167         fAmtFrom.setToolTipText(Msg.translate(Env.getCtx(), "AmtFrom"));
168         lAmtTo.setLabelFor(fAmtTo);
169         fAmtTo.setBackground(CompierePLAF.getInfoBackground());
170         fAmtTo.setToolTipText(Msg.translate(Env.getCtx(), "AmtTo"));
171         //
172
parameterPanel.setLayout(new ALayout());
173         // First Row
174
parameterPanel.add(lDocumentNo, new ALayoutConstraint(0,0));
175         parameterPanel.add(fDocumentNo, null);
176         parameterPanel.add(lBPartner_ID, null);
177         parameterPanel.add(fBPartner_ID, null);
178         parameterPanel.add(fIsSOTrx, new ALayoutConstraint(0,5));
179         // 2nd Row
180
parameterPanel.add(lDescription, new ALayoutConstraint(1,0));
181         parameterPanel.add(fDescription, null);
182         parameterPanel.add(lDateFrom, null);
183         parameterPanel.add(fDateFrom, null);
184         parameterPanel.add(lDateTo, null);
185         parameterPanel.add(fDateTo, null);
186         // 3rd Row
187
parameterPanel.add(lPOReference, new ALayoutConstraint(2,0));
188         parameterPanel.add(fPOReference, null);
189         parameterPanel.add(lAmtFrom, null);
190         parameterPanel.add(fAmtFrom, null);
191         parameterPanel.add(lAmtTo, null);
192         parameterPanel.add(fAmtTo, null);
193     // parameterPanel.add(lOrg_ID, null);
194
// parameterPanel.add(fOrg_ID, null);
195
} // statInit
196

197     /**
198      * General Init
199      * @return true, if success
200      */

201     private boolean initInfo ()
202     {
203         // Set Defaults
204
String JavaDoc bp = Env.getContext(Env.getCtx(), p_WindowNo, "C_BPartner_ID");
205         if (bp != null && bp.length() != 0)
206             fBPartner_ID.setValue(new Integer JavaDoc(bp));
207
208         // prepare table
209
StringBuffer JavaDoc where = new StringBuffer JavaDoc("o.IsActive='Y'");
210         if (p_whereClause.length() > 0)
211             where.append(" AND ").append(Util.replace(p_whereClause, "C_Order.", "o."));
212         prepareTable(s_invoiceLayout,
213             " C_Order o",
214             where.toString(),
215             "2,3,4");
216
217         return true;
218     } // initInfo
219

220     /*************************************************************************/
221
222     /**
223      * Construct SQL Where Clause and define parameters.
224      * (setParameters needs to set parameters)
225      * Includes first AND
226      * @return sql
227      */

228     String JavaDoc getSQLWhere()
229     {
230         StringBuffer JavaDoc sql = new StringBuffer JavaDoc();
231         if (fDocumentNo.getText().length() > 0)
232             sql.append(" AND UPPER(o.DocumentNo) LIKE ?");
233         if (fDescription.getText().length() > 0)
234             sql.append(" AND UPPER(o.Description) LIKE ?");
235         if (fPOReference.getText().length() > 0)
236             sql.append(" AND UPPER(o.POReference) LIKE ?");
237         //
238
if (fBPartner_ID.getValue() != null)
239             sql.append(" AND o.C_BPartner_ID=?");
240         //
241
if (fDateFrom.getValue() != null || fDateTo.getValue() != null)
242         {
243             Timestamp from = (Timestamp)fDateFrom.getValue();
244             Timestamp to = (Timestamp)fDateTo.getValue();
245             if (from == null && to != null)
246                 sql.append(" AND TRUNC(o.DateOrdered) <= ?");
247             else if (from != null && to == null)
248                 sql.append(" AND TRUNC(o.DateOrdered) >= ?");
249             else if (from != null && to != null)
250                 sql.append(" AND TRUNC(o.DateOrdered) BETWEEN ? AND ?");
251         }
252         //
253
if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null)
254         {
255             BigDecimal from = (BigDecimal)fAmtFrom.getValue();
256             BigDecimal to = (BigDecimal)fAmtTo.getValue();
257             if (from == null && to != null)
258                 sql.append(" AND o.GrandTotal <= ?");
259             else if (from != null && to == null)
260                 sql.append(" AND o.GrandTotal >= ?");
261             else if (from != null && to != null)
262                 sql.append(" AND o.GrandTotal BETWEEN ? AND ?");
263         }
264         sql.append(" AND o.IsSOTrx=?");
265
266     // Log.trace(Log.l6_Database, "InfoOrder.setWhereClause", sql.toString());
267
return sql.toString();
268     } // getSQLWhere
269

270     /**
271      * Set Parameters for Query.
272      * (as defined in getSQLWhere)
273      * @param pstmt statement
274      * @throws SQLException
275      */

276     void setParameters(PreparedStatement pstmt) throws SQLException
277     {
278         int index = 1;
279         if (fDocumentNo.getText().length() > 0)
280             pstmt.setString(index++, getSQLText(fDocumentNo));
281         if (fDescription.getText().length() > 0)
282             pstmt.setString(index++, getSQLText(fDescription));
283         if (fPOReference.getText().length() > 0)
284             pstmt.setString(index++, getSQLText(fPOReference));
285         //
286
if (fBPartner_ID.getValue() != null)
287         {
288             Integer JavaDoc bp = (Integer JavaDoc)fBPartner_ID.getValue();
289             pstmt.setInt(index++, bp.intValue());
290             Log.trace(Log.l5_DData, "BPartner=" + bp);
291         }
292         //
293
if (fDateFrom.getValue() != null || fDateTo.getValue() != null)
294         {
295             Timestamp from = (Timestamp)fDateFrom.getValue();
296             Timestamp to = (Timestamp)fDateTo.getValue();
297             Log.trace(Log.l5_DData, "Date From=" + from + ", To=" + to);
298             if (from == null && to != null)
299                 pstmt.setTimestamp(index++, to);
300             else if (from != null && to == null)
301                 pstmt.setTimestamp(index++, from);
302             else if (from != null && to != null)
303             {
304                 pstmt.setTimestamp(index++, from);
305                 pstmt.setTimestamp(index++, to);
306             }
307         }
308         //
309
if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null)
310         {
311             BigDecimal from = (BigDecimal)fAmtFrom.getValue();
312             BigDecimal to = (BigDecimal)fAmtTo.getValue();
313             Log.trace(Log.l5_DData, "Amt From=" + from + ", To=" + to);
314             if (from == null && to != null)
315                 pstmt.setBigDecimal(index++, to);
316             else if (from != null && to == null)
317                 pstmt.setBigDecimal(index++, from);
318             else if (from != null && to != null)
319             {
320                 pstmt.setBigDecimal(index++, from);
321                 pstmt.setBigDecimal(index++, to);
322             }
323         }
324         pstmt.setString(index++, fIsSOTrx.isSelected() ? "Y" : "N");
325     } // setParameters
326

327     /**
328      * Get SQL WHERE parameter
329      * @param f field
330      * @return sql
331      */

332     private String JavaDoc getSQLText (CTextField f)
333     {
334         String JavaDoc s = f.getText().toUpperCase();
335         if (!s.endsWith("%"))
336             s += "%";
337         Log.trace(Log.l5_DData, "String=" + s);
338         return s;
339     } // getSQLText
340
} // InfoOrder
341
Popular Tags