1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.validation.impl;
17
18 import java.text.MessageFormat;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Set;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.ole.fp.businessobject.DisbursementVoucherNonEmployeeTravel;
25 import org.kuali.ole.fp.businessobject.DisbursementVoucherWireTransfer;
26 import org.kuali.ole.fp.businessobject.options.PaymentReasonValuesFinder;
27 import org.kuali.ole.fp.document.DisbursementVoucherConstants;
28 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.OLEKeyConstants;
31 import org.kuali.ole.sys.OLEPropertyConstants;
32 import org.kuali.ole.sys.businessobject.Bank;
33 import org.kuali.ole.sys.context.SpringContext;
34 import org.kuali.ole.sys.service.BankService;
35 import org.kuali.rice.core.api.config.property.ConfigurationService;
36 import org.kuali.rice.core.api.util.KeyValue;
37 import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
38 import org.kuali.rice.krad.document.Document;
39 import org.kuali.rice.krad.util.ObjectUtils;
40
41
42
43
44 public class DisbursementVoucherDocumentPreRules extends PromptBeforeValidationBase implements DisbursementVoucherConstants {
45
46
47
48
49
50
51
52
53 @Override
54 public boolean doPrompts(Document document) {
55 boolean preRulesOK = true;
56
57 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) document;
58 checkSpecialHandlingIndicator(dvDocument);
59
60 preRulesOK &= checkNonEmployeeTravelTabState(dvDocument);
61
62 preRulesOK &= checkWireTransferTabState(dvDocument);
63
64 preRulesOK &= checkForeignDraftTabState(dvDocument);
65
66 preRulesOK &= checkBankCodeActive(dvDocument);
67
68 return preRulesOK;
69 }
70
71
72
73
74
75
76 protected void checkSpecialHandlingIndicator(DisbursementVoucherDocument dvDocument) {
77 if (StringUtils.isNotBlank(dvDocument.getDvPayeeDetail().getDisbVchrSpecialHandlingPersonName()) && StringUtils.isNotBlank(dvDocument.getDvPayeeDetail().getDisbVchrSpecialHandlingLine1Addr()) && allowTurningOnOfSpecialHandling(dvDocument)) {
78 dvDocument.setDisbVchrSpecialHandlingCode(true);
79 }
80 }
81
82
83
84
85
86
87 protected boolean allowTurningOnOfSpecialHandling(DisbursementVoucherDocument dvDocument) {
88 Set<String> currentNodes = dvDocument.getDocumentHeader().getWorkflowDocument().getCurrentNodeNames();
89 return !(currentNodes.contains(DisbursementVoucherConstants.RouteLevelNames.CAMPUS));
90 }
91
92
93
94
95
96
97
98 protected boolean checkNonEmployeeTravelTabState(DisbursementVoucherDocument dvDocument) {
99 boolean tabStatesOK = true;
100
101 DisbursementVoucherNonEmployeeTravel dvNonEmplTrav = dvDocument.getDvNonEmployeeTravel();
102 if (!hasNonEmployeeTravelValues(dvNonEmplTrav)) {
103 return true;
104 }
105
106 String paymentReasonCode = dvDocument.getDvPayeeDetail().getDisbVchrPaymentReasonCode();
107
108
109 List<String> nonEmpltravelPaymentReasonCodes = new ArrayList<String>();
110
111 if (nonEmpltravelPaymentReasonCodes == null || !nonEmpltravelPaymentReasonCodes.contains(paymentReasonCode) || dvDocument.getDvPayeeDetail().isEmployee()) {
112 String nonEmplTravReasonStr = getValidPaymentReasonsAsString(nonEmpltravelPaymentReasonCodes);
113
114 String paymentReasonName = dvDocument.getDvPayeeDetail().getDisbVchrPaymentReasonName();
115 Object[] args = { "payment reason", "'" + paymentReasonName + "'", "Non-Employee Travel", nonEmplTravReasonStr };
116
117 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.QUESTION_CLEAR_UNNEEDED_TAB);
118 questionText = MessageFormat.format(questionText, args);
119
120 boolean clearTab = super.askOrAnalyzeYesNoQuestion(OLEConstants.DisbursementVoucherDocumentConstants.CLEAR_NON_EMPLOYEE_TAB_QUESTION_ID, questionText);
121 if (clearTab) {
122 DisbursementVoucherNonEmployeeTravel blankDvNonEmplTrav = new DisbursementVoucherNonEmployeeTravel();
123 blankDvNonEmplTrav.setDocumentNumber(dvNonEmplTrav.getDocumentNumber());
124 blankDvNonEmplTrav.setVersionNumber(dvNonEmplTrav.getVersionNumber());
125 dvDocument.setDvNonEmployeeTravel(blankDvNonEmplTrav);
126 }
127 else {
128
129 super.event.setActionForwardName(OLEConstants.MAPPING_BASIC);
130 tabStatesOK = false;
131 }
132 }
133
134 return tabStatesOK;
135 }
136
137
138
139
140
141
142
143 protected boolean hasNonEmployeeTravelValues(DisbursementVoucherNonEmployeeTravel dvNonEmplTrav) {
144 boolean hasValues = false;
145
146
147 hasValues = hasNonEmployeeTravelGeneralValues(dvNonEmplTrav);
148
149
150 if (!hasValues) {
151 hasValues = hasNonEmployeeTravelPerDiemValues(dvNonEmplTrav);
152 }
153
154 if (!hasValues) {
155 hasValues = hasNonEmployeeTravelPersonalVehicleValues(dvNonEmplTrav);
156 }
157
158 if (!hasValues) {
159 hasValues = dvNonEmplTrav.getDvNonEmployeeExpenses().size() > 0;
160 }
161
162 if (!hasValues) {
163 hasValues = dvNonEmplTrav.getDvPrePaidEmployeeExpenses().size() > 0;
164 }
165
166 return hasValues;
167 }
168
169
170
171
172
173
174
175 protected boolean hasNonEmployeeTravelGeneralValues(DisbursementVoucherNonEmployeeTravel dvNonEmplTrav) {
176 return StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrNonEmpTravelerName()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrServicePerformedDesc()) || StringUtils.isNotBlank(dvNonEmplTrav.getDvServicePerformedLocName()) || StringUtils.isNotBlank(dvNonEmplTrav.getDvServiceRegularEmprName()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrTravelFromCityName()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrTravelFromStateCode()) || StringUtils.isNotBlank(dvNonEmplTrav.getDvTravelFromCountryCode()) || ObjectUtils.isNotNull(dvNonEmplTrav.getDvPerdiemStartDttmStamp()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrTravelToCityName()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrTravelToStateCode()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrTravelToCountryCode()) || ObjectUtils.isNotNull(dvNonEmplTrav.getDvPerdiemEndDttmStamp());
177 }
178
179
180
181
182
183
184
185 protected boolean hasNonEmployeeTravelPerDiemValues(DisbursementVoucherNonEmployeeTravel dvNonEmplTrav) {
186 return StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrPerdiemCategoryName()) || ObjectUtils.isNotNull(dvNonEmplTrav.getDisbVchrPerdiemRate()) || ObjectUtils.isNotNull(dvNonEmplTrav.getDisbVchrPerdiemCalculatedAmt()) || ObjectUtils.isNotNull(dvNonEmplTrav.getDisbVchrPerdiemActualAmount()) || StringUtils.isNotBlank(dvNonEmplTrav.getDvPerdiemChangeReasonText());
187 }
188
189
190
191
192
193
194
195 protected boolean hasNonEmployeeTravelPersonalVehicleValues(DisbursementVoucherNonEmployeeTravel dvNonEmplTrav) {
196 return StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrAutoFromCityName()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrAutoFromStateCode()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrAutoToCityName()) || StringUtils.isNotBlank(dvNonEmplTrav.getDisbVchrAutoToStateCode()) || ObjectUtils.isNotNull(dvNonEmplTrav.getDisbVchrMileageCalculatedAmt()) || ObjectUtils.isNotNull(dvNonEmplTrav.getDisbVchrPersonalCarAmount());
197 }
198
199
200
201
202
203
204
205 protected boolean checkForeignDraftTabState(DisbursementVoucherDocument dvDocument) {
206 boolean tabStatesOK = true;
207
208 DisbursementVoucherWireTransfer dvForeignDraft = dvDocument.getDvWireTransfer();
209
210
211 if ((StringUtils.equals(DisbursementVoucherConstants.PAYMENT_METHOD_CHECK, dvDocument.getDisbVchrPaymentMethodCode()) || StringUtils.equals(DisbursementVoucherConstants.PAYMENT_METHOD_WIRE, dvDocument.getDisbVchrPaymentMethodCode())) && hasForeignDraftValues(dvForeignDraft)) {
212 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.QUESTION_CLEAR_UNNEEDED_TAB);
213
214 Object[] args = { "payment method", dvDocument.getDisbVchrPaymentMethodCode(), "Foreign Draft", DisbursementVoucherConstants.PAYMENT_METHOD_DRAFT };
215 questionText = MessageFormat.format(questionText, args);
216
217 boolean clearTab = super.askOrAnalyzeYesNoQuestion(OLEConstants.DisbursementVoucherDocumentConstants.CLEAR_FOREIGN_DRAFT_TAB_QUESTION_ID, questionText);
218 if (clearTab) {
219
220 clearForeignDraftValues(dvForeignDraft);
221 }
222 else {
223
224 super.event.setActionForwardName(OLEConstants.MAPPING_BASIC);
225 tabStatesOK = false;
226 }
227 }
228
229 return tabStatesOK;
230 }
231
232
233
234
235
236
237
238
239 protected boolean hasForeignDraftValues(DisbursementVoucherWireTransfer dvForeignDraft) {
240 boolean hasValues = false;
241
242
243 hasValues |= StringUtils.isNotBlank(dvForeignDraft.getDisbursementVoucherForeignCurrencyTypeCode());
244 hasValues |= StringUtils.isNotBlank(dvForeignDraft.getDisbursementVoucherForeignCurrencyTypeName());
245
246 return hasValues;
247 }
248
249
250
251
252
253
254 protected void clearForeignDraftValues(DisbursementVoucherWireTransfer dvForeignDraft) {
255 dvForeignDraft.setDisbursementVoucherForeignCurrencyTypeCode(null);
256 dvForeignDraft.setDisbursementVoucherForeignCurrencyTypeName(null);
257 }
258
259
260
261
262
263
264
265 protected boolean checkWireTransferTabState(DisbursementVoucherDocument dvDocument) {
266 boolean tabStatesOK = true;
267
268 DisbursementVoucherWireTransfer dvWireTransfer = dvDocument.getDvWireTransfer();
269
270
271 if ((StringUtils.equals(DisbursementVoucherConstants.PAYMENT_METHOD_CHECK, dvDocument.getDisbVchrPaymentMethodCode()) || StringUtils.equals(DisbursementVoucherConstants.PAYMENT_METHOD_DRAFT, dvDocument.getDisbVchrPaymentMethodCode())) && hasWireTransferValues(dvWireTransfer)) {
272 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.QUESTION_CLEAR_UNNEEDED_TAB);
273
274 Object[] args = { "payment method", dvDocument.getDisbVchrPaymentMethodCode(), "Wire Transfer", DisbursementVoucherConstants.PAYMENT_METHOD_WIRE };
275 questionText = MessageFormat.format(questionText, args);
276
277 boolean clearTab = super.askOrAnalyzeYesNoQuestion(OLEConstants.DisbursementVoucherDocumentConstants.CLEAR_WIRE_TRANSFER_TAB_QUESTION_ID, questionText);
278 if (clearTab) {
279
280 clearWireTransferValues(dvWireTransfer);
281 }
282 else {
283
284 super.event.setActionForwardName(OLEConstants.MAPPING_BASIC);
285 tabStatesOK = false;
286 }
287 }
288
289 return tabStatesOK;
290 }
291
292
293
294
295
296
297
298 protected boolean checkBankCodeActive(DisbursementVoucherDocument dvDocument) {
299 boolean continueRules = true;
300
301
302 if (!SpringContext.getBean(BankService.class).isBankSpecificationEnabled()) {
303 return continueRules;
304 }
305
306
307 dvDocument.refreshReferenceObject(OLEPropertyConstants.BANK);
308 Bank bank = dvDocument.getBank();
309
310
311 if (bank != null && !bank.isActive() && bank.getContinuationBank().isActive()) {
312 String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.QUESTION_BANK_INACTIVE);
313 questionText = MessageFormat.format(questionText, dvDocument.getDisbVchrBankCode(), bank.getContinuationBankCode());
314
315 boolean useContinuation = super.askOrAnalyzeYesNoQuestion(OLEConstants.USE_CONTINUATION_BANK_QUESTION, questionText);
316 if (useContinuation) {
317 dvDocument.setDisbVchrBankCode(bank.getContinuationBankCode());
318 }
319 }
320
321 return continueRules;
322 }
323
324
325
326
327
328
329
330 protected boolean hasWireTransferValues(DisbursementVoucherWireTransfer dvWireTransfer) {
331 boolean hasValues = false;
332
333
334 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbursementVoucherAutomatedClearingHouseProfileNumber());
335 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbursementVoucherBankName());
336 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbVchrBankRoutingNumber());
337 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbVchrBankCityName());
338 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbVchrBankStateCode());
339 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbVchrBankCountryCode());
340 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbVchrPayeeAccountNumber());
341 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbVchrAttentionLineText());
342 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbVchrCurrencyTypeName());
343 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbVchrAdditionalWireText());
344 hasValues |= StringUtils.isNotBlank(dvWireTransfer.getDisbursementVoucherPayeeAccountName());
345
346 return hasValues;
347 }
348
349
350
351
352
353
354 protected void clearWireTransferValues(DisbursementVoucherWireTransfer dvWireTransfer) {
355 dvWireTransfer.setDisbursementVoucherAutomatedClearingHouseProfileNumber(null);
356 dvWireTransfer.setDisbursementVoucherBankName(null);
357 dvWireTransfer.setDisbVchrBankRoutingNumber(null);
358 dvWireTransfer.setDisbVchrBankCityName(null);
359 dvWireTransfer.setDisbVchrBankStateCode(null);
360 dvWireTransfer.setDisbVchrBankCountryCode(null);
361 dvWireTransfer.setDisbVchrPayeeAccountNumber(null);
362 dvWireTransfer.setDisbVchrAttentionLineText(null);
363 dvWireTransfer.setDisbVchrCurrencyTypeName(null);
364 dvWireTransfer.setDisbVchrAdditionalWireText(null);
365 dvWireTransfer.setDisbursementVoucherPayeeAccountName(null);
366 }
367
368
369
370
371
372
373
374 protected String getValidPaymentReasonsAsString(List<String> validPaymentReasonCodes) {
375 List<String> payementReasonString = new ArrayList<String>();
376
377 if (validPaymentReasonCodes == null || validPaymentReasonCodes.isEmpty()) {
378 return StringUtils.EMPTY;
379 }
380
381 List<KeyValue> reasons = new PaymentReasonValuesFinder().getKeyValues();
382 for (KeyValue reason : reasons) {
383 if (validPaymentReasonCodes.contains(reason.getKey())) {
384 payementReasonString.add(reason.getValue());
385 }
386 }
387
388 return payementReasonString.toString();
389 }
390 }