View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.gl.businessobject;
20  
21  import org.kuali.kfs.sys.KFSConstants;
22  import org.kuali.rice.core.api.util.type.KualiDecimal;
23  import org.kuali.rice.krad.bo.BusinessObject;
24  
25  /**
26   * A representation of LedgerEntries, which are summaries that show up on Ledger Reports created by the scrubber and poster.
27   */
28  public class LedgerEntryForReporting implements BusinessObject{
29  
30      private String balanceType;
31      private String originCode;
32      private Integer fiscalYear;
33      private String period;
34      private int recordCount;
35      private KualiDecimal debitAmount;
36      private int debitCount;
37      private KualiDecimal creditAmount;
38      private int creditCount;
39      private KualiDecimal noDCAmount;
40      private int noDCCount;
41  
42      /**
43       * Constructs a LedgerEntry.java.
44       */
45      public LedgerEntryForReporting() {
46          this(null, null, null, null);
47      }
48  
49      /**
50       * Constructs a LedgerEntry.java.
51       * 
52       * @param fiscalYear
53       * @param period
54       * @param balanceType
55       * @param originCode
56       */
57      public LedgerEntryForReporting(Integer fiscalYear, String period, String balanceType, String originCode) {
58          this.fiscalYear = fiscalYear;
59          this.period = period;
60          this.balanceType = balanceType;
61          this.originCode = originCode;
62  
63          this.creditAmount = KualiDecimal.ZERO;
64          this.debitAmount = KualiDecimal.ZERO;
65          this.noDCAmount = KualiDecimal.ZERO;
66      }
67  
68      /**
69       * Add the amounts of the given ledger entry into those of current ledger entry, and update the counts of corresponding fields
70       * 
71       * @param addend the given ledger entry to be added into current one
72       */
73      public void add(LedgerEntryForReporting addend) {
74          this.creditAmount = this.creditAmount.add(addend.getCreditAmount());
75          this.creditCount += addend.getCreditCount();
76  
77          this.debitAmount = this.debitAmount.add(addend.getDebitAmount());
78          this.debitCount += addend.getDebitCount();
79  
80          this.noDCAmount = this.noDCAmount.add(addend.getNoDCAmount());
81          this.noDCCount += addend.getNoDCCount();
82  
83          this.recordCount = this.creditCount + this.debitCount + this.noDCCount;
84      }
85  
86      /**
87       * create or update a ledger entry with the array of information from the given entry summary object
88       * 
89       * @param entrySummary an entry summary to turn into a ledger entry
90       * @return a LedgerEntry created from the entrySummary array
91       */
92      public static LedgerEntryForReporting buildLedgerEntry(Object[] entrySummary) {
93          // extract the data from an array and use them to populate a ledger entry
94          Object oFiscalYear = entrySummary[0];
95          Object oPeriodCode = entrySummary[1];
96          Object oBalanceType = entrySummary[2];
97          Object oOriginCode = entrySummary[3];
98          Object oDebitCreditCode = entrySummary[4];
99          Object oAmount = entrySummary[5];
100         Object oCount = entrySummary[6];
101 
102         Integer fiscalYear = oFiscalYear != null ? new Integer(oFiscalYear.toString()) : null;
103         String periodCode = oPeriodCode != null ? oPeriodCode.toString() : "  ";
104         String balanceType = oBalanceType != null ? oBalanceType.toString() : "  ";
105         String originCode = oOriginCode != null ? oOriginCode.toString() : "  ";
106         String debitCreditCode = oDebitCreditCode != null ? oDebitCreditCode.toString() : " ";
107         KualiDecimal amount = oAmount != null ? new KualiDecimal(oAmount.toString()) : KualiDecimal.ZERO;
108         int count = oCount != null ? Integer.parseInt(oCount.toString()) : 0;
109 
110         // construct a ledger entry with the information fetched from the given array
111         LedgerEntryForReporting ledgerEntry = new LedgerEntryForReporting(fiscalYear, periodCode, balanceType, originCode);
112         if (KFSConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
113             ledgerEntry.setCreditAmount(amount);
114             ledgerEntry.setCreditCount(count);
115         }
116         else if (KFSConstants.GL_DEBIT_CODE.equals(debitCreditCode)) {
117             ledgerEntry.setDebitAmount(amount);
118             ledgerEntry.setDebitCount(count);
119         }
120         else {
121             ledgerEntry.setNoDCAmount(amount);
122             ledgerEntry.setNoDCCount(count);
123         }
124         ledgerEntry.setRecordCount(count);
125 
126         return ledgerEntry;
127     }
128 
129     /**
130      * Gets the balanceType attribute.
131      * 
132      * @return Returns the balanceType.
133      */
134     public String getBalanceType() {
135         return balanceType;
136     }
137 
138     /**
139      * Sets the balanceType attribute value.
140      * 
141      * @param balanceType The balanceType to set.
142      */
143     public void setBalanceType(String balanceType) {
144         this.balanceType = balanceType;
145     }
146 
147     /**
148      * Gets the creditAmount attribute.
149      * 
150      * @return Returns the creditAmount.
151      */
152     public KualiDecimal getCreditAmount() {
153         return creditAmount;
154     }
155 
156     /**
157      * Sets the creditAmount attribute value.
158      * 
159      * @param creditAmount The creditAmount to set.
160      */
161     public void setCreditAmount(KualiDecimal creditAmount) {
162         this.creditAmount = creditAmount;
163     }
164 
165     /**
166      * Gets the creditCount attribute.
167      * 
168      * @return Returns the creditCount.
169      */
170     public int getCreditCount() {
171         return creditCount;
172     }
173 
174     /**
175      * Sets the creditCount attribute value.
176      * 
177      * @param creditCount The creditCount to set.
178      */
179     public void setCreditCount(int creditCount) {
180         this.creditCount = creditCount;
181     }
182 
183     /**
184      * Gets the debitAmount attribute.
185      * 
186      * @return Returns the debitAmount.
187      */
188     public KualiDecimal getDebitAmount() {
189         return debitAmount;
190     }
191 
192     /**
193      * Sets the debitAmount attribute value.
194      * 
195      * @param debitAmount The debitAmount to set.
196      */
197     public void setDebitAmount(KualiDecimal debitAmount) {
198         this.debitAmount = debitAmount;
199     }
200 
201     /**
202      * Gets the debitCount attribute.
203      * 
204      * @return Returns the debitCount.
205      */
206     public int getDebitCount() {
207         return debitCount;
208     }
209 
210     /**
211      * Sets the debitCount attribute value.
212      * 
213      * @param debitCount The debitCount to set.
214      */
215     public void setDebitCount(int debitCount) {
216         this.debitCount = debitCount;
217     }
218 
219     /**
220      * Gets the fiscalYear attribute.
221      * 
222      * @return Returns the fiscalYear.
223      */
224     public Integer getFiscalYear() {
225         return fiscalYear;
226     }
227 
228     /**
229      * Sets the fiscalYear attribute value.
230      * 
231      * @param fiscalYear The fiscalYear to set.
232      */
233     public void setFiscalYear(Integer fiscalYear) {
234         this.fiscalYear = fiscalYear;
235     }
236 
237     /**
238      * Gets the noDCAmount attribute.
239      * 
240      * @return Returns the noDCAmount.
241      */
242     public KualiDecimal getNoDCAmount() {
243         return noDCAmount;
244     }
245 
246     /**
247      * Sets the noDCAmount attribute value.
248      * 
249      * @param noDCAmount The noDCAmount to set.
250      */
251     public void setNoDCAmount(KualiDecimal noDCAmount) {
252         this.noDCAmount = noDCAmount;
253     }
254 
255     /**
256      * Gets the noDCCount attribute.
257      * 
258      * @return Returns the noDCCount.
259      */
260     public int getNoDCCount() {
261         return noDCCount;
262     }
263 
264     /**
265      * Sets the noDCCount attribute value.
266      * 
267      * @param noDCCount The noDCCount to set.
268      */
269     public void setNoDCCount(int noDCCount) {
270         this.noDCCount = noDCCount;
271     }
272 
273     /**
274      * Gets the originCode attribute.
275      * 
276      * @return Returns the originCode.
277      */
278     public String getOriginCode() {
279         return originCode;
280     }
281 
282     /**
283      * Sets the originCode attribute value.
284      * 
285      * @param originCode The originCode to set.
286      */
287     public void setOriginCode(String originCode) {
288         this.originCode = originCode;
289     }
290 
291     /**
292      * Gets the period attribute.
293      * 
294      * @return Returns the period.
295      */
296     public String getPeriod() {
297         return period;
298     }
299 
300     /**
301      * Sets the period attribute value.
302      * 
303      * @param period The period to set.
304      */
305     public void setPeriod(String period) {
306         this.period = period;
307     }
308 
309     /**
310      * Gets the recordCount attribute.
311      * 
312      * @return Returns the recordCount.
313      */
314     public int getRecordCount() {
315         return recordCount;
316     }
317 
318     /**
319      * Sets the recordCount attribute value.
320      * 
321      * @param recordCount The recordCount to set.
322      */
323     public void setRecordCount(int recordCount) {
324         this.recordCount = recordCount;
325     }
326 
327     /**
328      * @see java.lang.Object#toString()
329      */
330     public String toString() {
331         StringBuffer ledgerEntryDescription = new StringBuffer();
332 
333         ledgerEntryDescription.append(fiscalYear + "\t");
334         ledgerEntryDescription.append(period + "\t");
335         ledgerEntryDescription.append(balanceType + "\t");
336         ledgerEntryDescription.append(originCode + "\t");
337         ledgerEntryDescription.append(recordCount + "\t");
338 
339         ledgerEntryDescription.append(debitAmount + "\t\t");
340         ledgerEntryDescription.append(debitCount + "\t");
341 
342         ledgerEntryDescription.append(creditAmount + "\t\t");
343         ledgerEntryDescription.append(creditCount + "\t");
344 
345         ledgerEntryDescription.append(noDCAmount + "\t\t");
346         ledgerEntryDescription.append(noDCCount + "\t");
347 
348         return ledgerEntryDescription.toString();
349     }
350 
351     public void prepareForWorkflow() {}
352     public void refresh() { }
353 }