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.module.bc.document.service.impl;
017    
018    import org.kuali.kfs.module.bc.document.dataaccess.BenefitsCalculationDao;
019    import org.kuali.kfs.module.bc.document.service.BenefitsCalculationService;
020    import org.kuali.kfs.sys.service.OptionsService;
021    import org.kuali.rice.kns.service.KualiConfigurationService;
022    import org.springframework.transaction.annotation.Transactional;
023    
024    /**
025     * This class implements the BenefitsCalculationService interface
026     */
027    @Transactional
028    public class BenefitsCalculationServiceImpl implements BenefitsCalculationService {
029    
030        private KualiConfigurationService kualiConfigurationService;
031        private BenefitsCalculationDao benefitsCalculationDao;
032        private OptionsService optionsService;
033    
034        /**
035         * @see org.kuali.kfs.module.bc.document.service.BenefitsCalculationService#getBenefitsCalculationDisabled()
036         */
037        public boolean isBenefitsCalculationDisabled() {
038            // Note: for now just return false, implement application parameter
039            // if decision is made to implement this functionality as an enhancement
040            return false;
041    
042            // return kualiConfigurationService.getApplicationParameterIndicator(KFSConstants.ParameterGroups.SYSTEM,
043            // BCConstants.DISABLE_BENEFITS_CALCULATION_FLAG);
044        }
045    
046        /**
047         * @see org.kuali.kfs.module.bc.document.service.BenefitsCalculationService#calculateAnnualBudgetConstructionGeneralLedgerBenefits(java.lang.String,
048         *      java.lang.Integer, java.lang.String, java.lang.String, java.lang.String)
049         */
050    
051        public void calculateAnnualBudgetConstructionGeneralLedgerBenefits(String documentNumber, Integer fiscalYear, String chartOfAccounts, String accountNumber, String subAccountNumber) {
052            /**
053             * do nothing if benefits calculation is disabled
054             */
055            if (isBenefitsCalculationDisabled())
056                return;
057            /**
058             * get the financial object type expenditure/expense
059             */
060            String finObjTypeExpenditureexpCd = optionsService.getOptions(fiscalYear).getFinObjTypeExpenditureexpCd();
061            /**
062             * calculate annual benefits
063             */
064            benefitsCalculationDao.calculateAnnualBudgetConstructionGeneralLedgerBenefits(documentNumber, fiscalYear, chartOfAccounts, accountNumber, subAccountNumber, finObjTypeExpenditureexpCd);
065        }
066    
067        /**
068         * @see org.kuali.kfs.module.bc.document.service.BenefitsCalculationService#calculateMonthlyBudgetConstructionGeneralLedgerBenefits(java.lang.String,
069         *      java.lang.Integer, java.lang.String, java.lang.String, java.lang.String)
070         */
071        public void calculateMonthlyBudgetConstructionGeneralLedgerBenefits(String documentNumber, Integer fiscalYear, String chartOfAccounts, String accountNumber, String subAccountNumber) {
072            /**
073             * do nothing if benefits calculation is disabled
074             */
075            if (isBenefitsCalculationDisabled())
076                return;
077            /**
078             * get the financial object type expenditure/expense
079             */
080            String finObjTypeExpenditureexpCd = optionsService.getOptions(fiscalYear).getFinObjTypeExpenditureexpCd();
081            /**
082             * calculate monthly benefits (assumes annual benefits have already been calculated
083             */
084            benefitsCalculationDao.calculateMonthlyBudgetConstructionGeneralLedgerBenefits(documentNumber, fiscalYear, chartOfAccounts, accountNumber, subAccountNumber, finObjTypeExpenditureexpCd);
085        }
086    
087        /**
088         * @see org.kuali.kfs.module.bc.document.service.BenefitsCalculationService#calculateAllBudgetConstructionGeneralLedgerBenefits(java.lang.String,
089         *      java.lang.Integer, java.lang.String, java.lang.String, java.lang.String)
090         */
091        public void calculateAllBudgetConstructionGeneralLedgerBenefits(String documentNumber, Integer fiscalYear, String chartOfAccounts, String accountNumber, String subAccountNumber) {
092            /**
093             *  do nothing if benefits calculation is disabled
094             */
095            if (isBenefitsCalculationDisabled())
096                return;
097            /**
098             * get the financial object type expenditure/expense
099             */
100            String finObjTypeExpenditureexpCd = optionsService.getOptions(fiscalYear).getFinObjTypeExpenditureexpCd();
101            /**
102             * call both annual and monthly calculations (order is important)
103             */
104            benefitsCalculationDao.calculateAnnualBudgetConstructionGeneralLedgerBenefits(documentNumber, fiscalYear, chartOfAccounts, accountNumber, subAccountNumber, finObjTypeExpenditureexpCd);
105            benefitsCalculationDao.calculateMonthlyBudgetConstructionGeneralLedgerBenefits(documentNumber, fiscalYear, chartOfAccounts, accountNumber, subAccountNumber, finObjTypeExpenditureexpCd);
106        }
107    
108    
109        /**
110         * Gets the kualiConfigurationService attribute.
111         * 
112         * @return Returns the kualiConfigurationService.
113         */
114        public KualiConfigurationService getKualiConfigurationService() {
115            return kualiConfigurationService;
116        }
117    
118        /**
119         * Sets the kualiConfigurationService attribute value.
120         * 
121         * @param kualiConfigurationService The kualiConfigurationService to set.
122         */
123        public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
124            this.kualiConfigurationService = kualiConfigurationService;
125        }
126    
127        /**
128         * This method allows spring to initialize the Dao, so we don't have to look up the bean on each call from the application
129         * 
130         * @param benefitsCalculationDao - the Dao for benefits calculation
131         */
132        public void setBenefitsCalculationDao(BenefitsCalculationDao benefitsCalculationDao) {
133            this.benefitsCalculationDao = benefitsCalculationDao;
134        }
135    
136        /**
137         * use this to return the "Expenditures/Expense" financial object type code from the options table this must be done by fiscal
138         * year, so unfortunately we have to make one call to OJB whenever one of the methods that needs this constant is called.
139         * 
140         * @param optionsService
141         */
142    
143        public void setOptionsService(OptionsService optionsService) {
144            this.optionsService = optionsService;
145        }
146    
147    
148    }