View Javadoc
1   /*
2    * Copyright 2009 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.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.businessobject.InvoiceItem;
19  import org.kuali.ole.module.purap.document.InvoiceDocument;
20  import org.kuali.ole.sys.document.validation.GenericValidation;
21  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
22  
23  import java.math.BigDecimal;
24  
25  public class InvoiceReviewValidation extends GenericValidation {
26      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(InvoiceReviewValidation.class);
27  
28      private InvoiceItem itemForValidation;
29  
30      public boolean validate(AttributedDocumentEvent event) {
31          boolean valid = true;
32          InvoiceDocument invoice = (InvoiceDocument) event.getDocument();
33  
34  
35          boolean containsAccounts = false;
36          int accountLineNbr = 0;
37  
38          String identifier = itemForValidation.getItemIdentifierString();
39          BigDecimal total = BigDecimal.ZERO;
40          if (LOG.isDebugEnabled()) {
41              LOG.debug("validateInvoiceReview() The " + identifier + " is getting the total percent field set to " + BigDecimal.ZERO);
42          }
43  
44          //if ((itemForValidation.getItemType().isLineItemIndicator() && itemForValidation.getTotalAmount() != null &&
45          //        itemForValidation.getTotalAmount().isNonZero() &&
46          //       ((itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator() && (itemForValidation.getPoOutstandingAmount() == null || itemForValidation.getPoOutstandingAmount().isZero())) || (itemForValidation.getItemType().isQuantityBasedGeneralLedgerIndicator() && (itemForValidation.getPoOutstandingQuantity() == null || itemForValidation.getPoOutstandingQuantity().isZero()))))) {
47  
48  
49          if ((itemForValidation.getItemType().isLineItemIndicator() && itemForValidation.getTotalAmount() != null &&
50                  itemForValidation.getTotalAmount().isNonZero() &&
51                  ((itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator() || (itemForValidation.getItemType().isQuantityBasedGeneralLedgerIndicator()))))) {
52  
53  
54              // ERROR because we have total amount and no open encumberance on the PO item
55              // this error should have been caught at an earlier level
56              if (itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator()) {
57                  String error = "Payment Request " + invoice.getPurapDocumentIdentifier() + ", " + identifier + " has total amount '" + itemForValidation.getTotalAmount() + "' but outstanding encumbered amount " + itemForValidation.getPoOutstandingAmount();
58                  LOG.error("validateInvoiceReview() " + error);
59              } else {
60                  String error = "Payment Request " + invoice.getPurapDocumentIdentifier() + ", " + identifier + " has quantity '" + itemForValidation.getItemQuantity() + "' but outstanding encumbered quantity " + itemForValidation.getPoOutstandingQuantity();
61                  LOG.error("validateInvoiceReview() " + error);
62              }
63          } else {
64              // not validating but ok
65              String error = "Payment Request " + invoice.getPurapDocumentIdentifier() + ", " + identifier + " has total amount '" + itemForValidation.getTotalAmount() + "'";
66              if (itemForValidation.getItemType().isLineItemIndicator()) {
67                  if (itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator()) {
68                      error = error + " with outstanding encumbered amount " + itemForValidation.getPoOutstandingAmount();
69                  } else {
70                      error = error + " with outstanding encumbered quantity " + itemForValidation.getPoOutstandingQuantity();
71                  }
72              }
73              LOG.info("validateInvoiceReview() " + error);
74          }
75  
76          return valid;
77      }
78  
79  
80      public InvoiceItem getItemForValidation() {
81          return itemForValidation;
82      }
83  
84      public void setItemForValidation(InvoiceItem itemForValidation) {
85          this.itemForValidation = itemForValidation;
86      }
87  
88  
89  }