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.businessobject;
017    
018    import org.kuali.kfs.sys.KFSConstants;
019    import org.kuali.rice.kns.bo.BusinessObject;
020    import org.kuali.rice.kns.util.KualiDecimal;
021    
022    /**
023     * A representation of LedgerEntries, which are summaries that show up on Ledger Reports created by the scrubber and poster.
024     */
025    public class LedgerEntryForReporting implements BusinessObject{
026    
027        private String balanceType;
028        private String originCode;
029        private Integer fiscalYear;
030        private String period;
031        private int recordCount;
032        private KualiDecimal debitAmount;
033        private int debitCount;
034        private KualiDecimal creditAmount;
035        private int creditCount;
036        private KualiDecimal noDCAmount;
037        private int noDCCount;
038    
039        /**
040         * Constructs a LedgerEntry.java.
041         */
042        public LedgerEntryForReporting() {
043            this(null, null, null, null);
044        }
045    
046        /**
047         * Constructs a LedgerEntry.java.
048         * 
049         * @param fiscalYear
050         * @param period
051         * @param balanceType
052         * @param originCode
053         */
054        public LedgerEntryForReporting(Integer fiscalYear, String period, String balanceType, String originCode) {
055            this.fiscalYear = fiscalYear;
056            this.period = period;
057            this.balanceType = balanceType;
058            this.originCode = originCode;
059    
060            this.creditAmount = KualiDecimal.ZERO;
061            this.debitAmount = KualiDecimal.ZERO;
062            this.noDCAmount = KualiDecimal.ZERO;
063        }
064    
065        /**
066         * Add the amounts of the given ledger entry into those of current ledger entry, and update the counts of corresponding fields
067         * 
068         * @param addend the given ledger entry to be added into current one
069         */
070        public void add(LedgerEntryForReporting addend) {
071            this.creditAmount = this.creditAmount.add(addend.getCreditAmount());
072            this.creditCount += addend.getCreditCount();
073    
074            this.debitAmount = this.debitAmount.add(addend.getDebitAmount());
075            this.debitCount += addend.getDebitCount();
076    
077            this.noDCAmount = this.noDCAmount.add(addend.getNoDCAmount());
078            this.noDCCount += addend.getNoDCCount();
079    
080            this.recordCount = this.creditCount + this.debitCount + this.noDCCount;
081        }
082    
083        /**
084         * create or update a ledger entry with the array of information from the given entry summary object
085         * 
086         * @param entrySummary an entry summary to turn into a ledger entry
087         * @return a LedgerEntry created from the entrySummary array
088         */
089        public static LedgerEntryForReporting buildLedgerEntry(Object[] entrySummary) {
090            // extract the data from an array and use them to populate a ledger entry
091            Object oFiscalYear = entrySummary[0];
092            Object oPeriodCode = entrySummary[1];
093            Object oBalanceType = entrySummary[2];
094            Object oOriginCode = entrySummary[3];
095            Object oDebitCreditCode = entrySummary[4];
096            Object oAmount = entrySummary[5];
097            Object oCount = entrySummary[6];
098    
099            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 (KFSConstants.GL_CREDIT_CODE.equals(debitCreditCode)) {
110                ledgerEntry.setCreditAmount(amount);
111                ledgerEntry.setCreditCount(count);
112            }
113            else if (KFSConstants.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    }