View Javadoc
1   /*
2    * Copyright 2007 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  package org.kuali.ole.gl.businessobject;
17  
18  import java.util.HashMap;
19  import java.util.Iterator;
20  import java.util.LinkedHashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.ole.coa.businessobject.OrganizationReversionCategory;
26  import org.kuali.rice.core.api.util.type.KualiDecimal;
27  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
28  
29  /**
30   * This class represents a unit of work for the organization reversion
31   */
32  public class OrgReversionUnitOfWork extends PersistableBusinessObjectBase {
33      public String chartOfAccountsCode = "";
34      public String accountNumber = "";
35      public String subAccountNumber = "";
36      public Map<String, OrgReversionUnitOfWorkCategoryAmount> amounts;
37      private KualiDecimal totalReversion;
38      private KualiDecimal totalCarryForward;
39      private KualiDecimal totalAvailable;
40      private KualiDecimal totalCash;
41  
42      public OrgReversionUnitOfWork() {
43          amounts = new HashMap<String, OrgReversionUnitOfWorkCategoryAmount>();
44      }
45  
46      public OrgReversionUnitOfWork(String chart, String acct, String subAcct) {
47          this();
48          chartOfAccountsCode = chart;
49          accountNumber = acct;
50          subAccountNumber = subAcct;
51      }
52  
53      /**
54       * Returns true if COA code and account number are not blank.
55       * 
56       * @return true if COA code and account number are not blank.
57       */
58      public boolean isInitialized() {
59          return !StringUtils.isBlank(chartOfAccountsCode) && !StringUtils.isBlank(accountNumber);
60      }
61  
62      public void setFields(String chart, String acct, String subAcct) {
63          chartOfAccountsCode = chart;
64          accountNumber = acct;
65          subAccountNumber = subAcct;
66          cascadeCategoryAmountKeys();
67          clearAmounts();
68      }
69  
70      /**
71       * Set category amounts
72       * @param cats list of organization reversion categories
73       */
74      public void setCategories(List<OrganizationReversionCategory> cats) {
75          for (OrganizationReversionCategory element : cats) {
76              OrgReversionUnitOfWorkCategoryAmount ca = new OrgReversionUnitOfWorkCategoryAmount(element.getOrganizationReversionCategoryCode());
77              amounts.put(element.getOrganizationReversionCategoryCode(), ca);
78          }
79      }
80  
81      /**
82       * This method adds to the actual amount for a specific category code
83       * @param categoryCode category code
84       * @param amount amount
85       */
86      public void addActualAmount(String categoryCode, KualiDecimal amount) {
87          OrgReversionUnitOfWorkCategoryAmount ca = amounts.get(categoryCode);
88          ca.setActual(ca.getActual().add(amount));
89      }
90  
91      /**
92       * This method adds to the budget amount for a specific category code
93       * @param categoryCode category code
94       * @param amount amount
95       */
96      public void addBudgetAmount(String categoryCode, KualiDecimal amount) {
97          OrgReversionUnitOfWorkCategoryAmount ca = amounts.get(categoryCode);
98          ca.setBudget(ca.getBudget().add(amount));
99      }
100 
101     /**
102      * This method adds to the encumbrance amount for a specific category code
103      * @param categoryCode category code
104      * @param amount amount
105      */
106     public void addEncumbranceAmount(String categoryCode, KualiDecimal amount) {
107         OrgReversionUnitOfWorkCategoryAmount ca = amounts.get(categoryCode);
108         ca.setEncumbrance(ca.getEncumbrance().add(amount));
109     }
110 
111     /**
112      * This method adds to the carry forward amount for a specific category code
113      * @param categoryCode category code
114      * @param amount amount
115      */
116     public void addCarryForwardAmount(String categoryCode, KualiDecimal amount) {
117         OrgReversionUnitOfWorkCategoryAmount ca = amounts.get(categoryCode);
118         ca.setCarryForward(ca.getCarryForward().add(amount));
119     }
120 
121     /**
122      * This method clears all amounts for this unit of work
123      */
124     public void clearAmounts() {
125         totalAvailable = KualiDecimal.ZERO;
126         totalCarryForward = KualiDecimal.ZERO;
127         totalCash = KualiDecimal.ZERO;
128         totalReversion = KualiDecimal.ZERO;
129 
130         for (Iterator<OrgReversionUnitOfWorkCategoryAmount> iter = amounts.values().iterator(); iter.hasNext();) {
131             OrgReversionUnitOfWorkCategoryAmount element = iter.next();
132             element.setActual(KualiDecimal.ZERO);
133             element.setBudget(KualiDecimal.ZERO);
134             element.setEncumbrance(KualiDecimal.ZERO);
135         }
136     }
137 
138     /**
139      * This method updates the category amount keys for the current unit of work
140      */
141     public void cascadeCategoryAmountKeys() {
142         for (String category : amounts.keySet()) {
143             OrgReversionUnitOfWorkCategoryAmount catAmt = amounts.get(category);
144             catAmt.setChartOfAccountsCode(this.chartOfAccountsCode);
145             catAmt.setAccountNumber(this.accountNumber);
146             catAmt.setSubAccountNumber(this.subAccountNumber);
147         }
148     }
149 
150     /**
151      * This method returns true if this unit of work's chart of accounts code, account number, and sub account number match the passed in parameter values
152      * @param chart
153      * @param acct
154      * @param subAcct
155      * @return true if this unit of work's chart of accounts code, account number, and sub account number match the passed in parameter values
156      */
157     public boolean isSame(String chart, String acct, String subAcct) {
158         return (chartOfAccountsCode.equals(chart) && accountNumber.equals(acct) && subAccountNumber.equals(subAcct));
159     }
160 
161     /**
162      * Return true of this unit of work has the same chart of accounts code, account number, and sub account number as the passed in balance
163      * @param balance
164      * @return
165      */
166     public boolean wouldHold(Balance balance) {
167         return StringUtils.equals(chartOfAccountsCode, balance.getChartOfAccountsCode()) && StringUtils.equals(accountNumber, balance.getAccountNumber()) && StringUtils.equals(subAccountNumber, balance.getSubAccountNumber());
168     }
169 
170     public KualiDecimal getTotalAccountAvailable() {
171         KualiDecimal amount = KualiDecimal.ZERO;
172         for (Iterator<OrgReversionUnitOfWorkCategoryAmount> iter = amounts.values().iterator(); iter.hasNext();) {
173             OrgReversionUnitOfWorkCategoryAmount element = iter.next();
174             amount = amount.add(element.getAvailable());
175         }
176         return amount;
177     }
178 
179     public KualiDecimal getTotalCarryForward() {
180         return totalCarryForward;
181     }
182 
183     public void setTotalCarryForward(KualiDecimal totalCarryForward) {
184         this.totalCarryForward = totalCarryForward;
185     }
186 
187     public KualiDecimal getTotalReversion() {
188         return totalReversion;
189     }
190 
191     public void addTotalCarryForward(KualiDecimal amount) {
192         totalCarryForward = totalCarryForward.add(amount);
193     }
194 
195     public void setTotalReversion(KualiDecimal totalReversion) {
196         this.totalReversion = totalReversion;
197     }
198 
199     public void addTotalReversion(KualiDecimal amount) {
200         totalReversion = totalReversion.add(amount);
201     }
202 
203     public KualiDecimal getTotalAvailable() {
204         return totalAvailable;
205     }
206 
207     public void addTotalAvailable(KualiDecimal amount) {
208         totalAvailable = totalAvailable.add(amount);
209     }
210 
211     public void setTotalAvailable(KualiDecimal totalAvailable) {
212         this.totalAvailable = totalAvailable;
213     }
214 
215     public void addTotalCash(KualiDecimal amount) {
216         totalCash = totalCash.add(amount);
217     }
218 
219     public KualiDecimal getTotalCash() {
220         return totalCash;
221     }
222 
223     public void setTotalCash(KualiDecimal totalCash) {
224         this.totalCash = totalCash;
225     }
226 
227     public Map<String, OrgReversionUnitOfWorkCategoryAmount> getCategoryAmounts() {
228         return amounts;
229     }
230 
231     /**
232      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
233      */
234     
235     public LinkedHashMap toStringMapper_RICE20_REFACTORME() {
236         LinkedHashMap pkMap = new LinkedHashMap();
237         pkMap.put("chartOfAccountsCode", this.chartOfAccountsCode);
238         pkMap.put("accountNbr", this.accountNumber);
239         pkMap.put("subAccountNbr", this.subAccountNumber);
240         return pkMap;
241     }
242 
243     /**
244      * Gets the accountNumber attribute.
245      * 
246      * @return Returns the accountNumber.
247      */
248     public String getAccountNumber() {
249         return accountNumber;
250     }
251 
252     /**
253      * Sets the accountNumber attribute value.
254      * 
255      * @param accountNumber The accountNumber to set.
256      */
257     public void setAccountNumber(String accountNumber) {
258         this.accountNumber = accountNumber;
259     }
260 
261     /**
262      * Gets the chartOfAccountsCode attribute.
263      * 
264      * @return Returns the chartOfAccountsCode.
265      */
266     public String getChartOfAccountsCode() {
267         return chartOfAccountsCode;
268     }
269 
270     /**
271      * Sets the chartOfAccountsCode attribute value.
272      * 
273      * @param chartOfAccountsCode The chartOfAccountsCode to set.
274      */
275     public void setChartOfAccountsCode(String chartOfAccountsCode) {
276         this.chartOfAccountsCode = chartOfAccountsCode;
277     }
278 
279     /**
280      * Gets the subAccountNumber attribute.
281      * 
282      * @return Returns the subAccountNumber.
283      */
284     public String getSubAccountNumber() {
285         return subAccountNumber;
286     }
287 
288     /**
289      * Sets the subAccountNumber attribute value.
290      * 
291      * @param subAccountNumber The subAccountNumber to set.
292      */
293     public void setSubAccountNumber(String subAccountNumber) {
294         this.subAccountNumber = subAccountNumber;
295     }
296 
297 }