001: /*
002: * Copyright 2006-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.util;
017:
018: import java.util.List;
019:
020: import org.apache.commons.lang.ArrayUtils;
021: import org.kuali.core.service.KualiConfigurationService;
022: import org.kuali.core.util.KualiDecimal;
023: import org.kuali.kfs.KFSConstants;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.module.chart.service.ObjectTypeService;
026:
027: /**
028: * This class represents a poster output summary entry
029: */
030: public class PosterOutputSummaryEntry implements Comparable {
031: private Integer universityFiscalYear;
032: private String fiscalPeriodCode;
033: private String balanceTypeCode;
034: private String fundGroup;
035: private String objectTypeCode;
036: private KualiDecimal creditAmount;
037: private KualiDecimal debitAmount;
038: private KualiDecimal budgetAmount;
039: private KualiDecimal netAmount;
040:
041: private final String[] assetExpenseObjectTypeCodes;
042:
043: public PosterOutputSummaryEntry() {
044: creditAmount = KualiDecimal.ZERO;
045: debitAmount = KualiDecimal.ZERO;
046: budgetAmount = KualiDecimal.ZERO;
047: netAmount = KualiDecimal.ZERO;
048:
049: KualiConfigurationService kualiConfigurationService = SpringContext
050: .getBean(KualiConfigurationService.class);
051:
052: ObjectTypeService objectTypeService = (ObjectTypeService) SpringContext
053: .getBean(ObjectTypeService.class);
054: List<String> objectTypes = objectTypeService
055: .getCurrentYearExpenseObjectTypes();
056: objectTypes.add(objectTypeService
057: .getCurrentYearAssetObjectType());
058:
059: assetExpenseObjectTypeCodes = objectTypes
060: .toArray(new String[0]);
061: }
062:
063: /**
064: * This method returns the key for the poster output summary entry
065: *
066: * @return String returns a string with format "universityFiscalYear-balanceTypeCode-fiscalPeriodCode-fundGroup"
067: */
068: public String getKey() {
069: return universityFiscalYear + "-" + balanceTypeCode + "-"
070: + fiscalPeriodCode + "-" + fundGroup;
071: }
072:
073: /**
074: * Add the amounts of two summary entries
075: *
076: * @param posterInputSummaryEntry a poster input summary entry which contains the amounts to add to this poster output summary entry
077: */
078: public void add(PosterOutputSummaryEntry posterInputSummaryEntry) {
079: // calculate the credit amount
080: setCreditAmount(creditAmount.add(posterInputSummaryEntry
081: .getCreditAmount()));
082:
083: // calculate the debit amount
084: setDebitAmount(debitAmount.add(posterInputSummaryEntry
085: .getDebitAmount()));
086:
087: // calculate the budget amount
088: setBudgetAmount(budgetAmount.add(posterInputSummaryEntry
089: .getBudgetAmount()));
090:
091: // calculate the net amount
092: setNetAmount(netAmount.add(posterInputSummaryEntry
093: .getNetAmount()));
094: }
095:
096: /**
097: * This method sets the amounts for this poster output summary entry.
098: *
099: * @param debitCreditCode credit code used to determine whether amounts is debit or credit
100: * @param objectTypeCode object type code associated with amount
101: * @param amount amount to add
102: */
103: public void setAmount(String debitCreditCode,
104: String objectTypeCode, KualiDecimal amount) {
105:
106: if (KFSConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
107: setCreditAmount(creditAmount.add(amount));
108: if (ArrayUtils.contains(assetExpenseObjectTypeCodes,
109: objectTypeCode)) {
110: setNetAmount(netAmount.subtract(amount));
111: } else {
112: setNetAmount(netAmount.add(amount));
113: }
114: } else if (KFSConstants.GL_DEBIT_CODE.equals(debitCreditCode)) {
115: setDebitAmount(debitAmount.add(amount));
116: if (ArrayUtils.contains(assetExpenseObjectTypeCodes,
117: objectTypeCode)) {
118: setNetAmount(netAmount.add(amount));
119: } else {
120: setNetAmount(netAmount.subtract(amount));
121: }
122: } else {
123: setNetAmount(netAmount.add(amount));
124: setBudgetAmount(amount);
125: }
126: }
127:
128: public String toString() {
129: String posterOutputSummaryEntry = "";
130: posterOutputSummaryEntry += "[UniversityFiscalYear: "
131: + this .getUniversityFiscalYear();
132: posterOutputSummaryEntry += ", FiscalPeriodCode: "
133: + this .getFiscalPeriodCode();
134: posterOutputSummaryEntry += ", BalanceTypeCode:"
135: + this .getBalanceTypeCode();
136: posterOutputSummaryEntry += ", FundGroup: "
137: + this .getFundGroup();
138: posterOutputSummaryEntry += ", ObjectTypeCode: "
139: + this .getObjectTypeCode();
140: posterOutputSummaryEntry += ", CreditAmount: "
141: + this .getCreditAmount();
142: posterOutputSummaryEntry += ", DebitAmount: "
143: + this .getDebitAmount();
144: posterOutputSummaryEntry += ", BudgetAmount: "
145: + this .getBudgetAmount();
146: posterOutputSummaryEntry += ", NetAmount: "
147: + this .getNetAmount();
148: posterOutputSummaryEntry += "]";
149:
150: return posterOutputSummaryEntry;
151: }
152:
153: /**
154: * Compares this poster output summary entry with another poster output summary entry based on key value
155: *
156: * @see java.lang.Comparable#compareTo(java.lang.Object)
157: */
158: public int compareTo(Object anotherPosterOutputSummaryEntry) {
159: PosterOutputSummaryEntry tempPosterOutputSummaryEntry = (PosterOutputSummaryEntry) anotherPosterOutputSummaryEntry;
160:
161: return getKey()
162: .compareTo(tempPosterOutputSummaryEntry.getKey());
163: }
164:
165: /**
166: * This method returns an empty PosterOutputSummaryEntry
167: *
168: * @param entrySummary
169: * @return
170: */
171: public static PosterOutputSummaryEntry buildPosterOutputSummaryEntry(
172: Object[] entrySummary) {
173: PosterOutputSummaryEntry posterOutputSummaryEntry = new PosterOutputSummaryEntry();
174: int indexOfField = 0;
175:
176: Object tempEntry = entrySummary[indexOfField++];
177: String entry = (tempEntry == null) ? "" : tempEntry.toString();
178: posterOutputSummaryEntry.setBalanceTypeCode(entry);
179:
180: tempEntry = entrySummary[indexOfField++];
181: entry = (tempEntry == null) ? null : tempEntry.toString();
182: posterOutputSummaryEntry.setUniversityFiscalYear(new Integer(
183: entry));
184:
185: tempEntry = entrySummary[indexOfField++];
186: entry = (tempEntry == null) ? "" : tempEntry.toString();
187: posterOutputSummaryEntry.setFiscalPeriodCode(entry);
188:
189: tempEntry = entrySummary[indexOfField++];
190: entry = (tempEntry == null) ? "" : tempEntry.toString();
191: posterOutputSummaryEntry.setFundGroup(entry);
192:
193: tempEntry = entrySummary[indexOfField++];
194: String objectTypeCode = (tempEntry == null) ? "" : tempEntry
195: .toString();
196: posterOutputSummaryEntry.setObjectTypeCode(objectTypeCode);
197:
198: tempEntry = entrySummary[indexOfField++];
199: String debitCreditCode = (tempEntry == null) ? KFSConstants.GL_BUDGET_CODE
200: : tempEntry.toString();
201:
202: tempEntry = entrySummary[indexOfField];
203: entry = (tempEntry == null) ? "0" : tempEntry.toString();
204: KualiDecimal amount = new KualiDecimal(entry);
205:
206: posterOutputSummaryEntry.setAmount(debitCreditCode,
207: objectTypeCode, amount);
208:
209: return posterOutputSummaryEntry;
210: }
211:
212: public String getFiscalPeriodCode() {
213: return fiscalPeriodCode;
214: }
215:
216: public void setFiscalPeriodCode(String fiscalPeriodCode) {
217: this .fiscalPeriodCode = fiscalPeriodCode;
218: }
219:
220: public String getBalanceTypeCode() {
221: return balanceTypeCode;
222: }
223:
224: public void setBalanceTypeCode(String balanceTypeCode) {
225: this .balanceTypeCode = balanceTypeCode;
226: }
227:
228: public KualiDecimal getBudgetAmount() {
229: return budgetAmount;
230: }
231:
232: public void setBudgetAmount(KualiDecimal budgetAmount) {
233: this .budgetAmount = budgetAmount;
234: }
235:
236: public KualiDecimal getCreditAmount() {
237: return creditAmount;
238: }
239:
240: public void setCreditAmount(KualiDecimal creditAmount) {
241: this .creditAmount = creditAmount;
242: }
243:
244: public KualiDecimal getDebitAmount() {
245: return debitAmount;
246: }
247:
248: public void setDebitAmount(KualiDecimal debitAmount) {
249: this .debitAmount = debitAmount;
250: }
251:
252: public String getFundGroup() {
253: return fundGroup;
254: }
255:
256: public void setFundGroup(String fundGroup) {
257: this .fundGroup = fundGroup;
258: }
259:
260: public String getObjectTypeCode() {
261: return objectTypeCode;
262: }
263:
264: public void setObjectTypeCode(String objectTypeCode) {
265: this .objectTypeCode = objectTypeCode;
266: }
267:
268: public Integer getUniversityFiscalYear() {
269: return universityFiscalYear;
270: }
271:
272: public void setUniversityFiscalYear(Integer universityFiscalYear) {
273: this .universityFiscalYear = universityFiscalYear;
274: }
275:
276: public KualiDecimal getNetAmount() {
277: return netAmount;
278: }
279:
280: public void setNetAmount(KualiDecimal netAmount) {
281: this.netAmount = netAmount;
282: }
283: }
|