View Javadoc
1   /*
2    * Copyright 2006-2009 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 org.kuali.ole.sys.OLEConstants;
19  import org.kuali.rice.core.api.util.type.KualiDecimal;
20  
21  /**
22   * A representation of LedgerEntries, which are summaries that show up on Ledger Reports created by the scrubber and poster.
23   */
24  public class LedgerEntry {
25  
26      private String balanceType;
27      private String originCode;
28      private Integer fiscalYear;
29      private String period;
30      private int recordCount;
31      private KualiDecimal debitAmount;
32      private int debitCount;
33      private KualiDecimal creditAmount;
34      private int creditCount;
35      private KualiDecimal noDCAmount;
36      private int noDCCount;
37  
38      /**
39       * Constructs a LedgerEntry.java.
40       */
41      public LedgerEntry() {
42          this(null, null, null, null);
43      }
44  
45      /**
46       * Constructs a LedgerEntry.java.
47       * 
48       * @param fiscalYear
49       * @param period
50       * @param balanceType
51       * @param originCode
52       */
53      public LedgerEntry(Integer fiscalYear, String period, String balanceType, String originCode) {
54          this.fiscalYear = fiscalYear;
55          this.period = period;
56          this.balanceType = balanceType;
57          this.originCode = originCode;
58  
59          this.creditAmount = KualiDecimal.ZERO;
60          this.debitAmount = KualiDecimal.ZERO;
61          this.noDCAmount = KualiDecimal.ZERO;
62      }
63      
64      /**
65       * Constructs a LedgerEntry.java.
66       * 
67       * @param fiscalYear
68       * @param period
69       * @param balanceType
70       * @param originCode
71       * @param debitCreditCode
72       * @param amount
73       * @param count
74       */
75      public LedgerEntry(Integer fiscalYear, String period, String balanceType, String originCode, String debitCreditCode, KualiDecimal amount, int count) {
76          this.fiscalYear = fiscalYear;
77          this.period = period;
78          this.balanceType = balanceType;
79          this.originCode = originCode;
80  
81          if (OLEConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
82              this.creditAmount = amount;
83              this.creditCount = count;
84          }
85          else if (OLEConstants.GL_DEBIT_CODE.equals(debitCreditCode)) {
86              this.debitAmount = amount;
87              this.debitCount = count;
88          }
89          else {
90              this.noDCAmount = amount;
91              this.noDCCount = count;
92          }
93          
94          this.recordCount = count;
95      }
96  
97      /**
98       * Add the amounts of the given ledger entry into those of current ledger entry, and update the counts of corresponding fields
99       * 
100      * @param addend the given ledger entry to be added into current one
101      */
102     public void add(LedgerEntry addend) {
103         this.creditAmount = this.creditAmount.add(addend.getCreditAmount());
104         this.creditCount += addend.getCreditCount();
105 
106         this.debitAmount = this.debitAmount.add(addend.getDebitAmount());
107         this.debitCount += addend.getDebitCount();
108 
109         this.noDCAmount = this.noDCAmount.add(addend.getNoDCAmount());
110         this.noDCCount += addend.getNoDCCount();
111 
112         this.recordCount = this.creditCount + this.debitCount + this.noDCCount;
113     }
114 
115     /**
116      * create or update a ledger entry with the array of information from the given entry summary object
117      * 
118      * @param entrySummary an entry summary to turn into a ledger entry
119      * @return a LedgerEntry created from the entrySummary array
120      */
121     public static LedgerEntry buildLedgerEntry(Object[] entrySummary) {
122         // extract the data from an array and use them to populate a ledger entry
123         Object oFiscalYear = entrySummary[0];
124         Object oPeriodCode = entrySummary[1];
125         Object oBalanceType = entrySummary[2];
126         Object oOriginCode = entrySummary[3];
127         Object oDebitCreditCode = entrySummary[4];
128         Object oAmount = entrySummary[5];
129         Object oCount = entrySummary[6];
130 
131         Integer fiscalYear = oFiscalYear != null ? new Integer(oFiscalYear.toString()) : null;
132         String periodCode = oPeriodCode != null ? oPeriodCode.toString() : "  ";
133         String balanceType = oBalanceType != null ? oBalanceType.toString() : "  ";
134         String originCode = oOriginCode != null ? oOriginCode.toString() : "  ";
135         String debitCreditCode = oDebitCreditCode != null ? oDebitCreditCode.toString() : " ";
136         KualiDecimal amount = oAmount != null ? new KualiDecimal(oAmount.toString()) : KualiDecimal.ZERO;
137         int count = oCount != null ? Integer.parseInt(oCount.toString()) : 0;
138 
139         // construct a ledger entry with the information fetched from the given array
140         LedgerEntry ledgerEntry = new LedgerEntry(fiscalYear, periodCode, balanceType, originCode);
141         if (OLEConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
142             ledgerEntry.setCreditAmount(amount);
143             ledgerEntry.setCreditCount(count);
144         }
145         else if (OLEConstants.GL_DEBIT_CODE.equals(debitCreditCode)) {
146             ledgerEntry.setDebitAmount(amount);
147             ledgerEntry.setDebitCount(count);
148         }
149         else {
150             ledgerEntry.setNoDCAmount(amount);
151             ledgerEntry.setNoDCCount(count);
152         }
153         ledgerEntry.setRecordCount(count);
154 
155         return ledgerEntry;
156     }
157 
158     /**
159      * Gets the balanceType attribute.
160      * 
161      * @return Returns the balanceType.
162      */
163     public String getBalanceType() {
164         return balanceType;
165     }
166 
167     /**
168      * Sets the balanceType attribute value.
169      * 
170      * @param balanceType The balanceType to set.
171      */
172     public void setBalanceType(String balanceType) {
173         this.balanceType = balanceType;
174     }
175 
176     /**
177      * Gets the creditAmount attribute.
178      * 
179      * @return Returns the creditAmount.
180      */
181     public KualiDecimal getCreditAmount() {
182         return creditAmount;
183     }
184 
185     /**
186      * Sets the creditAmount attribute value.
187      * 
188      * @param creditAmount The creditAmount to set.
189      */
190     public void setCreditAmount(KualiDecimal creditAmount) {
191         this.creditAmount = creditAmount;
192     }
193 
194     /**
195      * Gets the creditCount attribute.
196      * 
197      * @return Returns the creditCount.
198      */
199     public int getCreditCount() {
200         return creditCount;
201     }
202 
203     /**
204      * Sets the creditCount attribute value.
205      * 
206      * @param creditCount The creditCount to set.
207      */
208     public void setCreditCount(int creditCount) {
209         this.creditCount = creditCount;
210     }
211 
212     /**
213      * Gets the debitAmount attribute.
214      * 
215      * @return Returns the debitAmount.
216      */
217     public KualiDecimal getDebitAmount() {
218         return debitAmount;
219     }
220 
221     /**
222      * Sets the debitAmount attribute value.
223      * 
224      * @param debitAmount The debitAmount to set.
225      */
226     public void setDebitAmount(KualiDecimal debitAmount) {
227         this.debitAmount = debitAmount;
228     }
229 
230     /**
231      * Gets the debitCount attribute.
232      * 
233      * @return Returns the debitCount.
234      */
235     public int getDebitCount() {
236         return debitCount;
237     }
238 
239     /**
240      * Sets the debitCount attribute value.
241      * 
242      * @param debitCount The debitCount to set.
243      */
244     public void setDebitCount(int debitCount) {
245         this.debitCount = debitCount;
246     }
247 
248     /**
249      * Gets the fiscalYear attribute.
250      * 
251      * @return Returns the fiscalYear.
252      */
253     public Integer getFiscalYear() {
254         return fiscalYear;
255     }
256 
257     /**
258      * Sets the fiscalYear attribute value.
259      * 
260      * @param fiscalYear The fiscalYear to set.
261      */
262     public void setFiscalYear(Integer fiscalYear) {
263         this.fiscalYear = fiscalYear;
264     }
265 
266     /**
267      * Gets the noDCAmount attribute.
268      * 
269      * @return Returns the noDCAmount.
270      */
271     public KualiDecimal getNoDCAmount() {
272         return noDCAmount;
273     }
274 
275     /**
276      * Sets the noDCAmount attribute value.
277      * 
278      * @param noDCAmount The noDCAmount to set.
279      */
280     public void setNoDCAmount(KualiDecimal noDCAmount) {
281         this.noDCAmount = noDCAmount;
282     }
283 
284     /**
285      * Gets the noDCCount attribute.
286      * 
287      * @return Returns the noDCCount.
288      */
289     public int getNoDCCount() {
290         return noDCCount;
291     }
292 
293     /**
294      * Sets the noDCCount attribute value.
295      * 
296      * @param noDCCount The noDCCount to set.
297      */
298     public void setNoDCCount(int noDCCount) {
299         this.noDCCount = noDCCount;
300     }
301 
302     /**
303      * Gets the originCode attribute.
304      * 
305      * @return Returns the originCode.
306      */
307     public String getOriginCode() {
308         return originCode;
309     }
310 
311     /**
312      * Sets the originCode attribute value.
313      * 
314      * @param originCode The originCode to set.
315      */
316     public void setOriginCode(String originCode) {
317         this.originCode = originCode;
318     }
319 
320     /**
321      * Gets the period attribute.
322      * 
323      * @return Returns the period.
324      */
325     public String getPeriod() {
326         return period;
327     }
328 
329     /**
330      * Sets the period attribute value.
331      * 
332      * @param period The period to set.
333      */
334     public void setPeriod(String period) {
335         this.period = period;
336     }
337 
338     /**
339      * Gets the recordCount attribute.
340      * 
341      * @return Returns the recordCount.
342      */
343     public int getRecordCount() {
344         return recordCount;
345     }
346 
347     /**
348      * Sets the recordCount attribute value.
349      * 
350      * @param recordCount The recordCount to set.
351      */
352     public void setRecordCount(int recordCount) {
353         this.recordCount = recordCount;
354     }
355 
356     /**
357      * @see java.lang.Object#toString()
358      */
359     public String toString() {
360         StringBuffer ledgerEntryDescription = new StringBuffer();
361 
362         ledgerEntryDescription.append(fiscalYear + "\t");
363         ledgerEntryDescription.append(period + "\t");
364         ledgerEntryDescription.append(balanceType + "\t");
365         ledgerEntryDescription.append(originCode + "\t");
366         ledgerEntryDescription.append(recordCount + "\t");
367 
368         ledgerEntryDescription.append(debitAmount + "\t\t");
369         ledgerEntryDescription.append(debitCount + "\t");
370 
371         ledgerEntryDescription.append(creditAmount + "\t\t");
372         ledgerEntryDescription.append(creditCount + "\t");
373 
374         ledgerEntryDescription.append(noDCAmount + "\t\t");
375         ledgerEntryDescription.append(noDCCount + "\t");
376 
377         return ledgerEntryDescription.toString();
378     }
379 }