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.util.ArrayList;
19 import java.util.LinkedHashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.ole.gl.businessobject.LedgerBalanceTypeSummaryTotalLine;
25 import org.kuali.ole.gl.businessobject.LedgerSummaryDetailLine;
26 import org.kuali.ole.gl.businessobject.LedgerSummaryTotalLine;
27 import org.kuali.ole.gl.businessobject.OriginEntryInformation;
28 import org.kuali.ole.sys.DynamicCollectionComparator;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.service.ReportWriterService;
31
32
33
34
35 public class LedgerSummaryReport {
36 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LedgerSummaryReport.class);
37
38 private LedgerSummaryTotalLine ledgerTotalLine;
39 private Map<String, LedgerBalanceTypeSummaryTotalLine> balanceTypeTotals;
40 Map<String, LedgerSummaryDetailLine> details;
41
42
43
44
45 public LedgerSummaryReport() {
46 ledgerTotalLine = new LedgerSummaryTotalLine();
47 balanceTypeTotals = new LinkedHashMap<String, LedgerBalanceTypeSummaryTotalLine>();
48 details = new LinkedHashMap<String, LedgerSummaryDetailLine>();
49 }
50
51
52
53
54
55 public void summarizeEntry(OriginEntryInformation entry) {
56 LedgerBalanceTypeSummaryTotalLine balanceTypeTotal = getBalanceTypeSummaryTotalLine(entry, balanceTypeTotals);
57 LedgerSummaryDetailLine detailLine = getDetailLine(entry, details);
58 addEntryToLedgerSummaries(entry, ledgerTotalLine, balanceTypeTotal, detailLine);
59 }
60
61
62
63
64
65
66
67 protected LedgerBalanceTypeSummaryTotalLine getBalanceTypeSummaryTotalLine(OriginEntryInformation entry, Map<String, LedgerBalanceTypeSummaryTotalLine> balanceTypeTotals) {
68 final String balanceTypeCode = (StringUtils.isBlank(entry.getFinancialBalanceTypeCode())) ? " " : entry.getFinancialBalanceTypeCode();
69 LedgerBalanceTypeSummaryTotalLine balanceTypeTotal = balanceTypeTotals.get(balanceTypeCode);
70 if (balanceTypeTotal == null) {
71 balanceTypeTotal = new LedgerBalanceTypeSummaryTotalLine(balanceTypeCode);
72 balanceTypeTotals.put(balanceTypeCode, balanceTypeTotal);
73 }
74 return balanceTypeTotal;
75 }
76
77
78
79
80
81
82
83 protected LedgerSummaryDetailLine getDetailLine(OriginEntryInformation entry, Map<String, LedgerSummaryDetailLine> detailLines) {
84 final String key = LedgerSummaryDetailLine.getKeyString(entry);
85 LedgerSummaryDetailLine detailLine = detailLines.get(key);
86 if (detailLine == null) {
87 detailLine = new LedgerSummaryDetailLine(entry.getFinancialBalanceTypeCode(), entry.getFinancialSystemOriginationCode(), entry.getUniversityFiscalYear(), entry.getUniversityFiscalPeriodCode());
88 detailLines.put(detailLine.getKey(), detailLine);
89 }
90 return detailLine;
91 }
92
93
94
95
96
97
98
99
100 protected void addEntryToLedgerSummaries(OriginEntryInformation originEntry, LedgerSummaryTotalLine totalLine, LedgerBalanceTypeSummaryTotalLine balanceTypeTotal, LedgerSummaryDetailLine detailLine) {
101 if (originEntry.getTransactionDebitCreditCode() != null && originEntry.getTransactionDebitCreditCode().equals(OLEConstants.GL_DEBIT_CODE)) {
102 totalLine.addDebitAmount(originEntry.getTransactionLedgerEntryAmount());
103 balanceTypeTotal.addDebitAmount(originEntry.getTransactionLedgerEntryAmount());
104 detailLine.addDebitAmount(originEntry.getTransactionLedgerEntryAmount());
105 } else if (originEntry.getTransactionDebitCreditCode() != null && originEntry.getTransactionDebitCreditCode().equals(OLEConstants.GL_CREDIT_CODE)) {
106 totalLine.addCreditAmount(originEntry.getTransactionLedgerEntryAmount());
107 balanceTypeTotal.addCreditAmount(originEntry.getTransactionLedgerEntryAmount());
108 detailLine.addCreditAmount(originEntry.getTransactionLedgerEntryAmount());
109 } else{
110 totalLine.addBudgetAmount(originEntry.getTransactionLedgerEntryAmount());
111 balanceTypeTotal.addBudgetAmount(originEntry.getTransactionLedgerEntryAmount());
112 detailLine.addBudgetAmount(originEntry.getTransactionLedgerEntryAmount());
113 }
114 }
115
116
117
118
119
120 public void writeReport(ReportWriterService reportWriterService) {
121 if (details.size() > 0) {
122 List<LedgerSummaryDetailLine> detailList = new ArrayList<LedgerSummaryDetailLine>(details.values());
123 DynamicCollectionComparator.sort(detailList, LedgerSummaryDetailLine.keyFields);
124
125 reportWriterService.writeTableHeader(detailList.get(0));
126 String currentBalanceType = detailList.get(0).getFinancialBalanceTypeCode();
127 currentBalanceType = StringUtils.isBlank(currentBalanceType) ? " " : currentBalanceType;
128
129 for (LedgerSummaryDetailLine detailLine : detailList) {
130 String detailLineBalanceType = (StringUtils.isBlank(detailLine.getFinancialBalanceTypeCode())) ? " " : detailLine.getFinancialBalanceTypeCode();
131 if (!detailLineBalanceType.equals(currentBalanceType)) {
132 LedgerBalanceTypeSummaryTotalLine subTitleLine = balanceTypeTotals.get(currentBalanceType);
133
134 if (subTitleLine != null) {
135 reportWriterService.writeTableRow(subTitleLine);
136 reportWriterService.writeTableRowSeparationLine(subTitleLine);
137 }
138 currentBalanceType = detailLineBalanceType;
139 }
140
141 reportWriterService.writeTableRow(detailLine);
142 }
143 final LedgerBalanceTypeSummaryTotalLine lastLine = balanceTypeTotals.get(detailList.get(detailList.size()-1).getFinancialBalanceTypeCode());
144 if (lastLine != null) {
145 reportWriterService.writeTableRow(lastLine);
146 }
147
148 reportWriterService.writeTableRowSeparationLine(ledgerTotalLine);
149 reportWriterService.writeTableRow(ledgerTotalLine);
150 }
151 }
152
153 }