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.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
19  
20  import org.kuali.ole.fp.document.CashReceiptDocument;
21  import org.kuali.ole.fp.document.CashReceiptFamilyBase;
22  import org.kuali.ole.sys.OLEKeyConstants;
23  import org.kuali.ole.sys.OLEPropertyConstants;
24  import org.kuali.ole.sys.document.validation.GenericValidation;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.rice.core.api.util.type.KualiDecimal;
27  import org.kuali.rice.krad.util.GlobalVariables;
28  
29  /**
30   * Validation for the Cash Receipt family of documents that checks the total amount of the document.
31   */
32  public class CashReceiptFamilyDocumentTotalValidation extends GenericValidation {
33      private CashReceiptFamilyBase cashReceiptFamilyDocumentForValidation;
34  
35      /**
36       * For Cash Receipt documents, the document is balanced if the sum total of checks and cash and coin equals the sum total of the
37       * accounting lines. In addition, the sum total of checks and cash and coin must be greater than zero.
38       * 
39       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
40       */
41      public boolean validate(AttributedDocumentEvent event) {
42          // make sure that cash reconciliation total is greater than zero
43          boolean isValid = getCashReceiptFamilyDocumentForValidation().getTotalDollarAmount().compareTo(KualiDecimal.ZERO) > 0;
44          if (!isValid) {
45              GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + OLEPropertyConstants.SUM_TOTAL_AMOUNT, OLEKeyConstants.CashReceipt.ERROR_DOCUMENT_CASH_RECEIPT_NO_CASH_RECONCILIATION_TOTAL);
46          }
47  
48          if (isValid) {
49              // make sure the document is in balance
50              isValid = getCashReceiptFamilyDocumentForValidation().getSourceTotal().compareTo(getCashReceiptFamilyDocumentForValidation().getTotalDollarAmount().subtract( 
51                      ((CashReceiptDocument)getCashReceiptFamilyDocumentForValidation()).getTotalChangeAmount())) == 0;
52  
53              if (!isValid) {
54                  GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + OLEPropertyConstants.SUM_TOTAL_AMOUNT, OLEKeyConstants.CashReceipt.ERROR_DOCUMENT_CASH_RECEIPT_BALANCE);
55              }
56          }
57  
58          return isValid;
59      }
60  
61      /**
62       * Gets the cashReceiptFamilyDocumentForValidation attribute. 
63       * @return Returns the cashReceiptFamilyDocumentForValidation.
64       */
65      public CashReceiptFamilyBase getCashReceiptFamilyDocumentForValidation() {
66          return cashReceiptFamilyDocumentForValidation;
67      }
68  
69      /**
70       * Sets the cashReceiptFamilyDocumentForValidation attribute value.
71       * @param cashReceiptFamilyDocumentForValidation The cashReceiptFamilyDocumentForValidation to set.
72       */
73      public void setCashReceiptFamilyDocumentForValidation(CashReceiptFamilyBase cashReceiptFamilyDocumentForValidation) {
74          this.cashReceiptFamilyDocumentForValidation = cashReceiptFamilyDocumentForValidation;
75      }
76  }