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.util.HashMap;
021 import java.util.List;
022 import java.util.Map;
023
024 import org.apache.commons.lang.StringUtils;
025 import org.kuali.kfs.module.ar.ArConstants;
026 import org.kuali.kfs.module.ar.ArKeyConstants;
027 import org.kuali.kfs.module.ar.ArPropertyConstants;
028 import org.kuali.kfs.module.ar.businessobject.CashControlDetail;
029 import org.kuali.kfs.module.ar.businessobject.Customer;
030 import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail;
031 import org.kuali.kfs.module.ar.document.CashControlDocument;
032 import org.kuali.kfs.sys.KFSConstants;
033 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry;
034 import org.kuali.kfs.sys.context.SpringContext;
035 import org.kuali.kfs.sys.document.validation.GenericValidation;
036 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
037 import org.kuali.rice.kns.service.BusinessObjectService;
038 import org.kuali.rice.kns.service.ParameterService;
039 import org.kuali.rice.kns.util.GlobalVariables;
040 import org.kuali.rice.kns.util.ObjectUtils;
041
042 public class CashControlLineAmountValidation extends GenericValidation {
043
044 private CashControlDocument cashControlDocument;
045 private CashControlDetail cashControlDetail;
046
047 public boolean validate(AttributedDocumentEvent event) {
048
049 boolean isValid = true;
050
051 // line amount cannot be zero
052 if (cashControlDetail.getFinancialDocumentLineAmount().isZero()) {
053 GlobalVariables.getMessageMap().putError(ArPropertyConstants.CashControlDocumentFields.FINANCIAL_DOCUMENT_LINE_AMOUNT, ArKeyConstants.ERROR_LINE_AMOUNT_CANNOT_BE_ZERO);
054 isValid = false;
055 }
056 // line amount cannot be negative
057 if (cashControlDetail.getFinancialDocumentLineAmount().isNegative()) {
058 GlobalVariables.getMessageMap().putError(ArPropertyConstants.CashControlDocumentFields.FINANCIAL_DOCUMENT_LINE_AMOUNT, ArKeyConstants.ERROR_LINE_AMOUNT_CANNOT_BE_NEGATIVE);
059 isValid = false;
060 }
061 return isValid;
062 }
063
064 public CashControlDocument getCashControlDocument() {
065 return cashControlDocument;
066 }
067
068 public void setCashControlDocument(CashControlDocument cashControlDocument) {
069 this.cashControlDocument = cashControlDocument;
070 }
071
072 public CashControlDetail getCashControlDetail() {
073 return cashControlDetail;
074 }
075
076 public void setCashControlDetail(CashControlDetail cashControlDetail) {
077 this.cashControlDetail = cashControlDetail;
078 }
079 }