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.fp.document.BudgetAdjustmentDocument;
020    import org.kuali.kfs.fp.service.FiscalYearFunctionControlService;
021    import org.kuali.kfs.sys.KFSKeyConstants;
022    import org.kuali.kfs.sys.KFSPropertyConstants;
023    import org.kuali.kfs.sys.document.validation.GenericValidation;
024    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
025    import org.kuali.rice.kns.util.GlobalVariables;
026    
027    /**
028     * Validates an accounting line on a budget adjustment document whether the base amount on the line can be changed or not
029     */
030    public class BudgetAdjustmentAccountingLineBaseAmountValidation extends GenericValidation {
031        private BudgetAdjustmentDocument accountingDocumentForValidation;
032        private BudgetAdjustmentAccountingLine accountingLineForValidation;
033        private FiscalYearFunctionControlService fiscalYearFunctionControlService;
034    
035        /**
036         * Validate that, if a base amount is entered for a line, that it can be adjusted for the posting year
037         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
038         */
039        public boolean validate(AttributedDocumentEvent event) {
040            boolean allow = true;
041            if (getAccountingLineForValidation().getBaseBudgetAdjustmentAmount().isNonZero() && !fiscalYearFunctionControlService.isBaseAmountChangeAllowed(getAccountingDocumentForValidation().getPostingYear())) {
042                GlobalVariables.getMessageMap().putError(KFSPropertyConstants.BASE_BUDGET_ADJUSTMENT_AMOUNT, KFSKeyConstants.ERROR_DOCUMENT_BA_BASE_AMOUNT_CHANGE_NOT_ALLOWED);
043                allow = false;
044            }
045            return allow;
046        }
047    
048        /**
049         * Gets the accountingLineForValidation attribute. 
050         * @return Returns the accountingLineForValidation.
051         */
052        public BudgetAdjustmentAccountingLine getAccountingLineForValidation() {
053            return accountingLineForValidation;
054        }
055    
056        /**
057         * Sets the accountingLineForValidation attribute value.
058         * @param accountingLineForValidation The accountingLineForValidation to set.
059         */
060        public void setAccountingLineForValidation(BudgetAdjustmentAccountingLine accountingLineForValidation) {
061            this.accountingLineForValidation = accountingLineForValidation;
062        }
063    
064        /**
065         * Gets the fiscalYearFunctionControlService attribute. 
066         * @return Returns the fiscalYearFunctionControlService.
067         */
068        public FiscalYearFunctionControlService getFiscalYearFunctionControlService() {
069            return fiscalYearFunctionControlService;
070        }
071    
072        /**
073         * Sets the fiscalYearFunctionControlService attribute value.
074         * @param fiscalYearFunctionControlService The fiscalYearFunctionControlService to set.
075         */
076        public void setFiscalYearFunctionControlService(FiscalYearFunctionControlService fiscalYearFunctionControlService) {
077            this.fiscalYearFunctionControlService = fiscalYearFunctionControlService;
078        }
079    
080        /**
081         * Gets the accountingDocumentForValidation attribute. 
082         * @return Returns the accountingDocumentForValidation.
083         */
084        public BudgetAdjustmentDocument getAccountingDocumentForValidation() {
085            return accountingDocumentForValidation;
086        }
087    
088        /**
089         * Sets the accountingDocumentForValidation attribute value.
090         * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
091         */
092        public void setAccountingDocumentForValidation(BudgetAdjustmentDocument accountingDocumentForValidation) {
093            this.accountingDocumentForValidation = accountingDocumentForValidation;
094        }
095    }