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.PaymentRequestItem;
19  import org.kuali.ole.module.purap.document.PaymentRequestDocument;
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 PaymentRequestReviewValidation extends GenericValidation {
26      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PaymentRequestReviewValidation.class);
27  
28      private PaymentRequestItem itemForValidation;
29  
30      public boolean validate(AttributedDocumentEvent event) {
31          boolean valid = true;
32          PaymentRequestDocument paymentRequest = (PaymentRequestDocument) 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("validatePaymentRequestReview() The " + identifier + " is getting the total percent field set to " + BigDecimal.ZERO);
42          }
43  
44          if ((itemForValidation.getTotalAmount() != null && itemForValidation.getTotalAmount().isNonZero() && itemForValidation.getItemType().isLineItemIndicator() && ((itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator() && (itemForValidation.getPoOutstandingAmount() == null || itemForValidation.getPoOutstandingAmount().isZero())) || (itemForValidation.getItemType().isQuantityBasedGeneralLedgerIndicator() && (itemForValidation.getPoOutstandingQuantity() == null || itemForValidation.getPoOutstandingQuantity().isZero()))))) {
45              // ERROR because we have total amount and no open encumberance on the PO item
46              // this error should have been caught at an earlier level
47              if (itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator()) {
48                  String error = "Payment Request " + paymentRequest.getPurapDocumentIdentifier() + ", " + identifier + " has total amount '" + itemForValidation.getTotalAmount() + "' but outstanding encumbered amount " + itemForValidation.getPoOutstandingAmount();
49                  LOG.error("validatePaymentRequestReview() " + error);
50              } else {
51                  String error = "Payment Request " + paymentRequest.getPurapDocumentIdentifier() + ", " + identifier + " has quantity '" + itemForValidation.getItemQuantity() + "' but outstanding encumbered quantity " + itemForValidation.getPoOutstandingQuantity();
52                  LOG.error("validatePaymentRequestReview() " + error);
53              }
54          } else {
55              // not validating but ok
56              String error = "Payment Request " + paymentRequest.getPurapDocumentIdentifier() + ", " + identifier + " has total amount '" + itemForValidation.getTotalAmount() + "'";
57              if (itemForValidation.getItemType().isLineItemIndicator()) {
58                  if (itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator()) {
59                      error = error + " with outstanding encumbered amount " + itemForValidation.getPoOutstandingAmount();
60                  } else {
61                      error = error + " with outstanding encumbered quantity " + itemForValidation.getPoOutstandingQuantity();
62                  }
63              }
64              LOG.info("validatePaymentRequestReview() " + error);
65          }
66  
67          return valid;
68      }
69  
70  
71      public PaymentRequestItem getItemForValidation() {
72          return itemForValidation;
73      }
74  
75      public void setItemForValidation(PaymentRequestItem itemForValidation) {
76          this.itemForValidation = itemForValidation;
77      }
78  
79  
80  }