View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
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          /* check payment reason is allowed for payee type */
71  //        ParameterEvaluator paymentReasonsByTypeEvaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_PAYEE_TYPES_BY_PAYMENT_REASON_PARM, DisbursementVoucherConstants.INVALID_PAYEE_TYPES_BY_PAYMENT_REASON_PARM, paymentReasonCode, dvPayeeDetail.getDisbursementVoucherPayeeTypeCode());
72  //        paymentReasonsByTypeEvaluator.evaluateAndAddError(document.getClass(), DV_PAYMENT_REASON_PROPERTY_PATH);
73  
74        //Commented for the jira issue OLE-3415
75          // restrictions on payment reason when alien indicator is checked
76          /*if (dvPayeeDetail.isDisbVchrAlienPaymentCode()) {
77              ParameterEvaluator alienPaymentReasonsEvaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, ALIEN_PAYMENT_REASONS_PARM_NM, paymentReasonCode);
78              alienPaymentReasonsEvaluator.evaluateAndAddError(document.getClass(), DV_PAYMENT_REASON_PROPERTY_PATH);
79          }*/
80  
81          /* for vendors with a payee type of revolving fund, the payment reason must be a revolving fund payment reason */
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 = /*REFACTORME*/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          // if payment reason is moving, payee must be an employee or have vendor ownership type I (individual)
99        //Commented for the jira issue OLE-3415
100         //boolean isMovingPaymentReason = disbursementVoucherPaymentReasonService.isMovingPaymentReason(paymentReasonCode);
101         //if (isMovingPaymentReason) {
102             // only need to review this rule if the payee is a vendor; NOTE that a vendor can be an employee also
103             if (isVendor && !isEmployee) {
104                 boolean isPayeeIndividualVendor = disbursementVoucherPayeeService.isPayeeIndividualVendor(dvPayeeDetail);
105 
106                 // only vendors who are individuals can be paid moving expenses
107                 /*if (!isPayeeIndividualVendor) {
108                     errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_MOVING_PAYMENT_PAYEE);
109                     isValid = false;
110                 }*/
111             }
112         //}
113 
114         // for research payments over a certain limit the payee must be a vendor
115           //Commented for the jira issue OLE-3415
116 //        boolean isResearchPaymentReason = disbursementVoucherPaymentReasonService.isResearchPaymentReason(paymentReasonCode);
117 //        if (isResearchPaymentReason) {
118             String researchPayLimit = disbursementVoucherPaymentReasonService.getReserchNonVendorPayLimit();
119 
120             if (StringUtils.isNotBlank(researchPayLimit)) {
121                 KualiDecimal payLimit = new KualiDecimal(researchPayLimit);
122 
123               /*  if (!isVendor && document.getDisbVchrCheckTotalAmount().isGreaterEqual(payLimit)) {
124                     errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_RESEARCH_PAYMENT_PAYEE, researchPayLimit);
125                     isValid = false;
126                 }*/
127            // }
128         }
129 
130         errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
131 
132         isValid = initialErrorCount == errors.getErrorCount();
133         return isValid;
134     }
135 
136     /**
137      * Retrieves the VendorDetail object from the vendor id number.
138      *
139      * @param vendorIdNumber vendor ID number
140      * @param vendorDetailIdNumber vendor detail ID number
141      * @return <code>VendorDetail</code>
142      */
143     protected VendorDetail retrieveVendorDetail(Integer vendorIdNumber, Integer vendorDetailIdNumber) {
144         return SpringContext.getBean(VendorService.class).getVendorDetail(vendorIdNumber, vendorDetailIdNumber);
145     }
146 
147     /**
148      * Gets the parameterService attribute.
149      * @return Returns the parameterService.
150      */
151     public ParameterService getParameterService() {
152         return parameterService;
153     }
154 
155     /**
156      * Gets the disbursementVoucherPaymentReasonService attribute.
157      * @return Returns the disbursementVoucherPaymentReasonService.
158      */
159     public DisbursementVoucherPaymentReasonService getDisbursementVoucherPaymentReasonService() {
160         return disbursementVoucherPaymentReasonService;
161     }
162 
163     /**
164      * Gets the disbursementVoucherPayeeService attribute.
165      * @return Returns the disbursementVoucherPayeeService.
166      */
167     public DisbursementVoucherPayeeService getDisbursementVoucherPayeeService() {
168         return disbursementVoucherPayeeService;
169     }
170 
171     /**
172      * Sets the accountingDocumentForValidation attribute value.
173      *
174      * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
175      */
176     public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
177         this.accountingDocumentForValidation = accountingDocumentForValidation;
178     }
179 
180     /**
181      * Sets the parameterService attribute value.
182      *
183      * @param parameterService The parameterService to set.
184      */
185     public void setParameterService(ParameterService parameterService) {
186         this.parameterService = parameterService;
187     }
188 
189     /**
190      * Gets the accountingDocumentForValidation attribute.
191      *
192      * @return Returns the accountingDocumentForValidation.
193      */
194     public AccountingDocument getAccountingDocumentForValidation() {
195         return accountingDocumentForValidation;
196     }
197 
198     /**
199      * Sets the disbursementVoucherPaymentReasonService attribute value.
200      *
201      * @param disbursementVoucherPaymentReasonService The disbursementVoucherPaymentReasonService to set.
202      */
203     public void setDisbursementVoucherPaymentReasonService(DisbursementVoucherPaymentReasonService disbursementVoucherPaymentReasonService) {
204         this.disbursementVoucherPaymentReasonService = disbursementVoucherPaymentReasonService;
205     }
206 
207     /**
208      * Sets the disbursementVoucherPayeeService attribute value.
209      *
210      * @param disbursementVoucherPayeeService The disbursementVoucherPayeeService to set.
211      */
212     public void setDisbursementVoucherPayeeService(DisbursementVoucherPayeeService disbursementVoucherPayeeService) {
213         this.disbursementVoucherPayeeService = disbursementVoucherPayeeService;
214     }
215 }