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.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  
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          
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          
75          
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  
91  
92  
93  
94  
95      protected boolean isTravelPrepaidPaymentReason(DisbursementVoucherDocument disbursementVoucherDocument) {
96          ParameterEvaluator travelPrepaidPaymentReasonEvaluator = 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 
102 
103 
104 
105     public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
106         this.accountingDocumentForValidation = accountingDocumentForValidation;
107     }
108 
109     
110 
111 
112 
113     public void setParameterService(ParameterService parameterService) {
114         this.parameterService = parameterService;
115     }
116 
117     
118 
119 
120 
121     public AccountingDocument getAccountingDocumentForValidation() {
122         return accountingDocumentForValidation;
123     }
124 }