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.sys.document.service.impl;
017    
018    import org.kuali.kfs.coa.businessobject.Account;
019    import org.kuali.kfs.coa.businessobject.ObjectCode;
020    import org.kuali.kfs.gl.businessobject.Balance;
021    import org.kuali.kfs.gl.dataaccess.BalanceDao;
022    import org.kuali.kfs.sys.document.service.AccountPresenceService;
023    import org.kuali.kfs.sys.service.NonTransactional;
024    
025    /**
026     * 
027     * This is the default implementation of the AccountPresenceService interface.
028     * 
029     */
030    
031    @NonTransactional
032    public class AccountPresenceServiceImpl implements AccountPresenceService {
033        private BalanceDao balanceDao;
034    
035        /**
036         * This method determines if an object code has been budgeted for account presence.  
037         * 
038         * @param account The account to be checked for the presence control flag.
039         * @param objectCode The object code being reviewed.
040         * @return True if the object code has been budgeted for an account presence, false otherwise.
041         * 
042         * @see org.kuali.kfs.sys.document.service.AccountPresenceService#isObjectCodeBudgetedForAccountPresence(org.kuali.kfs.coa.businessobject.Account, org.kuali.kfs.coa.businessobject.ObjectCode)
043         */
044        public boolean isObjectCodeBudgetedForAccountPresence(Account account, ObjectCode objectCode) {
045            boolean objectCodeValid = true;
046    
047            /*
048             * first check if account has presence control turned on, if not no checks need to take place on object code budgeting
049             */
050            if (account.isFinancialObjectivePrsctrlIndicator()) {
051                /*
052                 * can have budgeting record for object code, it's consolidation code, or object level
053                 */
054    
055                // try to find budget record for object code
056                Balance foundBalance = (Balance) balanceDao.getCurrentBudgetForObjectCode(objectCode.getUniversityFiscalYear(), account.getChartOfAccountsCode(), account.getAccountNumber(), objectCode.getFinancialObjectCode());
057    
058                // if object code budget not found, try consolidation object code
059                if (foundBalance == null) {
060                    foundBalance = (Balance) balanceDao.getCurrentBudgetForObjectCode(objectCode.getUniversityFiscalYear(), account.getChartOfAccountsCode(), account.getAccountNumber(), objectCode.getFinancialObjectLevel().getConsolidatedObjectCode());
061    
062                    // if consolidation object code budget not found, try object level
063                    if (foundBalance == null) {
064                        foundBalance = (Balance) balanceDao.getCurrentBudgetForObjectCode(objectCode.getUniversityFiscalYear(), account.getChartOfAccountsCode(), account.getAccountNumber(), objectCode.getFinancialObjectLevelCode());
065    
066                        // object not budgeted
067                        if (foundBalance == null) {
068                            objectCodeValid = false;
069                        }
070                    }
071                }
072            }
073    
074            return objectCodeValid;
075        }
076    
077        /**
078         * Simple getter used to retrieve an instance of the BalanceDao.
079         * 
080         * @return Returns the balanceDao.
081         */
082        public BalanceDao getBalanceDao() {
083            return balanceDao;
084        }
085    
086        /**
087         * Simple setter used to set the local BalanceDao attribute.
088         * 
089         * @param balanceDao The balanceDao to set.
090         */
091        public void setBalanceDao(BalanceDao balanceDao) {
092            this.balanceDao = balanceDao;
093        }
094    }