1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.businessobject;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.apache.commons.lang.StringUtils;
22
23
24
25
26 public class LedgerEntryHolder {
27 private Map ledgerEntries;
28 private Map subtotals;
29 private LedgerEntryForReporting grandTotal;
30
31 private static final String GRAND_TOTAL = "Grand Total";
32 private static final String SUB_TOTAL = "Subtotal";
33
34
35
36
37 public LedgerEntryHolder() {
38 ledgerEntries = new HashMap();
39 subtotals = new HashMap();
40 grandTotal = new LedgerEntryForReporting(null, null, null, GRAND_TOTAL);
41 }
42
43
44
45
46
47
48
49
50 public void insertLedgerEntry(LedgerEntryForReporting newLedgerEntry, boolean calculateTotal) {
51 Integer fiscalYear = newLedgerEntry.getFiscalYear();
52 String periodCode = newLedgerEntry.getPeriod();
53
54 String balanceType = newLedgerEntry.getBalanceType();
55 String originCode = newLedgerEntry.getOriginCode();
56
57 String keyOfLedgerEntry = balanceType + "-" + originCode + "-" + fiscalYear + "-" + periodCode;
58
59 if (!ledgerEntries.containsKey(keyOfLedgerEntry)) {
60 ledgerEntries.put(keyOfLedgerEntry, newLedgerEntry);
61 }
62 else {
63 LedgerEntryForReporting ledgerEntry = (LedgerEntryForReporting) ledgerEntries.get(keyOfLedgerEntry);
64 ledgerEntry.add(newLedgerEntry);
65 }
66
67
68 if (calculateTotal) {
69 updateSubtotal(newLedgerEntry);
70 updateGrandTotal(newLedgerEntry);
71 }
72 }
73
74
75
76
77
78
79 private void updateSubtotal(LedgerEntryForReporting newLedgerEntry) {
80 String groupingKey = newLedgerEntry.getBalanceType();
81
82 if (StringUtils.isBlank(groupingKey)) {
83 return;
84 }
85
86 LedgerEntryForReporting ledgerEntry = null;
87 if (!subtotals.containsKey(groupingKey)) {
88 ledgerEntry = new LedgerEntryForReporting(null, "", newLedgerEntry.getBalanceType(), SUB_TOTAL);
89 subtotals.put(groupingKey, ledgerEntry);
90 }
91 else {
92 ledgerEntry = (LedgerEntryForReporting) subtotals.get(groupingKey);
93 }
94 ledgerEntry.add(newLedgerEntry);
95 }
96
97
98
99
100
101
102 private void updateGrandTotal(LedgerEntryForReporting newLedgerEntry) {
103 this.grandTotal.add(newLedgerEntry);
104 }
105
106
107
108
109
110
111 public LedgerEntryForReporting getGrandTotal() {
112 return grandTotal;
113 }
114
115
116
117
118
119
120 public Map getLedgerEntries() {
121 return ledgerEntries;
122 }
123
124
125
126
127
128
129 public Map getSubtotals() {
130 return subtotals;
131 }
132 }