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.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.fp.document.DisbursementVoucherConstants;
22 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
23 import org.kuali.ole.fp.document.service.DisbursementVoucherTaxService;
24 import org.kuali.ole.sys.OLEKeyConstants;
25 import org.kuali.ole.sys.OLEPropertyConstants;
26 import org.kuali.ole.sys.businessobject.AccountingLine;
27 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.ole.sys.document.AccountingDocument;
30 import org.kuali.ole.sys.document.validation.GenericValidation;
31 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
32 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
33 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
34 import org.kuali.rice.krad.util.GlobalVariables;
35 import org.kuali.rice.krad.util.MessageMap;
36 import org.kuali.rice.krad.util.ObjectUtils;
37
38 public class DisbursementVoucherAccountingLineValidation extends GenericValidation {
39 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherAccountingLineValidation.class);
40
41 private ParameterService parameterService;
42
43 private AccountingDocument accountingDocumentForValidation;
44 private AccountingLine accountingLineForValidation;
45
46
47 protected static final String DV_PAYEE_ID_NUMBER_PROPERTY_PATH = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER;
48
49
50
51
52 @Override
53 public boolean validate(AttributedDocumentEvent event) {
54 LOG.debug("validate start");
55
56 boolean valid = true;
57 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) accountingDocumentForValidation;
58 MessageMap errors = GlobalVariables.getMessageMap();
59
60
61 if (dvDocument.getDvNonResidentAlienTax() != null) {
62 String lineText = dvDocument.getDvNonResidentAlienTax().getFinancialDocumentAccountingLineText();
63 List<Integer> taxLineNumbers = SpringContext.getBean(DisbursementVoucherTaxService.class).getNRATaxLineNumbers(lineText);
64
65 if (taxLineNumbers.contains(accountingLineForValidation.getSequenceNumber())) {
66 return true;
67 }
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 if (StringUtils.isBlank(dvDocument.getDvPayeeDetail().getDisbVchrPayeeIdNumber())) {
84 if (!errors.containsMessageKey(OLEKeyConstants.ERROR_DV_ADD_LINE_MISSING_PAYEE)) {
85 errors.putErrorWithoutFullErrorPath(OLEPropertyConstants.DOCUMENT + "." + DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_ADD_LINE_MISSING_PAYEE);
86 }
87 valid = false;
88 }
89
90 if (valid) {
91 valid = valid & validateAccountNumber(accountingDocumentForValidation, accountingLineForValidation);
92 valid = valid & validateObjectCode(accountingDocumentForValidation, accountingLineForValidation);
93 }
94
95 return valid;
96 }
97
98
99
100
101
102
103
104
105 public boolean validateObjectCode(AccountingDocument financialDocument, AccountingLine accountingLine) {
106 LOG.debug("beginning object code validation ");
107
108 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) financialDocument;
109 MessageMap errors = GlobalVariables.getMessageMap();
110
111 boolean objectCodeAllowed = true;
112
113
114 if (ObjectUtils.isNull(accountingLineForValidation.getAccount()) || ObjectUtils.isNull(accountingLine.getObjectCode())) {
115 return false;
116 }
117
118
119 if (!accountingLine.getObjectCode().isFinancialObjectActiveCode()) {
120 errors.putError(OLEPropertyConstants.FINANCIAL_OBJECT_CODE, OLEKeyConstants.ERROR_INACTIVE, "Object Code");
121 objectCodeAllowed = false;
122 }
123
124 String documentPaymentReason = dvDocument.getDvPayeeDetail().getDisbVchrPaymentReasonCode();
125 if (StringUtils.isBlank(documentPaymentReason)) {
126 return objectCodeAllowed;
127 }
128
129
130 objectCodeAllowed = objectCodeAllowed && SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_OBJ_LEVEL_BY_PAYMENT_REASON_PARM, DisbursementVoucherConstants.INVALID_OBJ_LEVEL_BY_PAYMENT_REASON_PARM, documentPaymentReason, accountingLine.getObjectCode().getFinancialObjectLevelCode()).evaluateAndAddError(SourceAccountingLine.class, "objectCode.financialObjectLevelCode", OLEPropertyConstants.FINANCIAL_OBJECT_CODE);
131
132
133 objectCodeAllowed = objectCodeAllowed && SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_OBJ_CODE_BY_PAYMENT_REASON_PARM, DisbursementVoucherConstants.INVALID_OBJ_CODE_BY_PAYMENT_REASON_PARM, documentPaymentReason, accountingLine.getFinancialObjectCode()).evaluateAndAddError(SourceAccountingLine.class, OLEPropertyConstants.FINANCIAL_OBJECT_CODE);
134
135 objectCodeAllowed = objectCodeAllowed && SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_OBJECT_SUB_TYPES_BY_SUB_FUND_GROUP_PARM, DisbursementVoucherConstants.INVALID_OBJECT_SUB_TYPES_BY_SUB_FUND_GROUP_PARM, accountingLine.getAccount().getSubFundGroupCode(), accountingLine.getObjectCode().getFinancialObjectSubTypeCode()).evaluateAndAddError(SourceAccountingLine.class, "objectCode.financialObjectSubTypeCode", OLEPropertyConstants.FINANCIAL_OBJECT_CODE);
136
137 return objectCodeAllowed;
138 }
139
140
141
142
143
144
145
146
147
148 public boolean validateAccountNumber(AccountingDocument financialDocument, AccountingLine accountingLine) {
149 LOG.debug("beginning account number validation ");
150
151 DisbursementVoucherDocument dvDocument = (DisbursementVoucherDocument) financialDocument;
152 MessageMap errors = GlobalVariables.getMessageMap();
153
154 String errorKey = OLEPropertyConstants.ACCOUNT_NUMBER;
155 boolean accountNumberAllowed = true;
156
157
158 if (ObjectUtils.isNull(accountingLine.getAccount()) || ObjectUtils.isNull(accountingLine.getObjectCode())) {
159 return false;
160 }
161
162
163
164
165
166
167
168
169 String documentPaymentReason = dvDocument.getDvPayeeDetail().getDisbVchrPaymentReasonCode();
170 if (StringUtils.isBlank(documentPaymentReason)) {
171 return accountNumberAllowed;
172 }
173
174
175 accountNumberAllowed = accountNumberAllowed && SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_SUB_FUND_GROUPS_BY_PAYMENT_REASON_PARM, DisbursementVoucherConstants.INVALID_SUB_FUND_GROUPS_BY_PAYMENT_REASON_PARM, documentPaymentReason, accountingLine.getAccount().getSubFundGroupCode()).evaluateAndAddError(SourceAccountingLine.class, "account.subFundGroupCode", OLEPropertyConstants.ACCOUNT_NUMBER);
176
177 return accountNumberAllowed;
178 }
179
180
181
182
183
184
185 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
186 this.accountingDocumentForValidation = accountingDocumentForValidation;
187 }
188
189
190
191
192
193
194 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
195 this.accountingLineForValidation = accountingLineForValidation;
196 }
197
198
199
200
201
202 public void setParameterService(ParameterService parameterService) {
203 this.parameterService = parameterService;
204 }
205
206
207
208
209
210 public AccountingDocument getAccountingDocumentForValidation() {
211 return accountingDocumentForValidation;
212 }
213
214
215
216
217
218 public AccountingLine getAccountingLineForValidation() {
219 return accountingLineForValidation;
220 }
221
222 }