View Javadoc
1   /*
2    * Copyright 2007 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.batch.service.impl;
17  
18  import java.util.Iterator;
19  
20  import org.kuali.ole.gl.businessobject.OriginEntryFull;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.rice.core.api.util.type.KualiDecimal;
23  
24  /**
25   * This class holds information about the sums of a list of origin entries. This information includes
26   * total credit amount, debit amount, other amount, number of credit entries, number of debit entries,
27   * and number of "other" entries
28   */
29  public class OriginEntryTotals {
30  
31      protected KualiDecimal creditAmount;
32      protected KualiDecimal debitAmount;
33      protected KualiDecimal otherAmount;
34      protected int numCreditEntries;
35      protected int numDebitEntries;
36      protected int numOtherEntries;
37  
38      public OriginEntryTotals() {
39          creditAmount = KualiDecimal.ZERO;
40          debitAmount = KualiDecimal.ZERO;
41          otherAmount = KualiDecimal.ZERO;
42          numCreditEntries = 0;
43          numDebitEntries = 0;
44          numOtherEntries = 0;
45      }
46  
47      /**
48       * Gets the creditAmount attribute.
49       * 
50       * @return Returns the creditAmount.
51       */
52      public KualiDecimal getCreditAmount() {
53          return creditAmount;
54      }
55  
56      /**
57       * Sets the creditAmount attribute value.
58       * 
59       * @param creditAmount The creditAmount to set.
60       */
61      public void setCreditAmount(KualiDecimal creditAmount) {
62          this.creditAmount = creditAmount;
63      }
64  
65      /**
66       * Gets the debitAmount attribute.
67       * 
68       * @return Returns the debitAmount.
69       */
70      public KualiDecimal getDebitAmount() {
71          return debitAmount;
72      }
73  
74      /**
75       * Sets the debitAmount attribute value.
76       * 
77       * @param debitAmount The debitAmount to set.
78       */
79      public void setDebitAmount(KualiDecimal debitAmount) {
80          this.debitAmount = debitAmount;
81      }
82  
83      /**
84       * Gets the numCreditEntries attribute.
85       * 
86       * @return Returns the numCreditEntries.
87       */
88      public int getNumCreditEntries() {
89          return numCreditEntries;
90      }
91  
92      /**
93       * Sets the numCreditEntries attribute value.
94       * 
95       * @param numCreditEntries The numCreditEntries to set.
96       */
97      public void setNumCreditEntries(int numCreditEntries) {
98          this.numCreditEntries = numCreditEntries;
99      }
100 
101     /**
102      * Gets the numDebitEntries attribute.
103      * 
104      * @return Returns the numDebitEntries.
105      */
106     public int getNumDebitEntries() {
107         return numDebitEntries;
108     }
109 
110     /**
111      * Sets the numDebitEntries attribute value.
112      * 
113      * @param numDebitEntries The numDebitEntries to set.
114      */
115     public void setNumDebitEntries(int numDebitEntries) {
116         this.numDebitEntries = numDebitEntries;
117     }
118 
119     /**
120      * Gets the numOtherEntries attribute.
121      * 
122      * @return Returns the numOtherEntries.
123      */
124     public int getNumOtherEntries() {
125         return numOtherEntries;
126     }
127 
128     /**
129      * Sets the numOtherEntries attribute value.
130      * 
131      * @param numOtherEntries The numOtherEntries to set.
132      */
133     public void setNumOtherEntries(int numOtherEntries) {
134         this.numOtherEntries = numOtherEntries;
135     }
136 
137     /**
138      * Gets the otherAmount attribute.
139      * 
140      * @return Returns the otherAmount.
141      */
142     public KualiDecimal getOtherAmount() {
143         return otherAmount;
144     }
145 
146     /**
147      * Sets the otherAmount attribute value.
148      * 
149      * @param otherAmount The otherAmount to set.
150      */
151     public void setOtherAmount(KualiDecimal otherAmount) {
152         this.otherAmount = otherAmount;
153     }
154 
155     /**
156      * This method adds amount from origin entries and increments number totals for the appropriate type
157      * (i.e. credit, debit, or other).
158      * 
159      * @param entries
160      */
161     public void addToTotals(Iterator<OriginEntryFull> entries) {
162         while (entries.hasNext()) {
163             OriginEntryFull originEntry = entries.next();
164             if (OLEConstants.GL_CREDIT_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
165                 creditAmount = creditAmount.add(originEntry.getTransactionLedgerEntryAmount());
166                 numCreditEntries++;
167             }
168             else if (OLEConstants.GL_DEBIT_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
169                 debitAmount = debitAmount.add(originEntry.getTransactionLedgerEntryAmount());
170                 numDebitEntries++;
171             }
172             else {
173                 otherAmount = otherAmount.add(originEntry.getTransactionLedgerEntryAmount());
174                 numOtherEntries++;
175                 ;
176             }
177         }
178     }
179     
180     /**
181      * This method adds amount from origin entry and increments number totals for the appropriate type (i.e. credit, debit, or
182      * other).
183      * 
184      * @param entry
185      */
186     public void addToTotals(OriginEntryFull originEntry) {
187         if (OLEConstants.GL_CREDIT_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
188             creditAmount = creditAmount.add(originEntry.getTransactionLedgerEntryAmount());
189             numCreditEntries++;
190         }
191         else if (OLEConstants.GL_DEBIT_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
192             debitAmount = debitAmount.add(originEntry.getTransactionLedgerEntryAmount());
193             numDebitEntries++;
194         }
195         else {
196             otherAmount = otherAmount.add(originEntry.getTransactionLedgerEntryAmount());
197             numOtherEntries++;
198         }
199     }
200 
201     /**
202      * Adds up the values in the parameter totals object to the corresponding fields in this object
203      * 
204      * @param anotherTotals another OriginEntryTotals to add to this OriginEntryTotals totals
205      */
206     public void incorporateTotals(OriginEntryTotals anotherTotals) {
207         creditAmount = creditAmount.add(anotherTotals.creditAmount);
208         debitAmount = debitAmount.add(anotherTotals.debitAmount);
209         otherAmount = otherAmount.add(anotherTotals.otherAmount);
210         numCreditEntries += anotherTotals.numCreditEntries;
211         numDebitEntries += anotherTotals.numDebitEntries;
212         numOtherEntries += anotherTotals.numOtherEntries;
213     }
214 }