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 static org.kuali.ole.sys.OLEConstants.ACCOUNTING_LINE_ERRORS;
19  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_BALANCE_CONSIDERING_CREDIT_AND_DEBIT_AMOUNTS;
20  
21  import org.kuali.ole.fp.document.AuxiliaryVoucherDocument;
22  import org.kuali.ole.sys.document.validation.GenericValidation;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.rice.core.api.util.type.KualiDecimal;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  /**
28   * Validation for Auxiliary Voucher, which checks tha tthe accounting lines on the document, with all of
29   * their various credits and debits, balance.
30   */
31  public class AuxiliaryVoucherAccountingLinesBalanceValidation extends GenericValidation {
32      private AuxiliaryVoucherDocument auxiliaryVoucherDocumentForValidation;
33  
34      /**
35       * Returns true if credit/debit entries are in balance
36       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
37       */
38      public boolean validate(AttributedDocumentEvent event) {
39          KualiDecimal creditAmount = getAuxiliaryVoucherDocumentForValidation().getCreditTotal();
40          KualiDecimal debitAmount = getAuxiliaryVoucherDocumentForValidation().getDebitTotal();
41  
42          boolean balanced = debitAmount.equals(creditAmount);
43          if (!balanced) {
44              String errorParams[] = { creditAmount.toString(), debitAmount.toString() };
45              GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DOCUMENT_BALANCE_CONSIDERING_CREDIT_AND_DEBIT_AMOUNTS, errorParams);
46          }
47          return balanced;
48      }
49  
50      /**
51       * Gets the auxiliaryVoucherDocumentForValidation attribute. 
52       * @return Returns the auxiliaryVoucherDocumentForValidation.
53       */
54      public AuxiliaryVoucherDocument getAuxiliaryVoucherDocumentForValidation() {
55          return auxiliaryVoucherDocumentForValidation;
56      }
57  
58      /**
59       * Sets the auxiliaryVoucherDocumentForValidation attribute value.
60       * @param auxiliaryVoucherDocumentForValidation The auxiliaryVoucherDocumentForValidation to set.
61       */
62      public void setAuxiliaryVoucherDocumentForValidation(AuxiliaryVoucherDocument accountingDocumentForValidation) {
63          this.auxiliaryVoucherDocumentForValidation = accountingDocumentForValidation;
64      }
65  }