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.sys.OLEConstants;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.ole.sys.OLEPropertyConstants;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.ole.sys.document.AccountingDocument;
27  import org.kuali.ole.sys.document.validation.GenericValidation;
28  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
29  import org.kuali.ole.vnd.businessobject.VendorDetail;
30  import org.kuali.ole.vnd.document.service.VendorService;
31  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
32  import org.kuali.rice.kim.api.KimConstants.PersonExternalIdentifierTypes;
33  import org.kuali.rice.kim.api.identity.Person;
34  import org.kuali.rice.kim.api.identity.PersonService;
35  import org.kuali.rice.kim.api.identity.entity.Entity;
36  import org.kuali.rice.kim.api.services.IdentityManagementService;
37  import org.kuali.rice.kns.service.DataDictionaryService;
38  import org.kuali.rice.krad.util.GlobalVariables;
39  import org.kuali.rice.krad.util.MessageMap;
40  
41  public class DisbursementVoucherVendorInformationValidation extends GenericValidation implements DisbursementVoucherConstants {
42      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPaymentReasonValidation.class);
43  
44      private ParameterService parameterService;
45      private AccountingDocument accountingDocumentForValidation;
46  
47      public static final String DV_PAYEE_ID_NUMBER_PROPERTY_PATH = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER;
48  
49      /**
50       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
51       */
52      @Override
53      public boolean validate(AttributedDocumentEvent event) {
54          LOG.debug("validate start");
55          boolean isValid = true;
56  
57          DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
58          DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
59  
60          if (!payeeDetail.isVendor()) {
61  
62              String initiator = document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
63              final Entity entity= SpringContext.getBean(IdentityManagementService.class).getEntityByPrincipalId(initiator);
64              String originatorId = entity.getEmploymentInformation().get(0).getEmployeeId();
65              String employeeId = payeeDetail.getDisbVchrEmployeeIdNumber();
66              // verify that originator does not equal payee
67              if (originatorId.equals(employeeId)) {
68                  isValid = false;
69                  MessageMap errors = GlobalVariables.getMessageMap();
70                  errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
71                  String[] errorName = { "Payee ID " + employeeId ," Originator has the same ID ", "name" };
72                  errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_VENDOR_NAME_PERSON_NAME_CONFUSION, errorName);
73              }
74              return isValid;
75          }
76  
77          if (StringUtils.isBlank(payeeDetail.getDisbVchrPayeeIdNumber())) {
78              return false;
79          }
80  
81          VendorDetail vendor = retrieveVendorDetail(payeeDetail.getDisbVchrVendorHeaderIdNumberAsInteger(), payeeDetail.getDisbVchrVendorDetailAssignedIdNumberAsInteger());
82  
83          MessageMap errors = GlobalVariables.getMessageMap();
84          errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
85  
86          /* Retrieve Vendor */
87          if (vendor == null) {
88              errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_EXISTENCE, SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER));
89              errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
90              return false;
91          }
92  
93          /* DV Vendor Detail must be active */
94          if (!vendor.isActiveIndicator()) {
95              errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_INACTIVE, SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER));
96              errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
97              return false;
98          }
99  
100         /* for vendors with tax type ssn, check employee restrictions */
101       //Commented for the jira issue OLE-3415
102         /*
103         if (TAX_TYPE_SSN.equals(vendor.getVendorHeader().getVendorTaxTypeCode())) {
104             if (isActiveEmployeeSSN(vendor.getVendorHeader().getVendorTaxNumber())) {
105             	//Commented for the jira issue OLE-3415
106                 // determine if the rule is flagged off in the param setting
107                 boolean performPrepaidEmployeeInd = parameterService.getIndicatorParameter(DisbursementVoucherDocument.class, PERFORM_PREPAID_EMPL_PARM_NM);
108 
109                 if (performPrepaidEmployeeInd) {
110                     //active vendor employees cannot be paid for prepaid travel
111                     ParameterEvaluator travelPrepaidPaymentReasonCodeEvaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, PREPAID_TRAVEL_PAYMENT_REASONS_PARM_NM, payeeDetail.getDisbVchrPaymentReasonCode());
112                     if (travelPrepaidPaymentReasonCodeEvaluator.evaluationSucceeds()) {
113                         errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_ACTIVE_EMPLOYEE_PREPAID_TRAVEL);
114                         isValid = false;
115                     }
116 
117                 }
118             }
119 
120             else if (isEmployeeSSN(vendor.getVendorHeader().getVendorTaxNumber())) {
121             	//Commented for the jira issue OLE-3415
122                 // check param setting for paid outside payroll check
123             	boolean performPaidOutsidePayrollInd = parameterService.getIndicatorParameter(DisbursementVoucherDocument.class, DisbursementVoucherConstants.CHECK_EMPLOYEE_PAID_OUTSIDE_PAYROLL_PARM_NM);
124 
125                 if (performPaidOutsidePayrollInd) {
126                      //If vendor is type employee, vendor record must be flagged as paid outside of payroll
127                     if (!SpringContext.getBean(VendorService.class).isVendorInstitutionEmployee(vendor.getVendorHeaderGeneratedIdentifier())) {
128                         errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_EMPLOYEE_PAID_OUTSIDE_PAYROLL);
129                         isValid = false;
130                     }
131                 }
132             }
133         }
134         */
135 
136         errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
137 
138         return isValid;
139     }
140 
141     /**
142      * Retrieves the VendorDetail object from the vendor id number.
143      *
144      * @param vendorIdNumber vendor ID number
145      * @param vendorDetailIdNumber vendor detail ID number
146      * @return <code>VendorDetail</code>
147      */
148     protected VendorDetail retrieveVendorDetail(Integer vendorIdNumber, Integer vendorDetailIdNumber) {
149         return SpringContext.getBean(VendorService.class).getVendorDetail(vendorIdNumber, vendorDetailIdNumber);
150     }
151 
152     /**
153      * Retrieves Person from SSN
154      *
155      * @param ssnNumber social security number
156      * @return <code>Person</code>
157      */
158     protected Person retrieveEmployeeBySSN(String ssnNumber) {
159         Person person = SpringContext.getBean(PersonService.class).getPersonByExternalIdentifier(PersonExternalIdentifierTypes.TAX, ssnNumber).get(0);
160         if (person == null) {
161             LOG.error("User Not Found");
162         }
163         return person;
164     }
165 
166     /**
167      * Confirms that the SSN provided is associated with an employee.
168      *
169      * @param ssnNumber social security number
170      * @return true if the ssn number is a valid employee ssn
171      */
172     protected boolean isEmployeeSSN(String ssnNumber) {
173         return retrieveEmployeeBySSN(ssnNumber) != null;
174     }
175 
176     /**
177      * Performs a lookup on universal users for the given ssn number.
178      *
179      * @param ssnNumber social security number
180      * @return true if the ssn number is a valid employee ssn and the employee is active
181      */
182     protected boolean isActiveEmployeeSSN(String ssnNumber) {
183         Person employee = retrieveEmployeeBySSN(ssnNumber);
184         return employee != null && OLEConstants.EMPLOYEE_ACTIVE_STATUS.equals(employee.getEmployeeStatusCode());
185     }
186 
187     /**
188      * Sets the accountingDocumentForValidation attribute value.
189      *
190      * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
191      */
192     public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
193         this.accountingDocumentForValidation = accountingDocumentForValidation;
194     }
195 
196     /**
197      * Sets the parameterService attribute value.
198      * @param parameterService The parameterService to set.
199      */
200     public void setParameterService(ParameterService parameterService) {
201         this.parameterService = parameterService;
202     }
203 
204     /**
205      * Gets the accountingDocumentForValidation attribute.
206      * @return Returns the accountingDocumentForValidation.
207      */
208     public AccountingDocument getAccountingDocumentForValidation() {
209         return accountingDocumentForValidation;
210     }
211 }
212