View Javadoc
1   /*
2    * Copyright 2005 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.ole.coa.businessobject;
18  
19  import java.sql.Date;
20  import java.util.Calendar;
21  import java.util.LinkedHashMap;
22  
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.sys.businessobject.FiscalYearBasedBusinessObject;
25  import org.kuali.ole.sys.businessobject.SystemOptions;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.rice.core.api.datetime.DateTimeService;
28  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
29  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
30  
31  /**
32   * 
33   */
34  public class AccountingPeriod extends PersistableBusinessObjectBase implements MutableInactivatable, FiscalYearBasedBusinessObject {
35  
36      public static final String CACHE_NAME = OLEConstants.APPLICATION_NAMESPACE_CODE + "/" + "AccountingPeriod";
37  
38      private Integer universityFiscalYear;
39      private String universityFiscalPeriodCode;
40      private String universityFiscalPeriodName;
41      private boolean active;
42      private boolean budgetRolloverIndicator;
43  
44      private Date universityFiscalPeriodEndDate;
45      private SystemOptions options;
46  
47      /**
48       * Default constructor.
49       */
50      public AccountingPeriod() {
51  
52      }
53  
54      /**
55       * Gets the universityFiscalYear attribute.
56       * 
57       * @return Returns the universityFiscalYear
58       */
59      public Integer getUniversityFiscalYear() {
60          return universityFiscalYear;
61      }
62  
63      /**
64       * Sets the universityFiscalYear attribute.
65       * 
66       * @param universityFiscalYear The universityFiscalYear to set.
67       */
68      public void setUniversityFiscalYear(Integer universityFiscalYear) {
69          this.universityFiscalYear = universityFiscalYear;
70      }
71  
72  
73      /**
74       * Gets the universityFiscalPeriodCode attribute.
75       * 
76       * @return Returns the universityFiscalPeriodCode
77       */
78      public String getUniversityFiscalPeriodCode() {
79          return universityFiscalPeriodCode;
80      }
81  
82      /**
83       * Sets the universityFiscalPeriodCode attribute.
84       * 
85       * @param universityFiscalPeriodCode The universityFiscalPeriodCode to set.
86       */
87      public void setUniversityFiscalPeriodCode(String universityFiscalPeriodCode) {
88          this.universityFiscalPeriodCode = universityFiscalPeriodCode;
89      }
90  
91  
92      /**
93       * Gets the universityFiscalPeriodName attribute.
94       * 
95       * @return Returns the universityFiscalPeriodName
96       */
97      public String getUniversityFiscalPeriodName() {
98          return universityFiscalPeriodName;
99      }
100 
101     /**
102      * Sets the universityFiscalPeriodName attribute.
103      * 
104      * @param universityFiscalPeriodName The universityFiscalPeriodName to set.
105      */
106     public void setUniversityFiscalPeriodName(String universityFiscalPeriodName) {
107         this.universityFiscalPeriodName = universityFiscalPeriodName;
108     }
109 
110 
111     /**
112      * Gets the active attribute.
113      * 
114      * @return Returns the active
115      */
116     public boolean isActive() {
117         return active;
118     }
119 
120     /**
121      * Sets the active attribute.
122      * 
123      * @param active The active to set.
124      */
125     public void setActive(boolean active) {
126         this.active = active;
127     }
128 
129 
130     /**
131      * Gets the budgetRolloverIndicator attribute.
132      * 
133      * @return Returns the budgetRolloverIndicator
134      */
135     public boolean isBudgetRolloverIndicator() {
136         return budgetRolloverIndicator;
137     }
138 
139 
140     /**
141      * Sets the budgetRolloverIndicator attribute.
142      * 
143      * @param budgetRolloverIndicator The budgetRolloverIndicator to set.
144      */
145     public void setBudgetRolloverIndicator(boolean budgetRolloverIndicator) {
146         this.budgetRolloverIndicator = budgetRolloverIndicator;
147     }
148 
149 
150     /**
151      * Gets the universityFiscalPeriodEndDate attribute.
152      * 
153      * @return Returns the universityFiscalPeriodEndDate
154      */
155     public Date getUniversityFiscalPeriodEndDate() {
156         return universityFiscalPeriodEndDate;
157     }
158 
159     /**
160      * Sets the universityFiscalPeriodEndDate attribute.
161      * 
162      * @param universityFiscalPeriodEndDate The universityFiscalPeriodEndDate to set.
163      */
164     public void setUniversityFiscalPeriodEndDate(Date universityFiscalPeriodEndDate) {
165         this.universityFiscalPeriodEndDate = universityFiscalPeriodEndDate;
166     }
167 
168     /**
169      * Determine if the current account period is open
170      * 
171      * @return true if the accounting period is open; otherwise, false
172      */
173     public boolean isOpen() {
174         return this.isActive();
175     }
176 
177     /**
178      * @return Returns the options.
179      */
180     public SystemOptions getOptions() {
181         return options;
182     }
183 
184     /**
185      * @param options The options to set.
186      * @deprecated
187      */
188     public void setOptions(SystemOptions options) {
189         this.options = options;
190     }
191 
192     /**
193      * This method returns the month that this period represents
194      * 
195      * @return the actual month (1 - 12) that this period represents
196      */
197     public int getMonth() {
198         DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
199         Calendar cal = dateTimeService.getCalendar(new Date(this.universityFiscalPeriodEndDate.getTime()));
200         return cal.get(Calendar.MONTH) + 1;
201     }
202 
203     /**
204      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
205      */
206     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
207         LinkedHashMap m = new LinkedHashMap();
208         m.put("universityFiscalYear", "" + this.universityFiscalYear);
209         m.put("universityFiscalPeriodCode", this.universityFiscalPeriodCode);
210         return m;
211     }
212 
213     /**
214      * generates a hash code for this accounting period, based on the primary keys of the AccountingPeriod BusinesObject: university
215      * fiscal year and university fiscal period code
216      * 
217      * @see java.lang.Object#hashCode()
218      */
219     @Override
220     public int hashCode() {
221         final int PRIME = 31;
222         int result = 1;
223         result = PRIME * result + ((universityFiscalPeriodCode == null) ? 0 : universityFiscalPeriodCode.hashCode());
224         result = PRIME * result + ((universityFiscalYear == null) ? 0 : universityFiscalYear.hashCode());
225         return result;
226     }
227 
228     /**
229      * determines if two accounting periods are equal, based on the primary keys of the AccountingPeriod BusinesObject: university
230      * fiscal year and university fiscal period code
231      * 
232      * @see java.lang.Object#equals(java.lang.Object)
233      */
234     @Override
235     public boolean equals(Object obj) {
236         // this method was added so that
237         // org.kuali.ole.fp.document.web.struts.AuxiliaryVoucherForm.populateAccountingPeriodListForRendering works properly
238         if (this == obj)
239             return true;
240         if (obj == null)
241             return false;
242         if (getClass() != obj.getClass())
243             return false;
244         final AccountingPeriod other = (AccountingPeriod) obj;
245         if (universityFiscalPeriodCode == null) {
246             if (other.universityFiscalPeriodCode != null)
247                 return false;
248         }
249         else if (!universityFiscalPeriodCode.equals(other.universityFiscalPeriodCode))
250             return false;
251         if (universityFiscalYear == null) {
252             if (other.universityFiscalYear != null)
253                 return false;
254         }
255         else if (!universityFiscalYear.equals(other.universityFiscalYear))
256             return false;
257         return true;
258     }
259 }