KickJava   Java API By Example, From Geeks To Geeks.

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


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

42 public class InfoPayment 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 whwre clause
52      */

53     protected InfoPayment(Frame frame, boolean modal, int WindowNo, String JavaDoc value,
54         boolean multiSelection, String JavaDoc whereClause)
55     {
56         super (frame, modal, WindowNo, "p", "C_Payment_ID", multiSelection, whereClause);
57         Log.trace(Log.l1_User, "InfoPayment");
58         setTitle(Msg.getMsg(Env.getCtx(), "InfoPayment"));
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     } // InfoPayment
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     //
97
// private CLabel lOrg_ID = new CLabel(Msg.translate(Env.getCtx(), "AD_Org_ID"));
98
// private VLookup fOrg_ID;
99
private CLabel lBPartner_ID = new CLabel(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
100     private VLookup fBPartner_ID;
101     //
102
private CLabel lDateFrom = new CLabel(Msg.translate(Env.getCtx(), "DateTrx"));
103     private VDate fDateFrom = new VDate("DateFrom", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateFrom"));
104     private CLabel lDateTo = new CLabel("-");
105     private VDate fDateTo = new VDate("DateTo", false, false, true, DisplayType.Date, Msg.translate(Env.getCtx(), "DateTo"));
106     private CLabel lAmtFrom = new CLabel(Msg.translate(Env.getCtx(), "PayAmt"));
107     private VNumber fAmtFrom = new VNumber("AmtFrom", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtFrom"));
108     private CLabel lAmtTo = new CLabel("-");
109     private VNumber fAmtTo = new VNumber("AmtTo", false, false, true, DisplayType.Amount, Msg.translate(Env.getCtx(), "AmtTo"));
110     private VCheckBox fIsReceipt = new VCheckBox ("IsReceipt", false, false, true, Msg.translate(Env.getCtx(), "IsReceipt"), "", false);
111
112     /** Array of Column Info */
113     private static final Info_Column[] s_paymentLayout = {
114         new Info_Column(" ", "p.C_Payment_ID", IDColumn.class),
115         new Info_Column(Msg.translate(Env.getCtx(), "C_BankAccount_ID"),
116             "(SELECT b.Name || ' ' || ba.AccountNo FROM C_Bank b, C_BankAccount ba WHERE b.C_Bank_ID=ba.C_Bank_ID AND ba.C_BankAccount_ID=p.C_BankAccount_ID)", String JavaDoc.class),
117         new Info_Column(Msg.translate(Env.getCtx(), "C_BPartner_ID"),
118             "(SELECT Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=p.C_BPartner_ID)", String JavaDoc.class),
119         new Info_Column(Msg.translate(Env.getCtx(), "DateTrx"),
120             "p.DateTrx", Timestamp.class),
121         new Info_Column(Msg.translate(Env.getCtx(), "DocumentNo"),
122             "p.DocumentNo", String JavaDoc.class),
123         new Info_Column(Msg.translate(Env.getCtx(), "IsReceipt"),
124             "p.IsReceipt", Boolean JavaDoc.class),
125         new Info_Column(Msg.translate(Env.getCtx(), "C_Currency_ID"),
126             "(SELECT ISO_Code FROM C_Currency c WHERE c.C_Currency_ID=p.C_Currency_ID)", String JavaDoc.class),
127         new Info_Column(Msg.translate(Env.getCtx(), "PayAmt"),
128             "p.PayAmt", BigDecimal.class),
129         new Info_Column(Msg.translate(Env.getCtx(), "ConvertedAmount"),
130             "C_Base_Convert(p.PayAmt,p.C_Currency_ID,p.AD_Client_ID,p.DateTrx,p.AD_Org_ID)", BigDecimal.class),
131         new Info_Column(Msg.translate(Env.getCtx(), "DiscountAmt"),
132             "p.DiscountAmt", BigDecimal.class),
133         new Info_Column(Msg.translate(Env.getCtx(), "WriteOffAmt"),
134             "p.WriteOffAmt", BigDecimal.class)
135     };
136
137     /**
138      * Static Setup - add fields to parameterPanel
139      * @throws Exception if Lookups cannot be created
140      */

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

194     /**
195      * General Init
196      * @return true, if success
197      */

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

217     /*************************************************************************/
218
219     /**
220      * Construct SQL Where Clause and define parameters
221      * (setParameters needs to set parameters)
222      * Includes first AND
223      * @return sql where clause
224      */

225     String JavaDoc getSQLWhere()
226     {
227         StringBuffer JavaDoc sql = new StringBuffer JavaDoc();
228         if (fDocumentNo.getText().length() > 0)
229             sql.append(" AND UPPER(p.DocumentNo) LIKE ?");
230         //
231
if (fBPartner_ID.getValue() != null)
232             sql.append(" AND p.C_BPartner_ID=?");
233         //
234
if (fDateFrom.getValue() != null || fDateTo.getValue() != null)
235         {
236             Timestamp from = (Timestamp)fDateFrom.getValue();
237             Timestamp to = (Timestamp)fDateTo.getValue();
238             if (from == null && to != null)
239                 sql.append(" AND TRUNC(p.DateTrx) <= ?");
240             else if (from != null && to == null)
241                 sql.append(" AND TRUNC(p.DateTrx) >= ?");
242             else if (from != null && to != null)
243                 sql.append(" AND TRUNC(p.DateTrx) BETWEEN ? AND ?");
244         }
245         //
246
if (fAmtFrom.getValue() != null || fAmtTo.getValue() != null)
247         {
248             BigDecimal from = (BigDecimal)fAmtFrom.getValue();
249             BigDecimal to = (BigDecimal)fAmtTo.getValue();
250             if (from == null && to != null)
251                 sql.append(" AND p.PayAmt <= ?");
252             else if (from != null && to == null)
253                 sql.append(" AND p.PayAmt >= ?");
254             else if (from != null && to != null)
255                 sql.append(" AND p.PayAmt BETWEEN ? AND ?");
256         }
257         sql.append(" AND p.IsReceipt=?");
258
259         Log.trace(Log.l6_Database, "InfoPayment.getWhereClause", sql.toString());
260         return sql.toString();
261     } // getSQLWhere
262

263     /**
264      * Set Parameters for Query.
265      * (as defined in getSQLWhere)
266      * @param pstmt statement
267      * @throws SQLException
268      */

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

316     /**
317      * Get SQL WHERE parameter
318      * @param f field
319      * @return Upper case text with % at the end
320      */

321     private String JavaDoc getSQLText (CTextField f)
322     {
323         String JavaDoc s = f.getText().toUpperCase();
324         if (!s.endsWith("%"))
325             s += "%";
326         Log.trace(Log.l5_DData, "String=" + s);
327         return s;
328     } // getSQLText
329
} // InfoPayment
330
Popular Tags