1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.service.impl;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.ole.fp.businessobject.DisbursementPayee;
26 import org.kuali.ole.fp.businessobject.PaymentReasonCode;
27 import org.kuali.ole.fp.document.DisbursementVoucherConstants;
28 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
29 import org.kuali.ole.fp.document.service.DisbursementVoucherPayeeService;
30 import org.kuali.ole.fp.document.service.DisbursementVoucherPaymentReasonService;
31 import org.kuali.ole.sys.OLEConstants;
32 import org.kuali.ole.sys.OLEKeyConstants;
33 import org.kuali.ole.sys.OLEPropertyConstants;
34 import org.kuali.ole.sys.context.SpringContext;
35 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
36 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
37 import org.kuali.rice.kns.util.MessageList;
38 import org.kuali.rice.krad.service.BusinessObjectService;
39
40
41
42
43
44
45 public class DisbursementVoucherPaymentReasonServiceImpl implements DisbursementVoucherPaymentReasonService {
46 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPaymentReasonServiceImpl.class);
47
48 protected ParameterService parameterService;
49 protected BusinessObjectService businessObjectService;
50 protected DisbursementVoucherPayeeService disbursementVoucherPayeeService;
51
52
53
54
55
56 public boolean isPayeeQualifiedForPayment(DisbursementPayee payee, String paymentReasonCode) {
57 Collection<String> payeeTypeCodes = this.getPayeeTypesByPaymentReason(paymentReasonCode);
58 return this.isPayeeQualifiedForPayment(payee, paymentReasonCode, payeeTypeCodes);
59 }
60
61
62
63
64
65 public boolean isPayeeQualifiedForPayment(DisbursementPayee payee, String paymentReasonCode, Collection<String> payeeTypeCodes) {
66 if (payeeTypeCodes == null || payeeTypeCodes.isEmpty()) {
67 return false;
68 }
69
70 String payeeTypeCode = payee.getPayeeTypeCode();
71 if (!payeeTypeCodes.contains(payeeTypeCode)) {
72 return false;
73 }
74
75 if (disbursementVoucherPayeeService.isVendor(payee)) {
76 Collection<String> vendorOwnershipTypeCodes = this.getVendorOwnershipTypesByPaymentReason(paymentReasonCode);
77
78 if (vendorOwnershipTypeCodes != null && !vendorOwnershipTypeCodes.isEmpty()) {
79 String vendorOwnershipTypeCodeOfPayee = disbursementVoucherPayeeService.getVendorOwnershipTypeCode(payee);
80 return vendorOwnershipTypeCodes.contains(vendorOwnershipTypeCodeOfPayee);
81 }
82 }
83
84
85
86
87
88
89
90
91
92
93 return true;
94 }
95
96
97
98
99 public boolean isMovingPaymentReason(String paymentReasonCode) {
100 String typeParameterName = DisbursementVoucherConstants.MOVING_PAYMENT_REASONS_PARM_NM;
101 return this.isPaymentReasonOfType(typeParameterName, paymentReasonCode);
102 }
103
104
105
106
107 public boolean isPrepaidTravelPaymentReason(String paymentReasonCode) {
108 String typeParameterName = DisbursementVoucherConstants.PREPAID_TRAVEL_PAYMENT_REASONS_PARM_NM;
109 return this.isPaymentReasonOfType(typeParameterName, paymentReasonCode);
110 }
111
112
113
114
115 public boolean isNonEmployeeTravelPaymentReason(String paymentReasonCode) {
116 String typeParameterName = DisbursementVoucherConstants.NONEMPLOYEE_TRAVEL_PAY_REASONS_PARM_NM;
117 return this.isPaymentReasonOfType(typeParameterName, paymentReasonCode);
118 }
119
120
121
122
123 public boolean isResearchPaymentReason(String paymentReasonCode) {
124 String typeParameterName = DisbursementVoucherConstants.RESEARCH_PAYMENT_REASONS_PARM_NM;
125 return this.isPaymentReasonOfType(typeParameterName, paymentReasonCode);
126 }
127
128
129
130
131 public boolean isRevolvingFundPaymentReason(String paymentReasonCode) {
132 String typeParameterName = DisbursementVoucherConstants.REVOLVING_FUND_PAYMENT_REASONS_PARM_NM;
133 return this.isPaymentReasonOfType(typeParameterName, paymentReasonCode);
134 }
135
136
137
138
139 public boolean isDecedentCompensationPaymentReason(String paymentReasonCode) {
140 String typeParameterName = DisbursementVoucherConstants.DECEDENT_COMPENSATION_PAYMENT_REASONS_PARM_NM;
141 return this.isPaymentReasonOfType(typeParameterName, paymentReasonCode);
142 }
143
144
145
146
147
148 public boolean isPaymentReasonOfType(String typeParameterName, String paymentReasonCode) {
149 return SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, typeParameterName, paymentReasonCode).evaluationSucceeds();
150 }
151
152
153
154
155 public String getReserchNonVendorPayLimit() {
156 return parameterService.getParameterValueAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.RESEARCH_NON_VENDOR_PAY_LIMIT_AMOUNT_PARM_NM);
157 }
158
159
160
161
162 public Collection<String> getPayeeTypesByPaymentReason(String paymentReasonCode) {
163 return parameterService.getSubParameterValuesAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_PAYEE_TYPES_BY_PAYMENT_REASON_PARM, paymentReasonCode);
164 }
165
166
167
168
169 public Collection<String> getVendorOwnershipTypesByPaymentReason(String paymentReasonCode) {
170 return parameterService.getSubParameterValuesAsString(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_VENDOR_OWNERSHIP_TYPES_BY_PAYMENT_REASON, paymentReasonCode);
171 }
172
173
174
175
176 public PaymentReasonCode getPaymentReasonByPrimaryId(String paymentReasonCode) {
177 Map<String, Object> primaryKeys = new HashMap<String, Object>();
178 primaryKeys.put(OLEPropertyConstants.CODE, paymentReasonCode);
179
180 return (PaymentReasonCode) businessObjectService.findByPrimaryKey(PaymentReasonCode.class, primaryKeys);
181 }
182
183
184
185
186 public boolean isTaxReviewRequired(String paymentReasonCode) {
187 String parameterName = DisbursementVoucherConstants.PAYMENT_REASONS_REQUIRING_TAX_REVIEW_PARM_NM;
188 List<String> values = new ArrayList<String>( parameterService.getParameterValuesAsString(DisbursementVoucherDocument.class, parameterName) );
189
190 return values != null && values.contains(paymentReasonCode);
191 }
192
193
194
195
196
197 public void postPaymentReasonCodeUsage(String paymentReasonCode, MessageList messageList) {
198 Collection<String> payeeTypeCodes = this.getPayeeTypesByPaymentReason(paymentReasonCode);
199 if (payeeTypeCodes == null || payeeTypeCodes.isEmpty()) {
200 return;
201 }
202
203 String descriptivePayeeTypes = this.getDescriptivePayeeTypesAsString(payeeTypeCodes);
204 String descriptivePaymentReason = this.getPaymentReasonByPrimaryId(paymentReasonCode).getCodeAndDescription();
205 if (payeeTypeCodes.size() > 1) {
206 String messageKey = OLEKeyConstants.WARNING_DV_PAYMENT_REASON_VALID_FOR_MULTIPLE_PAYEE_TYPES;
207 messageList.add(messageKey, descriptivePaymentReason, descriptivePayeeTypes);
208 }
209 else if (payeeTypeCodes.size() == 1) {
210 String messageKey = OLEKeyConstants.WARNING_DV_PAYMENT_REASON_VALID_FOR_SINGEL_PAYEE_TYPE;
211 messageList.add(messageKey, descriptivePaymentReason, descriptivePayeeTypes);
212 }
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238 }
239
240
241 protected String getDescriptivePayeeTypesAsString(Collection<String> payeeTypeCodes) {
242 List<String> payeeTypeDescriptions = new ArrayList<String>();
243
244 for (String payeeTypeCode : payeeTypeCodes) {
245 String description = SpringContext.getBean(DisbursementVoucherPayeeService.class).getPayeeTypeDescription(payeeTypeCode);
246 payeeTypeDescriptions.add(description);
247 }
248
249 return this.convertListToString(payeeTypeDescriptions);
250 }
251
252 protected String convertListToString(List<String> list) {
253 if (list == null || list.isEmpty()) {
254 return StringUtils.EMPTY;
255 }
256
257 String oneSpace = " ";
258 StringBuilder listAsString = new StringBuilder();
259 for (int index = 0; index < list.size(); index++) {
260 String emlement = list.get(index);
261
262 if (index == 0) {
263 listAsString.append(emlement);
264 }
265 else if (index < list.size() - 1) {
266 listAsString.append(OLEConstants.COMMA).append(oneSpace).append(emlement);
267 }
268 else if (index == list.size() - 1) {
269 listAsString.append(oneSpace).append(OLEConstants.AND).append(oneSpace).append(emlement);
270 }
271 }
272
273 return listAsString.toString();
274 }
275
276
277
278
279
280
281 public void setParameterService(ParameterService parameterService) {
282 this.parameterService = parameterService;
283 }
284
285
286
287
288
289
290 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
291 this.businessObjectService = businessObjectService;
292 }
293
294
295
296
297
298
299 public void setDisbursementVoucherPayeeService(DisbursementVoucherPayeeService disbursementVoucherPayeeService) {
300 this.disbursementVoucherPayeeService = disbursementVoucherPayeeService;
301 }
302 }