001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.gl.util;
017:
018: import java.util.Iterator;
019:
020: import org.kuali.core.util.KualiDecimal;
021: import org.kuali.kfs.KFSConstants;
022: import org.kuali.module.gl.bo.OriginEntryFull;
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
165: .getTransactionDebitCreditCode())) {
166: creditAmount = creditAmount.add(originEntry
167: .getTransactionLedgerEntryAmount());
168: numCreditEntries++;
169: } else if (KFSConstants.GL_DEBIT_CODE.equals(originEntry
170: .getTransactionDebitCreditCode())) {
171: debitAmount = debitAmount.add(originEntry
172: .getTransactionLedgerEntryAmount());
173: numDebitEntries++;
174: } else {
175: otherAmount = otherAmount.add(originEntry
176: .getTransactionLedgerEntryAmount());
177: numOtherEntries++;
178: ;
179: }
180: }
181: }
182:
183: /**
184: * Adds up the values in the parameter totals object to the corresponding fields in this object
185: *
186: * @param anotherTotals another OriginEntryTotals to add to this OriginEntryTotals totals
187: */
188: public void incorporateTotals(OriginEntryTotals anotherTotals) {
189: creditAmount = creditAmount.add(anotherTotals.creditAmount);
190: debitAmount = debitAmount.add(anotherTotals.debitAmount);
191: otherAmount = otherAmount.add(anotherTotals.otherAmount);
192: numCreditEntries += anotherTotals.numCreditEntries;
193: numDebitEntries += anotherTotals.numDebitEntries;
194: numOtherEntries += anotherTotals.numOtherEntries;
195: }
196: }
|