1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.ole.pdp.businessobject;
18
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.LinkedHashMap;
22 import java.util.List;
23
24 import org.apache.commons.lang.ObjectUtils;
25 import org.kuali.ole.pdp.PdpPropertyConstants;
26 import org.kuali.ole.pdp.service.PaymentGroupService;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.rice.core.api.util.type.KualiDecimal;
29 import org.kuali.rice.core.api.util.type.KualiInteger;
30 import org.kuali.rice.krad.bo.TransientBusinessObjectBase;
31 import org.kuali.rice.krad.service.BusinessObjectService;
32
33
34
35
36 public class FormatProcessSummary extends TransientBusinessObjectBase {
37
38 private List<ProcessSummary> processSummaryList;
39 private KualiInteger totalCount;
40 private KualiDecimal totalAmount;
41 private KualiInteger processId;
42
43
44
45
46 public FormatProcessSummary() {
47 super();
48 processSummaryList = new ArrayList<ProcessSummary>();
49 totalCount = KualiInteger.ZERO;
50 totalAmount = KualiDecimal.ZERO;
51 }
52
53
54
55
56
57
58 public void add(PaymentGroup paymentGroup) {
59 ProcessSummary ps = findProcessSummary(paymentGroup);
60
61
62 if (ps == null) {
63 ps = new ProcessSummary();
64 ps.setBeginDisbursementNbr(KualiInteger.ZERO);
65 ps.setCustomer(paymentGroup.getBatch().getCustomerProfile());
66 ps.setDisbursementType(paymentGroup.getDisbursementType());
67 ps.setEndDisbursementNbr(KualiInteger.ZERO);
68 ps.setProcess(paymentGroup.getProcess());
69 ps.setProcessTotalAmount(KualiDecimal.ZERO);
70 ps.setProcessTotalCount(KualiInteger.ZERO);
71 ps.setSortGroupId(new KualiInteger(SpringContext.getBean(PaymentGroupService.class).getSortGroupId(paymentGroup)));
72 processSummaryList.add(ps);
73
74
75 if (processId == null) {
76 processId = paymentGroup.getProcessId();
77 }
78 }
79
80
81 ps.setProcessTotalAmount(ps.getProcessTotalAmount().add(paymentGroup.getNetPaymentAmount()));
82 ps.setProcessTotalCount(new KualiInteger(ps.getProcessTotalCount().intValue() + paymentGroup.getPaymentDetails().size()));
83 totalAmount = totalAmount.add(paymentGroup.getNetPaymentAmount());
84 totalCount = totalCount.add(new KualiInteger(paymentGroup.getPaymentDetails().size()));
85 }
86
87
88
89
90
91
92 public void save() {
93 for (Iterator<ProcessSummary> iter = processSummaryList.iterator(); iter.hasNext();) {
94 ProcessSummary ps = (ProcessSummary) iter.next();
95
96 SpringContext.getBean(BusinessObjectService.class).save(ps);
97 }
98 }
99
100
101
102
103
104
105 private ProcessSummary findProcessSummary(PaymentGroup paymentGroup) {
106
107 for (Iterator<ProcessSummary> iter = processSummaryList.iterator(); iter.hasNext();) {
108 ProcessSummary processSummary = (ProcessSummary) iter.next();
109
110 if(ObjectUtils.equals(processSummary.getCustomer(), paymentGroup.getBatch().getCustomerProfile()) && ObjectUtils.equals(processSummary.getDisbursementType(), paymentGroup.getDisbursementType()) && (processSummary.getSortGroupId().intValue()==SpringContext.getBean(PaymentGroupService.class).getSortGroupId(paymentGroup)) && ObjectUtils.equals(processSummary.getProcess(), paymentGroup.getProcess())) {
111 return processSummary;
112 }
113 }
114 return null;
115 }
116
117
118
119
120
121 public void setDisbursementNumber(PaymentGroup paymentGroup, Integer disbursementNumber) {
122 ProcessSummary processSummary = findProcessSummary(paymentGroup);
123 if (processSummary != null) {
124 if (processSummary.getBeginDisbursementNbr().isZero()) {
125 processSummary.setBeginDisbursementNbr(new KualiInteger(disbursementNumber));
126 processSummary.setEndDisbursementNbr(new KualiInteger(disbursementNumber));
127 }
128 else {
129 processSummary.setEndDisbursementNbr(new KualiInteger(disbursementNumber));
130 }
131 }
132 }
133
134
135
136
137 @SuppressWarnings("rawtypes")
138
139 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
140 LinkedHashMap<String, List<ProcessSummary>> m = new LinkedHashMap<String, List<ProcessSummary>>();
141
142 m.put(PdpPropertyConstants.FormatProcessSummary.PROCESS_SUMMARY, this.processSummaryList);
143
144 return m;
145 }
146
147
148
149
150
151 public KualiDecimal getTotalAmount() {
152 return totalAmount;
153 }
154
155
156
157
158
159 public void setTotalAmount(KualiDecimal totalAmount) {
160 this.totalAmount = totalAmount;
161 }
162
163
164
165
166
167 public KualiInteger getTotalCount() {
168 return totalCount;
169 }
170
171
172
173
174
175 public void setTotalCount(KualiInteger totalCount) {
176 this.totalCount = totalCount;
177 }
178
179
180
181
182
183
184
185 public ProcessSummary getProcessSummary(int index) {
186 if (index >= processSummaryList.size()) {
187 for (int i = processSummaryList.size(); i <= index; i++) {
188 processSummaryList.add(new ProcessSummary());
189 }
190 }
191 return (ProcessSummary) processSummaryList.get(index);
192 }
193
194
195
196
197
198
199
200 public void setProcessSummary(int key, ProcessSummary value) {
201 processSummaryList.set(key, value);
202 }
203
204
205
206
207
208 public List<ProcessSummary> getProcessSummaryList() {
209 return processSummaryList;
210 }
211
212
213
214
215
216 public void setProcessSummaryList(List<ProcessSummary> processSummaryList) {
217 this.processSummaryList = processSummaryList;
218 }
219
220
221
222
223
224 public KualiInteger getProcessId() {
225 return processId;
226 }
227
228
229
230
231
232 public void setProcessId(KualiInteger processId) {
233 this.processId = processId;
234 }
235 }