001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.module.purap.document.validation.impl; 017 018 import java.math.BigDecimal; 019 import java.util.Date; 020 021 import org.kuali.kfs.module.purap.PurapKeyConstants; 022 import org.kuali.kfs.module.purap.businessobject.PaymentRequestItem; 023 import org.kuali.kfs.module.purap.document.PaymentRequestDocument; 024 import org.kuali.kfs.module.purap.document.service.PaymentRequestService; 025 import org.kuali.kfs.sys.document.validation.GenericValidation; 026 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 027 import org.kuali.kfs.sys.service.UniversityDateService; 028 import org.kuali.rice.kns.util.GlobalVariables; 029 030 public class PaymentRequestReviewValidation extends GenericValidation { 031 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PaymentRequestReviewValidation.class); 032 033 private PaymentRequestItem itemForValidation; 034 035 public boolean validate(AttributedDocumentEvent event) { 036 boolean valid = true; 037 PaymentRequestDocument paymentRequest = (PaymentRequestDocument)event.getDocument(); 038 039 040 boolean containsAccounts = false; 041 int accountLineNbr = 0; 042 043 String identifier = itemForValidation.getItemIdentifierString(); 044 BigDecimal total = BigDecimal.ZERO; 045 LOG.debug("validatePaymentRequestReview() The " + identifier + " is getting the total percent field set to " + BigDecimal.ZERO); 046 047 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()))))) { 048 // ERROR because we have total amount and no open encumberance on the PO item 049 // this error should have been caught at an earlier level 050 if (itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator()) { 051 String error = "Payment Request " + paymentRequest.getPurapDocumentIdentifier() + ", " + identifier + " has total amount '" + itemForValidation.getTotalAmount() + "' but outstanding encumbered amount " + itemForValidation.getPoOutstandingAmount(); 052 LOG.error("validatePaymentRequestReview() " + error); 053 } 054 else { 055 String error = "Payment Request " + paymentRequest.getPurapDocumentIdentifier() + ", " + identifier + " has quantity '" + itemForValidation.getItemQuantity() + "' but outstanding encumbered quantity " + itemForValidation.getPoOutstandingQuantity(); 056 LOG.error("validatePaymentRequestReview() " + error); 057 } 058 } 059 else { 060 // not validating but ok 061 String error = "Payment Request " + paymentRequest.getPurapDocumentIdentifier() + ", " + identifier + " has total amount '" + itemForValidation.getTotalAmount() + "'"; 062 if (itemForValidation.getItemType().isLineItemIndicator()) { 063 if (itemForValidation.getItemType().isAmountBasedGeneralLedgerIndicator()) { 064 error = error + " with outstanding encumbered amount " + itemForValidation.getPoOutstandingAmount(); 065 } 066 else { 067 error = error + " with outstanding encumbered quantity " + itemForValidation.getPoOutstandingQuantity(); 068 } 069 } 070 LOG.info("validatePaymentRequestReview() " + error); 071 } 072 073 return valid; 074 } 075 076 077 public PaymentRequestItem getItemForValidation() { 078 return itemForValidation; 079 } 080 081 public void setItemForValidation(PaymentRequestItem itemForValidation) { 082 this.itemForValidation = itemForValidation; 083 } 084 085 086 }