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 org.kuali.kfs.module.ar.ArConstants;
019 import org.kuali.kfs.module.ar.ArKeyConstants;
020 import org.kuali.kfs.module.ar.ArPropertyConstants;
021 import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail;
022 import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument;
023 import org.kuali.kfs.sys.KFSConstants;
024 import org.kuali.kfs.sys.document.validation.GenericValidation;
025 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
026 import org.kuali.rice.kns.util.GlobalVariables;
027 import org.kuali.rice.kns.util.KualiDecimal;
028
029 public class CustomerInvoiceDetailAmountValidation extends GenericValidation {
030
031 private CustomerInvoiceDocument customerInvoiceDocument;
032 private CustomerInvoiceDetail customerInvoiceDetail;
033
034 public boolean validate(AttributedDocumentEvent event) {
035
036 KualiDecimal amount = customerInvoiceDetail.getAmount();
037
038 if (KualiDecimal.ZERO.equals(amount)) {
039 GlobalVariables.getMessageMap().putError(KFSConstants.AMOUNT_PROPERTY_NAME, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DETAIL_TOTAL_AMOUNT_LESS_THAN_OR_EQUAL_TO_ZERO);
040 return false;
041 }
042 else {
043 // else if amount is greater than or less than zero
044
045 if (customerInvoiceDocument.isInvoiceReversal()) {
046 if (customerInvoiceDetail.isDiscountLine() && amount.isNegative()) {
047 GlobalVariables.getMessageMap().putError(KFSConstants.AMOUNT_PROPERTY_NAME, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DETAIL_TOTAL_AMOUNT_LESS_THAN_OR_EQUAL_TO_ZERO);
048 return false;
049 }
050 else if (!customerInvoiceDetail.isDiscountLine() && amount.isPositive()) {
051 GlobalVariables.getMessageMap().putError(KFSConstants.AMOUNT_PROPERTY_NAME, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DETAIL_TOTAL_AMOUNT_LESS_THAN_OR_EQUAL_TO_ZERO);
052 return false;
053 }
054 }
055 else {
056 if (customerInvoiceDetail.isDiscountLine() && amount.isPositive()) {
057 GlobalVariables.getMessageMap().putError(KFSConstants.AMOUNT_PROPERTY_NAME, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DETAIL_TOTAL_AMOUNT_LESS_THAN_OR_EQUAL_TO_ZERO);
058 return false;
059 }
060 else if (!customerInvoiceDetail.isDiscountLine() && amount.isNegative()) {
061 GlobalVariables.getMessageMap().putError(KFSConstants.AMOUNT_PROPERTY_NAME, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DETAIL_TOTAL_AMOUNT_LESS_THAN_OR_EQUAL_TO_ZERO);
062 return false;
063 }
064 }
065 }
066
067 return true;
068 }
069
070 public CustomerInvoiceDocument getCustomerInvoiceDocument() {
071 return customerInvoiceDocument;
072 }
073
074 public void setCustomerInvoiceDocument(CustomerInvoiceDocument customerInvoiceDocument) {
075 this.customerInvoiceDocument = customerInvoiceDocument;
076 }
077
078 public CustomerInvoiceDetail getCustomerInvoiceDetail() {
079 return customerInvoiceDetail;
080 }
081
082 public void setCustomerInvoiceDetail(CustomerInvoiceDetail customerInvoiceDetail) {
083 this.customerInvoiceDetail = customerInvoiceDetail;
084 }
085
086
087
088 }