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.report;
17  
18  import java.util.Iterator;
19  
20  import org.kuali.ole.gl.businessobject.Transaction;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.service.ReportWriterService;
23  import org.kuali.rice.core.api.util.type.KualiDecimal;
24  
25  /**
26   * This class prints out a transaction listing report. This is different from a transaction report in that this lists all the
27   * transactions and a total amount. The transaction report shows the primary key from transactions and a list of messages for each
28   * one.
29   */
30  public class TransactionListingReport {
31      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TransactionListingReport.class);
32  
33      protected int transactionCount;
34      protected KualiDecimal debitTotal;
35      protected KualiDecimal creditTotal;
36      protected KualiDecimal budgetTotal;
37      
38      public TransactionListingReport() {
39          super();
40          
41          transactionCount = 0;
42          debitTotal = KualiDecimal.ZERO;
43          creditTotal = KualiDecimal.ZERO;
44          budgetTotal = KualiDecimal.ZERO;
45      }
46      
47      /**
48       * This will write a transaction to the report. It collects data in order for this to be a listing, hence it is the developers responsibility
49       * to call generateStatistics after printing the listing.
50       * 
51       * @param reportWriterService destination report
52       * @param transaction Transaction to be printed
53       */
54      public void generateReport(ReportWriterService reportWriterService, Transaction transaction) {
55          LOG.debug("generateReport() started");
56  
57          if (transaction != null) {
58              if (transactionCount == 0) {
59                  reportWriterService.writeTableHeader(transaction);
60              }
61              
62              reportWriterService.writeTableRow(transaction);
63              
64              if (OLEConstants.GL_DEBIT_CODE.equals(transaction.getTransactionDebitCreditCode())) {
65                  debitTotal = debitTotal.add(transaction.getTransactionLedgerEntryAmount());
66              }
67              if (OLEConstants.GL_CREDIT_CODE.equals(transaction.getTransactionDebitCreditCode())) {
68                  creditTotal = creditTotal.add(transaction.getTransactionLedgerEntryAmount());
69              }
70              if (!OLEConstants.GL_CREDIT_CODE.equals(transaction.getTransactionDebitCreditCode()) && !OLEConstants.GL_DEBIT_CODE.equals(transaction.getTransactionDebitCreditCode())) {
71                  budgetTotal = budgetTotal.add(transaction.getTransactionLedgerEntryAmount());
72              }
73              transactionCount++;
74          }
75      }
76      
77      /**
78       * Writes the statistics to the report that were collected by this class
79       * 
80       * @param reportWriterService destination report
81       */
82      public void generateStatistics(ReportWriterService reportWriterService) {
83          LOG.debug("generateStatistics() started");
84          
85          reportWriterService.writeStatisticLine("Total Transactions                %,9d", transactionCount);
86          reportWriterService.writeStatisticLine("Total Debit Amount                %,9.2f", debitTotal.doubleValue());
87          reportWriterService.writeStatisticLine("Total Credit Amount               %,9.2f", creditTotal.doubleValue());
88          reportWriterService.writeStatisticLine("Total Budget Amount               %,9.2f", budgetTotal.doubleValue());
89      }
90      
91      /**
92       * This will generate a report on the transactions passed to it
93       * 
94       * @param reportWriterService destination report
95       * @param transactions Transactions sorted properly
96       */
97      public void generateReport(ReportWriterService reportWriterService, Iterator<? extends Transaction> transactions) {
98          LOG.debug("generateReport() started");
99  
100         if (transactions != null) {
101             while (transactions.hasNext()) {
102                 Transaction tran = (Transaction) transactions.next();
103 
104                 this.generateReport(reportWriterService, tran);
105             }
106         }
107 
108         this.generateStatistics(reportWriterService);
109     }
110 }