1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.report;
17
18 import java.text.MessageFormat;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.LinkedHashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.kuali.ole.gl.businessobject.OriginEntryInformation;
26 import org.kuali.ole.gl.businessobject.PosterOutputSummaryBalanceTypeFiscalYearAndPeriodTotal;
27 import org.kuali.ole.gl.businessobject.PosterOutputSummaryBalanceTypeFiscalYearTotal;
28 import org.kuali.ole.gl.businessobject.PosterOutputSummaryBalanceTypeTotal;
29 import org.kuali.ole.gl.businessobject.PosterOutputSummaryEntry;
30 import org.kuali.ole.gl.businessobject.PosterOutputSummaryTotal;
31 import org.kuali.ole.gl.businessobject.Transaction;
32 import org.kuali.ole.gl.service.PosterOutputSummaryService;
33 import org.kuali.ole.sys.OLEKeyConstants;
34 import org.kuali.ole.sys.context.SpringContext;
35 import org.kuali.ole.sys.service.ReportWriterService;
36 import org.kuali.rice.core.api.config.property.ConfigurationService;
37
38
39
40
41 public class PosterOutputSummaryReport {
42 private Map<String, PosterOutputSummaryEntry> posterOutputSummaryEntries;
43 private PosterOutputSummaryTotal posterOutputSummaryTotal;
44 private PosterOutputSummaryService posterOutputSummaryService;
45
46
47
48
49 public PosterOutputSummaryReport() {
50 posterOutputSummaryTotal = new PosterOutputSummaryTotal();
51 posterOutputSummaryEntries = new LinkedHashMap<String, PosterOutputSummaryEntry>();
52 }
53
54
55
56
57
58 public void summarize(Transaction transaction) {
59 getPosterOutputSummaryService().summarize(transaction, posterOutputSummaryEntries);
60 }
61
62
63
64
65
66 public void summarize(OriginEntryInformation originEntry) {
67 getPosterOutputSummaryService().summarize(originEntry, posterOutputSummaryEntries);
68 }
69
70
71
72
73
74 public void writeReport(ReportWriterService reportWriterService) {
75 List<PosterOutputSummaryEntry> entries = new ArrayList<PosterOutputSummaryEntry>(posterOutputSummaryEntries.values());
76
77 if (entries.size() > 0) {
78 Collections.sort(entries, getPosterOutputSummaryService().getEntryComparator());
79 final ConfigurationService configurationService = SpringContext.getBean(ConfigurationService.class);
80
81 String currentBalanceTypeCode = entries.get(0).getBalanceTypeCode();
82 PosterOutputSummaryBalanceTypeTotal balanceTypeTotal = new PosterOutputSummaryBalanceTypeTotal(currentBalanceTypeCode);
83 Integer currentFiscalYear = entries.get(0).getUniversityFiscalYear();
84 PosterOutputSummaryBalanceTypeFiscalYearTotal balanceTypeFiscalYearTotal = new PosterOutputSummaryBalanceTypeFiscalYearTotal(currentBalanceTypeCode, currentFiscalYear);
85 String currentFiscalPeriod = entries.get(0).getFiscalPeriodCode();
86 PosterOutputSummaryBalanceTypeFiscalYearAndPeriodTotal balanceTypeFiscalYearAndPeriodTotal = new PosterOutputSummaryBalanceTypeFiscalYearAndPeriodTotal(currentBalanceTypeCode, currentFiscalYear, currentFiscalPeriod);
87
88 final String titleMessage = configurationService.getPropertyValueAsString(OLEKeyConstants.MESSAGE_REPORT_POSTER_OUTPUT_SUMMARY_TITLE_LINE);
89 String formattedTitle = MessageFormat.format(titleMessage, entries.get(0).getUniversityFiscalYear().toString(), entries.get(0).getBalanceTypeCode());
90
91 reportWriterService.writeFormattedMessageLine(formattedTitle);
92 reportWriterService.writeTableHeader(entries.get(0));
93
94 for (PosterOutputSummaryEntry entry : entries) {
95 if (!entry.getBalanceTypeCode().equals(currentBalanceTypeCode)) {
96 reportWriterService.writeTableRow(balanceTypeFiscalYearAndPeriodTotal);
97 reportWriterService.writeTableRow(balanceTypeFiscalYearTotal);
98 reportWriterService.writeTableRow(balanceTypeTotal);
99
100 balanceTypeFiscalYearAndPeriodTotal = new PosterOutputSummaryBalanceTypeFiscalYearAndPeriodTotal(entry.getBalanceTypeCode(), entry.getUniversityFiscalYear(), entry.getFiscalPeriodCode());
101 balanceTypeFiscalYearTotal = new PosterOutputSummaryBalanceTypeFiscalYearTotal(entry.getBalanceTypeCode(), entry.getUniversityFiscalYear());
102 balanceTypeTotal = new PosterOutputSummaryBalanceTypeTotal(entry.getBalanceTypeCode());
103 currentBalanceTypeCode = entry.getBalanceTypeCode();
104 currentFiscalYear = entry.getUniversityFiscalYear();
105 currentFiscalPeriod = entry.getFiscalPeriodCode();
106
107
108 reportWriterService.pageBreak();
109 formattedTitle = MessageFormat.format(titleMessage, currentFiscalYear.toString(), currentBalanceTypeCode);
110 reportWriterService.writeFormattedMessageLine(formattedTitle);
111 reportWriterService.writeTableHeader(entry);
112 } else if (!entry.getUniversityFiscalYear().equals(currentFiscalYear)) {
113 reportWriterService.writeTableRow(balanceTypeFiscalYearAndPeriodTotal);
114 reportWriterService.writeTableRow(balanceTypeFiscalYearTotal);
115
116 balanceTypeFiscalYearAndPeriodTotal = new PosterOutputSummaryBalanceTypeFiscalYearAndPeriodTotal(entry.getBalanceTypeCode(), entry.getUniversityFiscalYear(), entry.getFiscalPeriodCode());
117 balanceTypeFiscalYearTotal = new PosterOutputSummaryBalanceTypeFiscalYearTotal(entry.getBalanceTypeCode(), entry.getUniversityFiscalYear());
118 currentFiscalYear = entry.getUniversityFiscalYear();
119 currentFiscalPeriod = entry.getFiscalPeriodCode();
120 } else if (!entry.getFiscalPeriodCode().equals(currentFiscalPeriod)) {
121 reportWriterService.writeTableRow(balanceTypeFiscalYearAndPeriodTotal);
122
123 balanceTypeFiscalYearAndPeriodTotal = new PosterOutputSummaryBalanceTypeFiscalYearAndPeriodTotal(entry.getBalanceTypeCode(), entry.getUniversityFiscalYear(), entry.getFiscalPeriodCode());
124 currentFiscalPeriod = entry.getFiscalPeriodCode();
125 }
126
127 reportWriterService.writeTableRow(entry);
128 balanceTypeFiscalYearAndPeriodTotal.addAmount(entry);
129 balanceTypeFiscalYearTotal.addAmount(entry);
130 balanceTypeTotal.addAmount(entry);
131 posterOutputSummaryTotal.addAmount(entry);
132 }
133
134 reportWriterService.writeTableRow(balanceTypeFiscalYearAndPeriodTotal);
135 reportWriterService.writeTableRow(balanceTypeFiscalYearTotal);
136 reportWriterService.writeTableRow(balanceTypeTotal);
137 reportWriterService.writeNewLines(1);
138 reportWriterService.writeTableRow(posterOutputSummaryTotal);
139 }
140 }
141
142
143
144
145 public PosterOutputSummaryService getPosterOutputSummaryService() {
146 if (posterOutputSummaryService == null) {
147 posterOutputSummaryService = SpringContext.getBean(PosterOutputSummaryService.class);
148 }
149
150 return posterOutputSummaryService;
151 }
152 }