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 org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.fp.businessobject.DisbursementVoucherPayeeDetail;
20 import org.kuali.ole.fp.document.DisbursementVoucherConstants;
21 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
22 import org.kuali.ole.fp.document.service.DisbursementVoucherPayeeService;
23 import org.kuali.ole.fp.document.service.DisbursementVoucherPaymentReasonService;
24 import org.kuali.ole.sys.OLEKeyConstants;
25 import org.kuali.ole.sys.OLEPropertyConstants;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.document.AccountingDocument;
28 import org.kuali.ole.sys.document.validation.GenericValidation;
29 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
30 import org.kuali.ole.vnd.businessobject.VendorDetail;
31 import org.kuali.ole.vnd.document.service.VendorService;
32 import org.kuali.rice.core.api.parameter.ParameterEvaluator;
33 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
34 import org.kuali.rice.core.api.util.type.KualiDecimal;
35 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
36 import org.kuali.rice.krad.util.GlobalVariables;
37 import org.kuali.rice.krad.util.MessageMap;
38
39 public class DisbursementVoucherPaymentReasonValidation extends GenericValidation implements DisbursementVoucherConstants {
40 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPaymentReasonValidation.class);
41
42 private ParameterService parameterService;
43 private AccountingDocument accountingDocumentForValidation;
44 private DisbursementVoucherPaymentReasonService disbursementVoucherPaymentReasonService;
45 private DisbursementVoucherPayeeService disbursementVoucherPayeeService;
46
47 public static final String DV_PAYMENT_REASON_PROPERTY_PATH = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYMENT_REASON_CODE;
48 public static final String DV_PAYEE_ID_NUMBER_PROPERTY_PATH = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER;
49
50
51
52
53 @Override
54 public boolean validate(AttributedDocumentEvent event) {
55 LOG.debug("validate start");
56
57 boolean isValid = true;
58
59 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
60 DisbursementVoucherPayeeDetail dvPayeeDetail = document.getDvPayeeDetail();
61 String paymentReasonCode = dvPayeeDetail.getDisbVchrPaymentReasonCode();
62
63 boolean isVendor = dvPayeeDetail.isVendor();
64 boolean isEmployee = dvPayeeDetail.isEmployee();
65
66 MessageMap errors = GlobalVariables.getMessageMap();
67 int initialErrorCount = errors.getErrorCount();
68 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
69
70
71
72
73
74
75
76
77
78
79
80
81
82 final boolean isRevolvingFundPaymentReason = disbursementVoucherPaymentReasonService.isRevolvingFundPaymentReason(paymentReasonCode);
83 if (isVendor) {
84 final boolean isRevolvingFundCodeVendor = SpringContext.getBean(VendorService.class).isRevolvingFundCodeVendor(dvPayeeDetail.getDisbVchrVendorHeaderIdNumberAsInteger());
85 if (isRevolvingFundCodeVendor) {
86 ParameterEvaluator revolvingFundPaymentReasonCodeEvaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, REVOLVING_FUND_PAYMENT_REASONS_PARM_NM, paymentReasonCode);
87 revolvingFundPaymentReasonCodeEvaluator.evaluateAndAddError(document.getClass(), DV_PAYMENT_REASON_PROPERTY_PATH);
88 } else if (isRevolvingFundPaymentReason) {
89 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_REVOLVING_PAYMENT_REASON, paymentReasonCode);
90 isValid = false;
91 }
92 }
93 if (!isVendor && isRevolvingFundPaymentReason) {
94 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_REVOLVING_PAYMENT_REASON, paymentReasonCode);
95 isValid = false;
96 }
97
98
99
100
101
102
103 if (isVendor && !isEmployee) {
104 boolean isPayeeIndividualVendor = disbursementVoucherPayeeService.isPayeeIndividualVendor(dvPayeeDetail);
105
106
107
108
109
110
111 }
112
113
114
115
116
117
118 String researchPayLimit = disbursementVoucherPaymentReasonService.getReserchNonVendorPayLimit();
119
120 if (StringUtils.isNotBlank(researchPayLimit)) {
121 KualiDecimal payLimit = new KualiDecimal(researchPayLimit);
122
123
124
125
126
127
128 }
129
130 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
131
132 isValid = initialErrorCount == errors.getErrorCount();
133 return isValid;
134 }
135
136
137
138
139
140
141
142
143 protected VendorDetail retrieveVendorDetail(Integer vendorIdNumber, Integer vendorDetailIdNumber) {
144 return SpringContext.getBean(VendorService.class).getVendorDetail(vendorIdNumber, vendorDetailIdNumber);
145 }
146
147
148
149
150
151 public ParameterService getParameterService() {
152 return parameterService;
153 }
154
155
156
157
158
159 public DisbursementVoucherPaymentReasonService getDisbursementVoucherPaymentReasonService() {
160 return disbursementVoucherPaymentReasonService;
161 }
162
163
164
165
166
167 public DisbursementVoucherPayeeService getDisbursementVoucherPayeeService() {
168 return disbursementVoucherPayeeService;
169 }
170
171
172
173
174
175
176 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
177 this.accountingDocumentForValidation = accountingDocumentForValidation;
178 }
179
180
181
182
183
184
185 public void setParameterService(ParameterService parameterService) {
186 this.parameterService = parameterService;
187 }
188
189
190
191
192
193
194 public AccountingDocument getAccountingDocumentForValidation() {
195 return accountingDocumentForValidation;
196 }
197
198
199
200
201
202
203 public void setDisbursementVoucherPaymentReasonService(DisbursementVoucherPaymentReasonService disbursementVoucherPaymentReasonService) {
204 this.disbursementVoucherPaymentReasonService = disbursementVoucherPaymentReasonService;
205 }
206
207
208
209
210
211
212 public void setDisbursementVoucherPayeeService(DisbursementVoucherPayeeService disbursementVoucherPayeeService) {
213 this.disbursementVoucherPayeeService = disbursementVoucherPayeeService;
214 }
215 }