001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: package org.kuali.module.gl.bo;
017:
018: import java.util.HashMap;
019: import java.util.Iterator;
020: import java.util.LinkedHashMap;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.bo.PersistableBusinessObjectBase;
026: import org.kuali.core.util.KualiDecimal;
027: import org.kuali.module.chart.bo.OrganizationReversionCategory;
028:
029: /**
030: * This class represents a unit of work for the organization reversion
031: */
032: public class OrgReversionUnitOfWork extends
033: PersistableBusinessObjectBase {
034: public String chartOfAccountsCode = "";
035: public String accountNumber = "";
036: public String subAccountNumber = "";
037: public Map<String, OrgReversionUnitOfWorkCategoryAmount> amounts;
038: private KualiDecimal totalReversion;
039: private KualiDecimal totalCarryForward;
040: private KualiDecimal totalAvailable;
041: private KualiDecimal totalCash;
042:
043: public OrgReversionUnitOfWork() {
044: amounts = new HashMap<String, OrgReversionUnitOfWorkCategoryAmount>();
045: }
046:
047: public OrgReversionUnitOfWork(String chart, String acct,
048: String subAcct) {
049: this ();
050: chartOfAccountsCode = chart;
051: accountNumber = acct;
052: subAccountNumber = subAcct;
053: }
054:
055: /**
056: * Returns true if COA code and account number are not blank.
057: *
058: * @return true if COA code and account number are not blank.
059: */
060: public boolean isInitialized() {
061: return !StringUtils.isBlank(chartOfAccountsCode)
062: && !StringUtils.isBlank(accountNumber);
063: }
064:
065: public void setFields(String chart, String acct, String subAcct) {
066: chartOfAccountsCode = chart;
067: accountNumber = acct;
068: subAccountNumber = subAcct;
069: cascadeCategoryAmountKeys();
070: clearAmounts();
071: }
072:
073: /**
074: * Set category amounts
075: * @param cats list of organization reversion categories
076: */
077: public void setCategories(List<OrganizationReversionCategory> cats) {
078: for (OrganizationReversionCategory element : cats) {
079: OrgReversionUnitOfWorkCategoryAmount ca = new OrgReversionUnitOfWorkCategoryAmount(
080: element.getOrganizationReversionCategoryCode());
081: amounts.put(element.getOrganizationReversionCategoryCode(),
082: ca);
083: }
084: }
085:
086: /**
087: * This method adds to the actual amount for a specific category code
088: * @param categoryCode category code
089: * @param amount amount
090: */
091: public void addActualAmount(String categoryCode, KualiDecimal amount) {
092: OrgReversionUnitOfWorkCategoryAmount ca = amounts
093: .get(categoryCode);
094: ca.setActual(ca.getActual().add(amount));
095: }
096:
097: /**
098: * This method adds to the budget amount for a specific category code
099: * @param categoryCode category code
100: * @param amount amount
101: */
102: public void addBudgetAmount(String categoryCode, KualiDecimal amount) {
103: OrgReversionUnitOfWorkCategoryAmount ca = amounts
104: .get(categoryCode);
105: ca.setBudget(ca.getBudget().add(amount));
106: }
107:
108: /**
109: * This method adds to the encumbrance amount for a specific category code
110: * @param categoryCode category code
111: * @param amount amount
112: */
113: public void addEncumbranceAmount(String categoryCode,
114: KualiDecimal amount) {
115: OrgReversionUnitOfWorkCategoryAmount ca = amounts
116: .get(categoryCode);
117: ca.setEncumbrance(ca.getEncumbrance().add(amount));
118: }
119:
120: /**
121: * This method adds to the carry forward amount for a specific category code
122: * @param categoryCode category code
123: * @param amount amount
124: */
125: public void addCarryForwardAmount(String categoryCode,
126: KualiDecimal amount) {
127: OrgReversionUnitOfWorkCategoryAmount ca = amounts
128: .get(categoryCode);
129: ca.setCarryForward(ca.getCarryForward().add(amount));
130: }
131:
132: /**
133: * This method clears all amounts for this unit of work
134: */
135: public void clearAmounts() {
136: totalAvailable = KualiDecimal.ZERO;
137: totalCarryForward = KualiDecimal.ZERO;
138: totalCash = KualiDecimal.ZERO;
139: totalReversion = KualiDecimal.ZERO;
140:
141: for (Iterator<OrgReversionUnitOfWorkCategoryAmount> iter = amounts
142: .values().iterator(); iter.hasNext();) {
143: OrgReversionUnitOfWorkCategoryAmount element = iter.next();
144: element.setActual(KualiDecimal.ZERO);
145: element.setBudget(KualiDecimal.ZERO);
146: element.setEncumbrance(KualiDecimal.ZERO);
147: }
148: }
149:
150: /**
151: * This method updates the category amount keys for the current unit of work
152: */
153: public void cascadeCategoryAmountKeys() {
154: for (String category : amounts.keySet()) {
155: OrgReversionUnitOfWorkCategoryAmount catAmt = amounts
156: .get(category);
157: catAmt.setChartOfAccountsCode(this .chartOfAccountsCode);
158: catAmt.setAccountNumber(this .accountNumber);
159: catAmt.setSubAccountNumber(this .subAccountNumber);
160: }
161: }
162:
163: /**
164: * 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
165: * @param chart
166: * @param acct
167: * @param subAcct
168: * @return true if this unit of work's chart of accounts code, account number, and sub account number match the passed in parameter values
169: */
170: public boolean isSame(String chart, String acct, String subAcct) {
171: return (chartOfAccountsCode.equals(chart)
172: && accountNumber.equals(acct) && subAccountNumber
173: .equals(subAcct));
174: }
175:
176: /**
177: * 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
178: * @param balance
179: * @return
180: */
181: public boolean wouldHold(Balance balance) {
182: return StringUtils.equals(chartOfAccountsCode, balance
183: .getChartOfAccountsCode())
184: && StringUtils.equals(accountNumber, balance
185: .getAccountNumber())
186: && StringUtils.equals(subAccountNumber, balance
187: .getSubAccountNumber());
188: }
189:
190: public KualiDecimal getTotalAccountAvailable() {
191: KualiDecimal amount = KualiDecimal.ZERO;
192: for (Iterator<OrgReversionUnitOfWorkCategoryAmount> iter = amounts
193: .values().iterator(); iter.hasNext();) {
194: OrgReversionUnitOfWorkCategoryAmount element = iter.next();
195: amount = amount.add(element.getAvailable());
196: }
197: return amount;
198: }
199:
200: public KualiDecimal getTotalCarryForward() {
201: return totalCarryForward;
202: }
203:
204: public void setTotalCarryForward(KualiDecimal totalCarryForward) {
205: this .totalCarryForward = totalCarryForward;
206: }
207:
208: public KualiDecimal getTotalReversion() {
209: return totalReversion;
210: }
211:
212: public void addTotalCarryForward(KualiDecimal amount) {
213: totalCarryForward = totalCarryForward.add(amount);
214: }
215:
216: public void setTotalReversion(KualiDecimal totalReversion) {
217: this .totalReversion = totalReversion;
218: }
219:
220: public void addTotalReversion(KualiDecimal amount) {
221: totalReversion = totalReversion.add(amount);
222: }
223:
224: public KualiDecimal getTotalAvailable() {
225: return totalAvailable;
226: }
227:
228: public void addTotalAvailable(KualiDecimal amount) {
229: totalAvailable = totalAvailable.add(amount);
230: }
231:
232: public void setTotalAvailable(KualiDecimal totalAvailable) {
233: this .totalAvailable = totalAvailable;
234: }
235:
236: public void addTotalCash(KualiDecimal amount) {
237: totalCash = totalCash.add(amount);
238: }
239:
240: public KualiDecimal getTotalCash() {
241: return totalCash;
242: }
243:
244: public void setTotalCash(KualiDecimal totalCash) {
245: this .totalCash = totalCash;
246: }
247:
248: public Map<String, OrgReversionUnitOfWorkCategoryAmount> getCategoryAmounts() {
249: return amounts;
250: }
251:
252: /**
253: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
254: */
255: @Override
256: public LinkedHashMap toStringMapper() {
257: LinkedHashMap pkMap = new LinkedHashMap();
258: pkMap.put("chartOfAccountsCode", this .chartOfAccountsCode);
259: pkMap.put("accountNbr", this .accountNumber);
260: pkMap.put("subAccountNbr", this .subAccountNumber);
261: return pkMap;
262: }
263:
264: /**
265: * Gets the accountNumber attribute.
266: *
267: * @return Returns the accountNumber.
268: */
269: public String getAccountNumber() {
270: return accountNumber;
271: }
272:
273: /**
274: * Sets the accountNumber attribute value.
275: *
276: * @param accountNumber The accountNumber to set.
277: */
278: public void setAccountNumber(String accountNumber) {
279: this .accountNumber = accountNumber;
280: }
281:
282: /**
283: * Gets the chartOfAccountsCode attribute.
284: *
285: * @return Returns the chartOfAccountsCode.
286: */
287: public String getChartOfAccountsCode() {
288: return chartOfAccountsCode;
289: }
290:
291: /**
292: * Sets the chartOfAccountsCode attribute value.
293: *
294: * @param chartOfAccountsCode The chartOfAccountsCode to set.
295: */
296: public void setChartOfAccountsCode(String chartOfAccountsCode) {
297: this .chartOfAccountsCode = chartOfAccountsCode;
298: }
299:
300: /**
301: * Gets the subAccountNumber attribute.
302: *
303: * @return Returns the subAccountNumber.
304: */
305: public String getSubAccountNumber() {
306: return subAccountNumber;
307: }
308:
309: /**
310: * Sets the subAccountNumber attribute value.
311: *
312: * @param subAccountNumber The subAccountNumber to set.
313: */
314: public void setSubAccountNumber(String subAccountNumber) {
315: this.subAccountNumber = subAccountNumber;
316: }
317:
318: }
|