001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.gl.batch.service.impl;
017
018 import java.util.Iterator;
019
020 import org.kuali.kfs.gl.businessobject.OriginEntryFull;
021 import org.kuali.kfs.sys.KFSConstants;
022 import org.kuali.rice.kns.util.KualiDecimal;
023
024 /**
025 * This class holds information about the sums of a list of origin entries. This information includes
026 * total credit amount, debit amount, other amount, number of credit entries, number of debit entries,
027 * and number of "other" entries
028 */
029 public class OriginEntryTotals {
030
031 protected KualiDecimal creditAmount;
032 protected KualiDecimal debitAmount;
033 protected KualiDecimal otherAmount;
034 protected int numCreditEntries;
035 protected int numDebitEntries;
036 protected int numOtherEntries;
037
038 public OriginEntryTotals() {
039 creditAmount = KualiDecimal.ZERO;
040 debitAmount = KualiDecimal.ZERO;
041 otherAmount = KualiDecimal.ZERO;
042 numCreditEntries = 0;
043 numDebitEntries = 0;
044 numOtherEntries = 0;
045 }
046
047 /**
048 * Gets the creditAmount attribute.
049 *
050 * @return Returns the creditAmount.
051 */
052 public KualiDecimal getCreditAmount() {
053 return creditAmount;
054 }
055
056 /**
057 * Sets the creditAmount attribute value.
058 *
059 * @param creditAmount The creditAmount to set.
060 */
061 public void setCreditAmount(KualiDecimal creditAmount) {
062 this.creditAmount = creditAmount;
063 }
064
065 /**
066 * Gets the debitAmount attribute.
067 *
068 * @return Returns the debitAmount.
069 */
070 public KualiDecimal getDebitAmount() {
071 return debitAmount;
072 }
073
074 /**
075 * Sets the debitAmount attribute value.
076 *
077 * @param debitAmount The debitAmount to set.
078 */
079 public void setDebitAmount(KualiDecimal debitAmount) {
080 this.debitAmount = debitAmount;
081 }
082
083 /**
084 * Gets the numCreditEntries attribute.
085 *
086 * @return Returns the numCreditEntries.
087 */
088 public int getNumCreditEntries() {
089 return numCreditEntries;
090 }
091
092 /**
093 * Sets the numCreditEntries attribute value.
094 *
095 * @param numCreditEntries The numCreditEntries to set.
096 */
097 public void setNumCreditEntries(int numCreditEntries) {
098 this.numCreditEntries = numCreditEntries;
099 }
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 (KFSConstants.GL_CREDIT_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
165 creditAmount = creditAmount.add(originEntry.getTransactionLedgerEntryAmount());
166 numCreditEntries++;
167 }
168 else if (KFSConstants.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 (KFSConstants.GL_CREDIT_CODE.equals(originEntry.getTransactionDebitCreditCode())) {
188 creditAmount = creditAmount.add(originEntry.getTransactionLedgerEntryAmount());
189 numCreditEntries++;
190 }
191 else if (KFSConstants.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 }