001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.kuali.kfs.coa.businessobject;
018    
019    import java.sql.Date;
020    import java.util.Calendar;
021    import java.util.LinkedHashMap;
022    
023    import org.kuali.kfs.sys.businessobject.SystemOptions;
024    import org.kuali.kfs.sys.context.SpringContext;
025    import org.kuali.rice.kns.bo.Inactivateable;
026    import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
027    import org.kuali.rice.kns.service.DateTimeService;
028    
029    /**
030     * 
031     */
032    public class AccountingPeriod extends PersistableBusinessObjectBase implements Inactivateable {
033    
034        private Integer universityFiscalYear;
035        private String universityFiscalPeriodCode;
036        private String universityFiscalPeriodName;
037        private boolean active;
038        private boolean budgetRolloverIndicator;
039    
040        private Date universityFiscalPeriodEndDate;
041        private SystemOptions options;
042    
043        /**
044         * Default constructor.
045         */
046        public AccountingPeriod() {
047    
048        }
049    
050        /**
051         * Gets the universityFiscalYear attribute.
052         * 
053         * @return Returns the universityFiscalYear
054         */
055        public Integer getUniversityFiscalYear() {
056            return universityFiscalYear;
057        }
058    
059        /**
060         * Sets the universityFiscalYear attribute.
061         * 
062         * @param universityFiscalYear The universityFiscalYear to set.
063         */
064        public void setUniversityFiscalYear(Integer universityFiscalYear) {
065            this.universityFiscalYear = universityFiscalYear;
066        }
067    
068    
069        /**
070         * Gets the universityFiscalPeriodCode attribute.
071         * 
072         * @return Returns the universityFiscalPeriodCode
073         */
074        public String getUniversityFiscalPeriodCode() {
075            return universityFiscalPeriodCode;
076        }
077    
078        /**
079         * Sets the universityFiscalPeriodCode attribute.
080         * 
081         * @param universityFiscalPeriodCode The universityFiscalPeriodCode to set.
082         */
083        public void setUniversityFiscalPeriodCode(String universityFiscalPeriodCode) {
084            this.universityFiscalPeriodCode = universityFiscalPeriodCode;
085        }
086    
087    
088        /**
089         * Gets the universityFiscalPeriodName attribute.
090         * 
091         * @return Returns the universityFiscalPeriodName
092         */
093        public String getUniversityFiscalPeriodName() {
094            return universityFiscalPeriodName;
095        }
096    
097        /**
098         * Sets the universityFiscalPeriodName attribute.
099         * 
100         * @param universityFiscalPeriodName The universityFiscalPeriodName to set.
101         */
102        public void setUniversityFiscalPeriodName(String universityFiscalPeriodName) {
103            this.universityFiscalPeriodName = universityFiscalPeriodName;
104        }
105    
106    
107        /**
108         * Gets the active attribute.
109         * 
110         * @return Returns the active
111         */
112        public boolean isActive() {
113            return active;
114        }
115    
116        /**
117         * Sets the active attribute.
118         * 
119         * @param active The active to set.
120         */
121        public void setActive(boolean active) {
122            this.active = active;
123        }
124    
125    
126        /**
127         * Gets the budgetRolloverIndicator attribute.
128         * 
129         * @return Returns the budgetRolloverIndicator
130         */
131        public boolean isBudgetRolloverIndicator() {
132            return budgetRolloverIndicator;
133        }
134    
135    
136        /**
137         * Sets the budgetRolloverIndicator attribute.
138         * 
139         * @param budgetRolloverIndicator The budgetRolloverIndicator to set.
140         */
141        public void setBudgetRolloverIndicator(boolean budgetRolloverIndicator) {
142            this.budgetRolloverIndicator = budgetRolloverIndicator;
143        }
144    
145    
146        /**
147         * Gets the universityFiscalPeriodEndDate attribute.
148         * 
149         * @return Returns the universityFiscalPeriodEndDate
150         */
151        public Date getUniversityFiscalPeriodEndDate() {
152            return universityFiscalPeriodEndDate;
153        }
154    
155        /**
156         * Sets the universityFiscalPeriodEndDate attribute.
157         * 
158         * @param universityFiscalPeriodEndDate The universityFiscalPeriodEndDate to set.
159         */
160        public void setUniversityFiscalPeriodEndDate(Date universityFiscalPeriodEndDate) {
161            this.universityFiscalPeriodEndDate = universityFiscalPeriodEndDate;
162        }
163    
164        /**
165         * Determine if the current account period is open
166         * 
167         * @return true if the accounting period is open; otherwise, false
168         */
169        public boolean isOpen() {
170            return this.isActive();
171        }
172    
173        /**
174         * @return Returns the options.
175         */
176        public SystemOptions getOptions() {
177            return options;
178        }
179    
180        /**
181         * @param options The options to set.
182         * @deprecated
183         */
184        public void setOptions(SystemOptions options) {
185            this.options = options;
186        }
187    
188        /**
189         * This method returns the month that this period represents
190         * 
191         * @return the actual month (1 - 12) that this period represents
192         */
193        public int getMonth() {
194            DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
195            Calendar cal = dateTimeService.getCalendar(new Date(this.universityFiscalPeriodEndDate.getTime()));
196            return cal.get(Calendar.MONTH) + 1;
197        }
198    
199        /**
200         * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
201         */
202        protected LinkedHashMap toStringMapper() {
203            LinkedHashMap m = new LinkedHashMap();
204            m.put("universityFiscalYear", "" + this.universityFiscalYear);
205            m.put("universityFiscalPeriodCode", this.universityFiscalPeriodCode);
206            return m;
207        }
208    
209        /**
210         * generates a hash code for this accounting period, based on the primary keys of the AccountingPeriod BusinesObject: university
211         * fiscal year and university fiscal period code
212         * 
213         * @see java.lang.Object#hashCode()
214         */
215        @Override
216        public int hashCode() {
217            final int PRIME = 31;
218            int result = 1;
219            result = PRIME * result + ((universityFiscalPeriodCode == null) ? 0 : universityFiscalPeriodCode.hashCode());
220            result = PRIME * result + ((universityFiscalYear == null) ? 0 : universityFiscalYear.hashCode());
221            return result;
222        }
223    
224        /**
225         * determines if two accounting periods are equal, based on the primary keys of the AccountingPeriod BusinesObject: university
226         * fiscal year and university fiscal period code
227         * 
228         * @see java.lang.Object#equals(java.lang.Object)
229         */
230        @Override
231        public boolean equals(Object obj) {
232            // this method was added so that
233            // org.kuali.kfs.fp.document.web.struts.AuxiliaryVoucherForm.populateAccountingPeriodListForRendering works properly
234            if (this == obj)
235                return true;
236            if (obj == null)
237                return false;
238            if (getClass() != obj.getClass())
239                return false;
240            final AccountingPeriod other = (AccountingPeriod) obj;
241            if (universityFiscalPeriodCode == null) {
242                if (other.universityFiscalPeriodCode != null)
243                    return false;
244            }
245            else if (!universityFiscalPeriodCode.equals(other.universityFiscalPeriodCode))
246                return false;
247            if (universityFiscalYear == null) {
248                if (other.universityFiscalYear != null)
249                    return false;
250            }
251            else if (!universityFiscalYear.equals(other.universityFiscalYear))
252                return false;
253            return true;
254        }
255    }