1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
55
56
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
72
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
83
84
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
93
94
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
103
104
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
113
114
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
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
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
152
153
154
155
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
163
164
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
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
245
246
247
248 public String getAccountNumber() {
249 return accountNumber;
250 }
251
252
253
254
255
256
257 public void setAccountNumber(String accountNumber) {
258 this.accountNumber = accountNumber;
259 }
260
261
262
263
264
265
266 public String getChartOfAccountsCode() {
267 return chartOfAccountsCode;
268 }
269
270
271
272
273
274
275 public void setChartOfAccountsCode(String chartOfAccountsCode) {
276 this.chartOfAccountsCode = chartOfAccountsCode;
277 }
278
279
280
281
282
283
284 public String getSubAccountNumber() {
285 return subAccountNumber;
286 }
287
288
289
290
291
292
293 public void setSubAccountNumber(String subAccountNumber) {
294 this.subAccountNumber = subAccountNumber;
295 }
296
297 }