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.fp.businessobject.BudgetAdjustmentAccountingLine;
019    import org.kuali.kfs.sys.KFSKeyConstants;
020    import org.kuali.kfs.sys.KFSPropertyConstants;
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 for a budget adjustment accounting line that validates the information in the monthly lines
028     */
029    public class BudgetAdjustmentAccountingLineMonthlyLinesValidation extends GenericValidation {
030        private BudgetAdjustmentAccountingLine accountingLineForValidation;
031    
032        /**
033         * Validates the total of the monthly amount fields (if not 0) equals the current budget amount. If current budget is 0, then
034         * total of monthly fields must be 0.
035         * 
036         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
037         */
038        public boolean validate(AttributedDocumentEvent event) {
039            boolean validMonthlyLines = true;
040    
041            KualiDecimal monthlyTotal = getAccountingLineForValidation().getMonthlyLinesTotal();
042            if (monthlyTotal.isNonZero() && monthlyTotal.compareTo(getAccountingLineForValidation().getCurrentBudgetAdjustmentAmount()) != 0) {
043                GlobalVariables.getMessageMap().putError(KFSPropertyConstants.CURRENT_BUDGET_ADJUSTMENT_AMOUNT, KFSKeyConstants.ERROR_DOCUMENT_BA_MONTH_TOTAL_NOT_EQUAL_CURRENT);
044                validMonthlyLines = false;
045            }
046    
047            return validMonthlyLines;
048        }
049    
050        /**
051         * Gets the accountingLineForValidation attribute. 
052         * @return Returns the accountingLineForValidation.
053         */
054        public BudgetAdjustmentAccountingLine getAccountingLineForValidation() {
055            return accountingLineForValidation;
056        }
057    
058        /**
059         * Sets the accountingLineForValidation attribute value.
060         * @param accountingLineForValidation The accountingLineForValidation to set.
061         */
062        public void setAccountingLineForValidation(BudgetAdjustmentAccountingLine accountingLineForValidation) {
063            this.accountingLineForValidation = accountingLineForValidation;
064        }
065    }