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.ar.document.validation.impl; 017 018 import static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX; 019 020 import java.math.BigDecimal; 021 022 import org.kuali.kfs.module.ar.ArConstants; 023 import org.kuali.kfs.module.ar.ArKeyConstants; 024 import org.kuali.kfs.module.ar.ArPropertyConstants; 025 import org.kuali.kfs.module.ar.businessobject.CustomerCreditMemoDetail; 026 import org.kuali.kfs.module.ar.document.CustomerCreditMemoDocument; 027 import org.kuali.kfs.sys.KFSConstants; 028 import org.kuali.kfs.sys.document.validation.GenericValidation; 029 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 030 import org.kuali.rice.kns.util.GlobalVariables; 031 import org.kuali.rice.kns.util.KualiDecimal; 032 import org.kuali.rice.kns.util.ObjectUtils; 033 034 public class CustomerCreditMemoDetailAmountValidation extends GenericValidation { 035 036 private CustomerCreditMemoDetail customerCreditMemoDetail; 037 038 public boolean validate(AttributedDocumentEvent event) { 039 040 BigDecimal quantity = customerCreditMemoDetail.getCreditMemoItemQuantity(); 041 KualiDecimal invoiceOpenItemAmount = customerCreditMemoDetail.getInvoiceOpenItemAmount(); 042 KualiDecimal creditMemoItemAmount = customerCreditMemoDetail.getCreditMemoItemTotalAmount(); 043 boolean validValue; 044 045 if (ObjectUtils.isNotNull(creditMemoItemAmount) && ObjectUtils.isNull(quantity)) { 046 047 // customer credit memo total amount must be greater than zero 048 validValue = creditMemoItemAmount.isPositive(); 049 if (!validValue) { 050 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerCreditMemoDocumentFields.CREDIT_MEMO_ITEM_TOTAL_AMOUNT, ArKeyConstants.ERROR_CUSTOMER_CREDIT_MEMO_DETAIL_ITEM_AMOUNT_LESS_THAN_OR_EQUAL_TO_ZERO); 051 return false; 052 } 053 054 // customer credit memo total amount must not be greater than invoice open item total amount 055 validValue = creditMemoItemAmount.isLessEqual(invoiceOpenItemAmount); 056 if (!validValue) { 057 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerCreditMemoDocumentFields.CREDIT_MEMO_ITEM_TOTAL_AMOUNT, ArKeyConstants.ERROR_CUSTOMER_CREDIT_MEMO_DETAIL_ITEM_AMOUNT_GREATER_THAN_INVOICE_ITEM_AMOUNT); 058 return false; 059 } 060 } 061 return true; 062 } 063 064 public CustomerCreditMemoDetail getCustomerCreditMemoDetail() { 065 return customerCreditMemoDetail; 066 } 067 068 public void setCustomerCreditMemoDetail(CustomerCreditMemoDetail customerCreditMemoDetail) { 069 this.customerCreditMemoDetail = customerCreditMemoDetail; 070 } 071 072 073 074 }