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.fp.document.validation.impl;
017
018 import org.kuali.kfs.sys.KFSConstants;
019 import org.kuali.kfs.sys.KFSKeyConstants;
020 import org.kuali.kfs.sys.businessobject.AccountingLine;
021 import org.kuali.kfs.sys.document.validation.GenericValidation;
022 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
023 import org.kuali.rice.kns.util.GlobalVariables;
024 import org.kuali.rice.kns.util.KualiDecimal;
025
026 /**
027 * Validation that validates the amounts on accounting lines for the Cash Receipt family of documents.
028 */
029 public class CashReceiptFamilyAccountingLineAmountValidation extends GenericValidation {
030 private AccountingLine accountingLineForValidation;
031
032 /**
033 * Cash Receipt documents allow both positive and negative values, so we only need to check for zero amounts.
034 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
035 */
036 public boolean validate(AttributedDocumentEvent event) {
037 KualiDecimal amount = getAccountingLineForValidation().getAmount();
038
039 if (KualiDecimal.ZERO.compareTo(amount) == 0) { // amount == 0
040 GlobalVariables.getMessageMap().putError(KFSConstants.AMOUNT_PROPERTY_NAME, KFSKeyConstants.ERROR_ZERO_AMOUNT, "an accounting line");
041 return false;
042 }
043
044 return true;
045 }
046
047 /**
048 * Gets the accountingLineForValidation attribute.
049 * @return Returns the accountingLineForValidation.
050 */
051 public AccountingLine getAccountingLineForValidation() {
052 return accountingLineForValidation;
053 }
054
055 /**
056 * Sets the accountingLineForValidation attribute value.
057 * @param accountingLineForValidation The accountingLineForValidation to set.
058 */
059 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
060 this.accountingLineForValidation = accountingLineForValidation;
061 }
062 }