KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > wstore > Info


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 Smart 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-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.wstore;
15
16 import javax.servlet.*;
17 import javax.servlet.http.*;
18 import java.io.*;
19 import java.util.*;
20 import java.sql.*;
21
22 import org.apache.log4j.Logger;
23
24 import org.compiere.model.*;
25 import org.compiere.util.*;
26
27
28 /**
29  * Information Storage.
30  * Container for JSP Information, added in InfoLinkTag
31  *
32  * @author Jorg Janke
33  * @version $Id: Info.java,v 1.13 2003/09/05 04:55:42 jjanke Exp $
34  */

35 public class Info
36 {
37     /**
38      * Get general Info
39      * @return info
40      */

41     public static Info getGeneral()
42     {
43         if (m_general == null)
44             m_general = new Info (new Properties(), -1, -1);
45         return m_general;
46     } // getGeneral
47

48     /** General Info */
49     private static Info m_general = null;
50
51     /**
52      * Constructor
53      * @param ctx context
54      * @param C_BPartner_ID BPartner
55      * @param AD_User_ID Contact
56      */

57     public Info (Properties ctx, int C_BPartner_ID, int AD_User_ID)
58     {
59         m_ctx = ctx;
60         m_C_BPartner_ID = C_BPartner_ID;
61         m_AD_User_ID = AD_User_ID;
62         log.debug("C_BPartner_ID=" + C_BPartner_ID + ", AD_User_ID=" + AD_User_ID);
63     } // Info
64

65     /** JSP Name */
66     static public final String JavaDoc NAME = "info";
67
68     /** Logging */
69     private Logger log = Logger.getLogger(getClass());
70     /** Context */
71     private Properties m_ctx = null;
72     /** Business Partner */
73     private int m_C_BPartner_ID = 0;
74     private int m_AD_User_ID = 0;
75     /** Info Message */
76     private String JavaDoc m_infoMessage = null;
77     /** Info ID */
78     private int m_id = 0;
79
80     /**
81      * String Representation
82      * @return info
83      */

84     public String JavaDoc toString()
85     {
86         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Info[");
87         sb.append(m_C_BPartner_ID);
88         sb.append("]");
89         return sb.toString();
90     } // toString
91

92     /**
93      * Get Info Message & reset
94      * @return info message
95      */

96     public String JavaDoc getMessage()
97     {
98         String JavaDoc retValue = m_infoMessage;
99         m_infoMessage = null;
100         return retValue;
101     } // getMessage
102

103     /**
104      * Get Info Message - do not reset
105      * @return info message
106      */

107     public String JavaDoc getInfo()
108     {
109         return m_infoMessage;
110     } // getInfo
111

112     /**
113      * Set Info Message
114      * @param msg info message
115      */

116     public void setMessage (String JavaDoc msg)
117     {
118         m_infoMessage = msg;
119     } // setMessage
120

121     /**
122      * Get Info Message
123      * @return info id
124      */

125     public int getId()
126     {
127         return m_id;
128     } // getId
129

130     /**
131      * Set Info Message
132      * @param id info id
133      */

134     public void setId (String JavaDoc id)
135     {
136         try
137         {
138             setId (Integer.parseInt (id));
139         }
140         catch (NumberFormatException JavaDoc ex)
141         {
142             log.error("setId - " + id + " - " + ex.toString());
143         }
144     } // setId
145

146     /**
147      * Set Info Message
148      * @param id info id
149      */

150     public void setId (int id)
151     {
152         log.info("setID = " + id);
153         m_id = id;
154     } // setId
155

156     /**
157      * Get BPartner
158      * @return C_BPartner_ID
159      */

160     public int getC_BPartner_ID()
161     {
162         return m_C_BPartner_ID;
163     } // getC_BPartner_ID
164

165     /**
166      * Get BPartner Contact/User
167      * @return AD_User_ID
168      */

169     public int getAD_User_ID()
170     {
171         return m_AD_User_ID;
172     } // getAD_User_ID
173

174     /**
175      * Get BPartner Contact/User
176      * @return AD_User_ID
177      */

178     public int getUser_ID()
179     {
180         return m_AD_User_ID;
181     } // getAD_User_ID
182

183     /*************************************************************************/
184
185     /**
186      * Get Orders
187      * @return invoices of BP
188      */

189     public ArrayList getOrders()
190     {
191         m_infoMessage = null;
192         ArrayList list = new ArrayList();
193         String JavaDoc sql = "SELECT * FROM C_Order WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC";
194         PreparedStatement pstmt = null;
195         try
196         {
197             pstmt = DB.prepareStatement(sql);
198             pstmt.setInt(1, m_C_BPartner_ID);
199             ResultSet rs = pstmt.executeQuery();
200             while (rs.next())
201                 list.add(new MOrder (m_ctx, rs));
202             rs.close();
203             pstmt.close();
204             pstmt = null;
205         }
206         catch (Exception JavaDoc e)
207         {
208             log.error("getOrders", e);
209         }
210         finally
211         {
212             try
213             {
214                 if (pstmt != null)
215                     pstmt.close ();
216             }
217             catch (Exception JavaDoc e)
218             {}
219             pstmt = null;
220         }
221         log.debug ("getOrders #" + list.size());
222         return list;
223     } // getOrders
224

225     /**
226      * Get Order.
227      * Needs to have ID set first
228      * @return invoice of BP with ID
229      */

230     public MOrder getOrder()
231     {
232         MOrder retValue = null;
233         String JavaDoc sql = "SELECT * FROM C_Order WHERE C_BPartner_ID=? AND C_Order_ID=?";
234         PreparedStatement pstmt = null;
235         try
236         {
237             pstmt = DB.prepareStatement(sql);
238             pstmt.setInt(1, m_C_BPartner_ID);
239             pstmt.setInt(2, m_id);
240             ResultSet rs = pstmt.executeQuery();
241             if (rs.next())
242                 retValue = new MOrder (m_ctx, rs);
243             rs.close();
244             pstmt.close();
245             pstmt = null;
246         }
247         catch (Exception JavaDoc e)
248         {
249             log.error("getOrder ID=" + m_id, e);
250         }
251         finally
252         {
253             try
254             {
255                 if (pstmt != null)
256                     pstmt.close ();
257             }
258             catch (Exception JavaDoc e)
259             {}
260             pstmt = null;
261         }
262         log.debug ("getOrder ID=" + m_id + " - " + retValue);
263         return retValue;
264     } // getOrder
265

266
267     /**
268      * Get Shipments
269      * @return shipments of BP
270      */

271     public ArrayList getShipments()
272     {
273         m_infoMessage = null;
274         ArrayList list = new ArrayList();
275         String JavaDoc sql = "SELECT * FROM M_InOut WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC";
276         PreparedStatement pstmt = null;
277         try
278         {
279             pstmt = DB.prepareStatement(sql);
280             pstmt.setInt(1, m_C_BPartner_ID);
281             ResultSet rs = pstmt.executeQuery();
282             while (rs.next())
283                 list.add(new MInOut (m_ctx, rs));
284             rs.close();
285             pstmt.close();
286             pstmt = null;
287         }
288         catch (Exception JavaDoc e)
289         {
290             log.error("getShipments", e);
291         }
292         finally
293         {
294             try
295             {
296                 if (pstmt != null)
297                     pstmt.close ();
298             }
299             catch (Exception JavaDoc e)
300             {}
301             pstmt = null;
302         }
303         log.debug ("getShipments #" + list.size());
304         return list;
305     } // getShipments
306

307     /**
308      * Get Own Requests
309      * @return Array of Own Requests
310      */

311     public ArrayList getRequestsOwn ()
312     {
313         return getRequests(true);
314     } // getRequestsOwn
315

316     /**
317      * Get Own Requests
318      * @return Array of Assigned Requests
319      */

320     public ArrayList getRequestsAssigned ()
321     {
322         return getRequests(false);
323     } // getRequestsAssigned
324

325     /**
326      * Get Requests
327      * @param own if true its own requests otherwise or
328      * @return Array of Requests
329      */

330     public ArrayList getRequests (boolean own)
331     {
332         m_infoMessage = null;
333         ArrayList list = new ArrayList();
334         String JavaDoc sql = own ? "SELECT * FROM R_Request WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC"
335             : "SELECT * FROM R_Request WHERE SalesRep_ID IN (SELECT AD_User_ID FROM AD_User WHERE C_BPartner_ID=?) "
336                 + "ORDER BY DocumentNo DESC";
337         PreparedStatement pstmt = null;
338         try
339         {
340             pstmt = DB.prepareStatement(sql);
341             pstmt.setInt(1, m_C_BPartner_ID);
342             ResultSet rs = pstmt.executeQuery();
343             while (rs.next())
344                 list.add (new MRequest (m_ctx, rs));
345             rs.close();
346             pstmt.close();
347             pstmt = null;
348         }
349         catch (Exception JavaDoc e)
350         {
351             log.error("getRequests Own=" + own, e);
352         }
353         finally
354         {
355             try
356             {
357                 if (pstmt != null)
358                     pstmt.close ();
359             }
360             catch (Exception JavaDoc e)
361             {}
362             pstmt = null;
363         }
364         log.debug ("getRequests Own=" + own +" #" + list.size());
365         return list;
366     } // getRequests
367

368     /**
369      * Get Invoices
370      * @return invoices of BP
371      */

372     public ArrayList getInvoices()
373     {
374         ArrayList list = new ArrayList();
375         String JavaDoc sql = "SELECT * FROM C_Invoice WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC";
376         PreparedStatement pstmt = null;
377         try
378         {
379             pstmt = DB.prepareStatement(sql);
380             pstmt.setInt(1, m_C_BPartner_ID);
381             ResultSet rs = pstmt.executeQuery();
382             while (rs.next())
383                 list.add(new MInvoice (m_ctx, rs));
384             rs.close();
385             pstmt.close();
386             pstmt = null;
387         }
388         catch (Exception JavaDoc e)
389         {
390             log.error("getInvoices", e);
391         }
392         finally
393         {
394             try
395             {
396                 if (pstmt != null)
397                     pstmt.close ();
398             }
399             catch (Exception JavaDoc e)
400             {}
401             pstmt = null;
402         }
403         log.debug ("getInvoices #" + list.size());
404         return list;
405     } // getInvoices
406

407     /**
408      * Get Invoice.
409      * Needs to have ID set first
410      * @return invoice with ID of BP
411      */

412     public MInvoice getInvoice()
413     {
414         MInvoice retValue = null;
415         String JavaDoc sql = "SELECT * FROM C_Invoice WHERE C_BPartner_ID=? AND C_Invoice_ID=?";
416         PreparedStatement pstmt = null;
417         try
418         {
419             pstmt = DB.prepareStatement(sql);
420             pstmt.setInt(1, m_C_BPartner_ID);
421             pstmt.setInt(2, m_id);
422             ResultSet rs = pstmt.executeQuery();
423             if (rs.next())
424                 retValue = new MInvoice (m_ctx, rs);
425             rs.close();
426             pstmt.close();
427             pstmt = null;
428         }
429         catch (Exception JavaDoc e)
430         {
431             log.error("getInvoice ID=" + m_id, e);
432         }
433         finally
434         {
435             try
436             {
437                 if (pstmt != null)
438                     pstmt.close ();
439             }
440             catch (Exception JavaDoc e)
441             {}
442             pstmt = null;
443         }
444         log.debug ("getInvoice ID=" + m_id + " - " + retValue);
445         return retValue;
446     } // getInvoice
447

448     /**
449      * Get Payments
450      * @return payments of BP
451      */

452     public ArrayList getPayments()
453     {
454         ArrayList list = new ArrayList();
455         String JavaDoc sql = "SELECT * FROM C_Payment WHERE C_BPartner_ID=? ORDER BY DocumentNo DESC";
456         PreparedStatement pstmt = null;
457         try
458         {
459             pstmt = DB.prepareStatement(sql);
460             pstmt.setInt(1, m_C_BPartner_ID);
461             ResultSet rs = pstmt.executeQuery();
462             while (rs.next())
463                 list.add(new MPayment (m_ctx, rs));
464             rs.close();
465             pstmt.close();
466             pstmt = null;
467         }
468         catch (Exception JavaDoc e)
469         {
470             log.error("getPayments", e);
471         }
472         finally
473         {
474             try
475             {
476                 if (pstmt != null)
477                     pstmt.close ();
478             }
479             catch (Exception JavaDoc e)
480             {}
481             pstmt = null;
482         }
483         log.debug ("getPayments #" + list.size());
484         return list;
485     } // getPayments
486

487     /**
488      * Get Active Assets
489      * @return payments of BP
490      */

491     public ArrayList getAssets()
492     {
493         ArrayList list = new ArrayList();
494         String JavaDoc sql = "SELECT * FROM A_Asset WHERE C_BPartner_ID=? AND IsActive='Y' ORDER BY Name";
495         PreparedStatement pstmt = null;
496         try
497         {
498             pstmt = DB.prepareStatement(sql);
499             pstmt.setInt(1, m_C_BPartner_ID);
500             ResultSet rs = pstmt.executeQuery();
501             while (rs.next())
502                 list.add(new MAsset (m_ctx, rs));
503             rs.close();
504             pstmt.close();
505             pstmt = null;
506         }
507         catch (Exception JavaDoc e)
508         {
509             log.error("getAssets", e);
510         }
511         finally
512         {
513             try
514             {
515                 if (pstmt != null)
516                     pstmt.close ();
517             }
518             catch (Exception JavaDoc e)
519             {}
520             pstmt = null;
521         }
522         log.debug ("getAssets #" + list.size());
523         return list;
524     } // getAssets
525

526     /**
527      * Get Interest Areas
528      * @return interest areas of BPC
529      */

530     public ArrayList getInterests()
531     {
532         int AD_Client_ID = Env.getContextAsInt(m_ctx, "#AD_Client_ID");
533         //
534
ArrayList list = new ArrayList();
535         String JavaDoc sql = "SELECT ia.R_InterestArea_ID, ia.AD_Client_ID,ia.AD_Org_ID,ia.IsActive,"
536             + " ia.Created,ia.CreatedBy,ia.Updated,ia.UpdatedBy,"
537             + " ia.Name,ia.Description,ia.IsSelfService,"
538             + " ci.AD_User_ID, ci.SubscribeDate,ci.OptOutDate "
539             + "FROM R_InterestArea ia"
540             + " LEFT OUTER JOIN R_ContactInterest ci ON (ia.R_InterestArea_ID=ci.R_InterestArea_ID AND ci.AD_User_ID=?) "
541             + "WHERE ia.IsActive='Y' AND ia.IsSelfService='Y'"
542             + " AND ia.AD_Client_ID=? "
543             + "ORDER BY ia.Name";
544         PreparedStatement pstmt = null;
545         try
546         {
547             pstmt = DB.prepareStatement(sql);
548             pstmt.setInt(1, m_AD_User_ID);
549             pstmt.setInt(2, AD_Client_ID);
550             ResultSet rs = pstmt.executeQuery();
551             while (rs.next())
552             {
553                 MInterestArea ia = new MInterestArea (m_ctx, rs);
554                 int contact = rs.getInt("AD_User_ID");
555                 if (contact != 0)
556                     ia.setSubscription(contact, rs.getTimestamp("SubscribeDate"), rs.getTimestamp("OptOutDate"));
557                 list.add (ia);
558             }
559             rs.close();
560             pstmt.close();
561             pstmt = null;
562         }
563         catch (Exception JavaDoc e)
564         {
565             log.error("getInterests", e);
566         }
567         finally
568         {
569             try
570             {
571                 if (pstmt != null)
572                     pstmt.close ();
573             }
574             catch (Exception JavaDoc e)
575             {}
576             pstmt = null;
577         }
578         log.debug ("getInterests #" + list.size());
579         return list;
580     } // getInterests
581

582     /**
583      * Get Advertisements
584      * @return advertisements of BP
585      */

586     public ArrayList getAdvertisements()
587     {
588         m_infoMessage = null;
589         ArrayList list = new ArrayList();
590         String JavaDoc sql = "SELECT * FROM W_Advertisement WHERE C_BPartner_ID=? ORDER BY ValidFrom DESC";
591         PreparedStatement pstmt = null;
592         try
593         {
594             pstmt = DB.prepareStatement(sql);
595             pstmt.setInt(1, m_C_BPartner_ID);
596             ResultSet rs = pstmt.executeQuery();
597             while (rs.next())
598                 list.add(new MAdvertisement (m_ctx, rs));
599             rs.close();
600             pstmt.close();
601             pstmt = null;
602         }
603         catch (Exception JavaDoc e)
604         {
605             log.error("getAdvertisement", e);
606         }
607         finally
608         {
609             try
610             {
611                 if (pstmt != null)
612                     pstmt.close ();
613             }
614             catch (Exception JavaDoc e)
615             {}
616             pstmt = null;
617         }
618         log.debug ("getAdvertisement #" + list.size());
619         return list;
620     } // getAdvertisement
621

622     /**
623      * Get All Advertisements
624      * @return all advertisements
625      */

626     public ArrayList getAllAds()
627     {
628         m_infoMessage = null;
629         ArrayList list = new ArrayList();
630         String JavaDoc sql = "SELECT * FROM W_Advertisement ORDER BY Description";
631         PreparedStatement pstmt = null;
632         try
633         {
634             pstmt = DB.prepareStatement(sql);
635             ResultSet rs = pstmt.executeQuery();
636             while (rs.next())
637                 list.add(new MAdvertisement (m_ctx, rs));
638             rs.close();
639             pstmt.close();
640             pstmt = null;
641         }
642         catch (Exception JavaDoc e)
643         {
644             log.error("getAllAds", e);
645         }
646         finally
647         {
648             try
649             {
650                 if (pstmt != null)
651                     pstmt.close ();
652             }
653             catch (Exception JavaDoc e)
654             {}
655             pstmt = null;
656         }
657         log.debug ("getAllAds #" + list.size());
658         return list;
659     } // getAllAds
660

661 } // Info
662
Popular Tags