KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MPeriod


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.model;
15
16 import java.util.*;
17 import java.sql.*;
18
19 import org.compiere.util.*;
20
21 /**
22  * Calendar Period Model
23  *
24  * @author Jorg Janke
25  * @version $Id: MPeriod.java,v 1.2 2003/10/04 03:51:51 jjanke Exp $
26  */

27 public class MPeriod extends X_C_Period
28 {
29     public MPeriod (Properties ctx, int C_Period_ID)
30     {
31         super (ctx, C_Period_ID);
32         if (C_Period_ID == 0)
33         {
34         // setC_Period_ID (0); // PK
35
// setC_Year_ID (0); // Parent
36
// setName (null);
37
// setPeriodNo (0);
38
// setPeriodType (null);
39
// setStartDate (new Timestamp(System.currentTimeMillis()));
40
}
41     } // MPeriod
42

43     public MPeriod (Properties ctx, ResultSet rs)
44     {
45         super (ctx, rs);
46     } // MPeriod
47

48     private static Logger s_log = Logger.getCLogger (MPeriod.class);
49
50
51
52
53     /*************************************************************************/
54
55     /**
56      * Find Period of DateAcct
57      * @param ctx context
58      * @param DateAcct date
59      * @return Period
60      */

61     public static MPeriod get (Properties ctx, Timestamp DateAcct)
62     {
63         MPeriod retValue = null;
64         int AD_Client_ID = Env.getContextAsInt(ctx, "#AD_Client_ID");
65         String JavaDoc sql = "SELECT * "
66             + "FROM C_Period "
67             + "WHERE C_Year_ID IN "
68             + " (SELECT C_Year_ID FROM C_Year WHERE C_Calendar_ID ="
69             + " (SELECT C_Calendar_ID FROM AD_ClientInfo WHERE AD_Client_ID=?))"
70             + " AND ? BETWEEN StartDate AND EndDate"
71             + " AND PeriodType='S'";
72         try
73         {
74             PreparedStatement pstmt = DB.prepareStatement(sql);
75             pstmt.setInt (1, AD_Client_ID);
76             pstmt.setTimestamp (2, DateAcct);
77             ResultSet rs = pstmt.executeQuery();
78             if (rs.next())
79                 retValue = new MPeriod(ctx, rs);
80             rs.close();
81             pstmt.close();
82         }
83         catch (SQLException e)
84         {
85             s_log.error("get - DateAcct", e);
86         }
87         return retValue;
88     } // get
89

90     /**
91      * Find valid Period ID of DateAcct
92      * @param ctx context
93      * @param DateAcct date
94      * @return C_Period_ID or 0
95      */

96     public static int getC_Period_ID (Properties ctx, Timestamp DateAcct)
97     {
98         MPeriod period = get (ctx, DateAcct);
99         if (period == null)
100             return 0;
101         return period.getC_Period_ID();
102     } // getC_Period_ID
103

104 } // MPeriod
105
Popular Tags