KickJava   Java API By Example, From Geeks To Geeks.

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


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 Invoice
38  *
39  * @author Jorg Janke
40  * @version $Id: InfoInvoice.java,v 1.24 2003/10/17 06:15:56 jjanke Exp $
41  */

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

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

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

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

213     /**
214      * General Init
215      * @return true, if success
216      */

217     private boolean initInfo ()
218     {
219         // Set Defaults
220
String JavaDoc bp = Env.getContext(Env.getCtx(), p_WindowNo, "C_BPartner_ID");
221         if (bp != null && bp.length() != 0)
222             fBPartner_ID.setValue(new Integer JavaDoc(bp));
223
224         // prepare table
225
StringBuffer JavaDoc where = new StringBuffer JavaDoc("i.IsActive='Y'");
226         if (p_whereClause.length() > 0)
227             where.append(" AND ").append(Util.replace(p_whereClause, "C_Invoice.", "i."));
228         prepareTable(s_invoiceLayout,
229             " C_Invoice_v i", // corrected for CM
230
where.toString(),
231             "2,3,4");
232
233         return true;
234     } // initInfo
235

236     /*************************************************************************/
237
238     /**
239      * Construct SQL Where Clause and define parameters.
240      * (setParameters needs to set parameters)
241      * Includes first AND
242      * @return sql
243      */

244     String JavaDoc getSQLWhere()
245     {
246         StringBuffer JavaDoc sql = new StringBuffer JavaDoc();
247         if (fDocumentNo.getText().length() > 0)
248             sql.append(" AND UPPER(i.DocumentNo) LIKE ?");
249         if (fDescription.getText().length() > 0)
250             sql.append(" AND UPPER(i.Description) LIKE ?");
251     // if (fPOReference.getText().length() > 0)
252
// sql.append(" AND UPPER(i.POReference) LIKE ?");
253
//
254
if (fBPartner_ID.getValue() != null)
255             sql.append(" AND i.C_BPartner_ID=?");
256         //
257
if (fOrder_ID.getValue() != null)
258             sql.append(" AND i.C_Order_ID=?");
259         //
260
if (fDateFrom.getValue() != null || fDateTo.getValue() != null)
261         {
262             Timestamp from = (Timestamp)fDateFrom.getValue();
263             Timestamp to = (Timestamp)fDateTo.getValue();
264             if (from == null && to != null)
265                 sql.append(" AND TRUNC(i.DateInvoiced) <= ?");
266             else if (from != null && to == null)
267                 sql.append(" AND TRUNC(i.DateInvoiced) >= ?");
268             else if (from != null && to != null)
269                 sql.append(" AND TRUNC(i.DateInvoiced) BETWEEN ? AND ?");
270         }
271         //
272
if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null)
273         {
274             BigDecimal from = (BigDecimal)fAmtFrom.getValue();
275             BigDecimal to = (BigDecimal)fAmtTo.getValue();
276             if (from == null && to != null)
277                 sql.append(" AND i.GrandTotal <= ?");
278             else if (from != null && to == null)
279                 sql.append(" AND i.GrandTotal >= ?");
280             else if (from != null && to != null)
281                 sql.append(" AND i.GrandTotal BETWEEN ? AND ?");
282         }
283         //
284
sql.append(" AND i.IsPaid=? AND i.IsSOTrx=?");
285
286     // Log.trace(Log.l6_Database, "InfoInvoice.setWhereClause", sql.toString());
287
return sql.toString();
288     } // getSQLWhere
289

290     /**
291      * Set Parameters for Query.
292      * (as defined in getSQLWhere)
293      * @param pstmt statement
294      * @throws SQLException
295      */

296     void setParameters(PreparedStatement pstmt) throws SQLException
297     {
298         int index = 1;
299         if (fDocumentNo.getText().length() > 0)
300             pstmt.setString(index++, getSQLText(fDocumentNo));
301         if (fDescription.getText().length() > 0)
302             pstmt.setString(index++, getSQLText(fDescription));
303     // if (fPOReference.getText().length() > 0)
304
// pstmt.setString(index++, getSQLText(fPOReference));
305
//
306
if (fBPartner_ID.getValue() != null)
307         {
308             Integer JavaDoc bp = (Integer JavaDoc)fBPartner_ID.getValue();
309             pstmt.setInt(index++, bp.intValue());
310             Log.trace(Log.l5_DData, "BPartner=" + bp);
311         }
312         //
313
if (fOrder_ID.getValue() != null)
314         {
315             Integer JavaDoc order = (Integer JavaDoc)fOrder_ID.getValue();
316             pstmt.setInt(index++, order.intValue());
317             Log.trace(Log.l5_DData, "Order=" + order);
318         }
319         //
320
if (fDateFrom.getValue() != null || fDateTo.getValue() != null)
321         {
322             Timestamp from = (Timestamp)fDateFrom.getValue();
323             Timestamp to = (Timestamp)fDateTo.getValue();
324             Log.trace(Log.l5_DData, "Date From=" + from + ", To=" + to);
325             if (from == null && to != null)
326                 pstmt.setTimestamp(index++, to);
327             else if (from != null && to == null)
328                 pstmt.setTimestamp(index++, from);
329             else if (from != null && to != null)
330             {
331                 pstmt.setTimestamp(index++, from);
332                 pstmt.setTimestamp(index++, to);
333             }
334         }
335         //
336
if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null)
337         {
338             BigDecimal from = (BigDecimal)fAmtFrom.getValue();
339             BigDecimal to = (BigDecimal)fAmtTo.getValue();
340             Log.trace(Log.l5_DData, "Amt From=" + from + ", To=" + to);
341             if (from == null && to != null)
342                 pstmt.setBigDecimal(index++, to);
343             else if (from != null && to == null)
344                 pstmt.setBigDecimal(index++, from);
345             else if (from != null && to != null)
346             {
347                 pstmt.setBigDecimal(index++, from);
348                 pstmt.setBigDecimal(index++, to);
349             }
350         }
351         pstmt.setString(index++, fIsPaid.isSelected() ? "Y" : "N");
352         pstmt.setString(index++, fIsSOTrx.isSelected() ? "Y" : "N");
353     } // setParameters
354

355     /**
356      * Get SQL WHERE parameter
357      * @param f field
358      * @return sql
359      */

360     private String JavaDoc getSQLText (CTextField f)
361     {
362         String JavaDoc s = f.getText().toUpperCase();
363         if (!s.endsWith("%"))
364             s += "%";
365         Log.trace(Log.l5_DData, "String=" + s);
366         return s;
367     } // getSQLText
368
} // InfoInvoice
369
Popular Tags