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.document.AdvanceDepositDocument;
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    
025    /**
026     * Validation for the Advance Deposit document that checks the total amount of the document.
027     */
028    public class AdvanceDepositDocumentTotalValidation extends GenericValidation {
029        private AdvanceDepositDocument advanceDepositDocumentForValidation;
030    
031        /**
032         * For the Advance Deposit document, the document is balanced if the sum total of deposits - positive or negative - equals the sum total of the
033         * accounting lines.
034         * 
035         * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
036         */
037        public boolean validate(AttributedDocumentEvent event) {
038            // make sure the document is in balance
039            boolean isValid = advanceDepositDocumentForValidation.getSourceTotal().equals(advanceDepositDocumentForValidation.getTotalDollarAmount());
040    
041            if (!isValid) {
042                GlobalVariables.getMessageMap().putError(KFSPropertyConstants.NEW_ADVANCE_DEPOSIT, KFSKeyConstants.AdvanceDeposit.ERROR_DOCUMENT_ADVANCE_DEPOSIT_OUT_OF_BALANCE);
043            }
044    
045            return isValid;
046        }
047    
048        /**
049         * Gets the advanceDepositDocumentForValidation attribute. 
050         * @return Returns the advanceDepositDocumentForValidation.
051         */
052        public AdvanceDepositDocument getAdvanceDepositDocumentForValidation() {
053            return advanceDepositDocumentForValidation;
054        }
055    
056        /**
057         * Sets the advanceDepositDocumentForValidation attribute value.
058         * @param advanceDepositDocumentForValidation The advanceDepositDocumentForValidation to set.
059         */
060        public void setAdvanceDepositDocumentForValidation(AdvanceDepositDocument advanceDepositDocumentForValidation) {
061            this.advanceDepositDocumentForValidation = advanceDepositDocumentForValidation;
062        }
063    
064    }