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_PC_TRANSACTION_TOTAL_ACCTING_LINE_TOTAL_NOT_EQUAL;
20  
21  import java.util.List;
22  
23  import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
24  import org.kuali.ole.fp.businessobject.ProcurementCardTransactionDetail;
25  import org.kuali.ole.sys.businessobject.AccountingLine;
26  import org.kuali.ole.sys.businessobject.TargetAccountingLine;
27  import org.kuali.ole.sys.document.AccountingDocument;
28  import org.kuali.ole.sys.document.validation.GenericValidation;
29  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
30  import org.kuali.rice.core.api.util.type.KualiDecimal;
31  import org.kuali.rice.krad.util.GlobalVariables;
32  
33  /**
34   * Validates that an accounting line does not have a capital object object code 
35   */
36  public class ProcurementCardFixErrorPathValidation extends GenericValidation {
37      private AccountingLine accountingLineForValidation;
38      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardFixErrorPathValidation.class);
39  
40      /**
41       * Validates that an accounting line does not have a capital object object code
42       * <strong>Expects an accounting line as the first a parameter</strong>
43       * @see org.kuali.ole.sys.document.validation.Validation#validate(java.lang.Object[])
44       */
45      public boolean validate(AttributedDocumentEvent event) {
46         ProcurementCardErrorPathUtil.fixErrorPath((AccountingDocument)event.getDocument(), accountingLineForValidation);
47          return true;
48      }
49  
50      /**
51       * This method validates the balance of the transaction given.  A procurement card transaction is in balance if 
52       * the total amount of the transaction equals the total of the target accounting lines corresponding to the transaction.
53       * 
54       * @param pcTransaction The transaction detail used to retrieve the procurement card transaction and target accounting 
55       *                      lines used to check for in balance.
56       * @return True if the amounts are equal and the transaction is in balance, false otherwise.
57       */
58      protected boolean isTransactionBalanceValid(ProcurementCardTransactionDetail pcTransactionDetail) {
59          boolean inBalance = true;
60          KualiDecimal transAmount = pcTransactionDetail.getTransactionTotalAmount();
61          List<ProcurementCardTargetAccountingLine> targetAcctingLines = pcTransactionDetail.getTargetAccountingLines();
62  
63          KualiDecimal targetLineTotal = KualiDecimal.ZERO;
64  
65          for (TargetAccountingLine targetLine : targetAcctingLines) {
66              targetLineTotal = targetLineTotal.add(targetLine.getAmount());
67          }
68  
69          // perform absolute value check because current system has situations where amounts may be opposite in sign
70          // This will no longer be necessary following completion of KULFDBCK-1290
71          inBalance = transAmount.abs().equals(targetLineTotal.abs());
72  
73          if (!inBalance) {
74              GlobalVariables.getMessageMap().putError(ACCOUNTING_LINE_ERRORS, ERROR_DOCUMENT_PC_TRANSACTION_TOTAL_ACCTING_LINE_TOTAL_NOT_EQUAL, new String[] { transAmount.toString(), targetLineTotal.toString() });
75          }
76  
77          return inBalance;
78      }
79  
80      /**
81       * Gets the accountingLineForValidation attribute. 
82       * @return Returns the accountingLineForValidation.
83       */
84      public AccountingLine getAccountingLineForValidation() {
85          return accountingLineForValidation;
86      }
87  
88      /**
89       * Sets the accountingLineForValidation attribute value.
90       * @param accountingLineForValidation The accountingLineForValidation to set.
91       */
92      public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
93          this.accountingLineForValidation = accountingLineForValidation;
94      }
95  
96     
97  }