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