View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.document.service.impl;
17  
18  import org.kuali.ole.coa.businessobject.Account;
19  import org.kuali.ole.coa.businessobject.ObjectCode;
20  import org.kuali.ole.gl.businessobject.Balance;
21  import org.kuali.ole.gl.dataaccess.BalanceDao;
22  import org.kuali.ole.sys.document.service.AccountPresenceService;
23  import org.kuali.ole.sys.service.NonTransactional;
24  
25  /**
26   * 
27   * This is the default implementation of the AccountPresenceService interface.
28   * 
29   */
30  
31  @NonTransactional
32  public class AccountPresenceServiceImpl implements AccountPresenceService {
33      private BalanceDao balanceDao;
34  
35      /**
36       * This method determines if an object code has been budgeted for account presence.  
37       * 
38       * @param account The account to be checked for the presence control flag.
39       * @param objectCode The object code being reviewed.
40       * @return True if the object code has been budgeted for an account presence, false otherwise.
41       * 
42       * @see org.kuali.ole.sys.document.service.AccountPresenceService#isObjectCodeBudgetedForAccountPresence(org.kuali.ole.coa.businessobject.Account, org.kuali.ole.coa.businessobject.ObjectCode)
43       */
44      public boolean isObjectCodeBudgetedForAccountPresence(Account account, ObjectCode objectCode) {
45          boolean objectCodeValid = true;
46  
47          /*
48           * first check if account has presence control turned on, if not no checks need to take place on object code budgeting
49           */
50          if (account.isFinancialObjectivePrsctrlIndicator()) {
51              /*
52               * can have budgeting record for object code, it's consolidation code, or object level
53               */
54  
55              // try to find budget record for object code
56              Balance foundBalance = (Balance) balanceDao.getCurrentBudgetForObjectCode(objectCode.getUniversityFiscalYear(), account.getChartOfAccountsCode(), account.getAccountNumber(), objectCode.getFinancialObjectCode());
57  
58              // if object code budget not found, try consolidation object code
59              if (foundBalance == null) {
60                  foundBalance = (Balance) balanceDao.getCurrentBudgetForObjectCode(objectCode.getUniversityFiscalYear(), account.getChartOfAccountsCode(), account.getAccountNumber(), objectCode.getFinancialObjectLevel().getConsolidatedObjectCode());
61  
62                  // if consolidation object code budget not found, try object level
63                  if (foundBalance == null) {
64                      foundBalance = (Balance) balanceDao.getCurrentBudgetForObjectCode(objectCode.getUniversityFiscalYear(), account.getChartOfAccountsCode(), account.getAccountNumber(), objectCode.getFinancialObjectLevelCode());
65  
66                      // object not budgeted
67                      if (foundBalance == null) {
68                          objectCodeValid = false;
69                      }
70                  }
71              }
72          }
73  
74          return objectCodeValid;
75      }
76  
77      /**
78       * Simple getter used to retrieve an instance of the BalanceDao.
79       * 
80       * @return Returns the balanceDao.
81       */
82      public BalanceDao getBalanceDao() {
83          return balanceDao;
84      }
85  
86      /**
87       * Simple setter used to set the local BalanceDao attribute.
88       * 
89       * @param balanceDao The balanceDao to set.
90       */
91      public void setBalanceDao(BalanceDao balanceDao) {
92          this.balanceDao = balanceDao;
93      }
94  }