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.kuali.ole.fp.businessobject.DisbursementVoucherPreConferenceDetail;
19  import org.kuali.ole.fp.document.DisbursementVoucherConstants;
20  import org.kuali.ole.fp.document.DisbursementVoucherDocument;
21  import org.kuali.ole.fp.document.service.DisbursementVoucherTaxService;
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.rice.core.api.parameter.ParameterEvaluator;
30  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
31  import org.kuali.rice.core.api.util.type.KualiDecimal;
32  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
33  import org.kuali.rice.kns.service.DictionaryValidationService;
34  import org.kuali.rice.krad.util.GlobalVariables;
35  import org.kuali.rice.krad.util.MessageMap;
36  
37  public class DisbursementVoucherPrePaidTravelValidation extends GenericValidation {
38      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPrePaidTravelValidation.class);
39  
40      private ParameterService parameterService;
41      private AccountingDocument accountingDocumentForValidation;
42  
43      /**
44       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
45       */
46      public boolean validate(AttributedDocumentEvent event) {
47          LOG.debug("validate start");
48          boolean isValid = true;
49          
50          DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
51          DisbursementVoucherPreConferenceDetail preConferenceDetail = document.getDvPreConferenceDetail();
52          
53          if (!isTravelPrepaidPaymentReason(document)) {
54              return true;
55          }
56          
57          MessageMap errors = GlobalVariables.getMessageMap();
58          errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
59          errors.addToErrorPath(OLEPropertyConstants.DV_PRE_CONFERENCE_DETAIL);
60          
61          SpringContext.getBean(DictionaryValidationService.class).validateBusinessObjectsRecursively(preConferenceDetail, 1);
62          if (errors.hasErrors()) {
63              errors.removeFromErrorPath(OLEPropertyConstants.DV_PRE_CONFERENCE_DETAIL);
64              errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
65              return false;
66          }
67  
68          /* check conference end date is not before conference start date */
69          if (preConferenceDetail.getDisbVchrConferenceEndDate().compareTo(preConferenceDetail.getDisbVchrConferenceStartDate()) < 0) {
70              errors.putError(OLEPropertyConstants.DISB_VCHR_CONFERENCE_END_DATE, OLEKeyConstants.ERROR_DV_CONF_END_DATE);
71              isValid = false;
72          }
73  
74          /* total on prepaid travel must equal Check Total */
75          /* if tax has been taken out, need to add back in the tax amount for the check */
76          KualiDecimal paidAmount = document.getDisbVchrCheckTotalAmount();
77          paidAmount = paidAmount.add(SpringContext.getBean(DisbursementVoucherTaxService.class).getNonResidentAlienTaxAmount(document));
78          if (paidAmount.compareTo(preConferenceDetail.getDisbVchrConferenceTotalAmt()) != 0) {
79              errors.putErrorWithoutFullErrorPath(OLEConstants.GENERAL_PREPAID_TAB_ERRORS, OLEKeyConstants.ERROR_DV_PREPAID_CHECK_TOTAL);
80              isValid = false;
81          }
82  
83          errors.removeFromErrorPath(OLEPropertyConstants.DV_PRE_CONFERENCE_DETAIL);
84          errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
85  
86          return isValid;
87      }
88      
89      /**
90       * Returns whether the document's payment reason is for prepaid travel
91       * 
92       * @param disbursementVoucherDocument
93       * @return true if payment reason is for pre-paid travel reason
94       */
95      protected boolean isTravelPrepaidPaymentReason(DisbursementVoucherDocument disbursementVoucherDocument) {
96          ParameterEvaluator travelPrepaidPaymentReasonEvaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.PREPAID_TRAVEL_PAYMENT_REASONS_PARM_NM, disbursementVoucherDocument.getDvPayeeDetail().getDisbVchrPaymentReasonCode());
97          return travelPrepaidPaymentReasonEvaluator.evaluationSucceeds();
98      }
99  
100     /**
101      * Sets the accountingDocumentForValidation attribute value.
102      * 
103      * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
104      */
105     public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
106         this.accountingDocumentForValidation = accountingDocumentForValidation;
107     }
108 
109     /**
110      * Sets the parameterService attribute value.
111      * @param parameterService The parameterService to set.
112      */
113     public void setParameterService(ParameterService parameterService) {
114         this.parameterService = parameterService;
115     }
116 
117     /**
118      * Gets the accountingDocumentForValidation attribute. 
119      * @return Returns the accountingDocumentForValidation.
120      */
121     public AccountingDocument getAccountingDocumentForValidation() {
122         return accountingDocumentForValidation;
123     }
124 }