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 java.util.ArrayList;
019    import java.util.Collection;
020    import java.util.HashMap;
021    import java.util.List;
022    import java.util.Map;
023    
024    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionAccountMonthlyDetailReport;
025    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionMonthly;
026    import org.kuali.kfs.module.bc.document.service.BudgetConstructionAccountMonthlyDetailReportService;
027    import org.kuali.kfs.module.bc.document.service.BudgetConstructionReportsServiceHelper;
028    import org.kuali.kfs.module.bc.report.BudgetConstructionReportHelper;
029    import org.kuali.kfs.sys.KFSPropertyConstants;
030    import org.kuali.rice.kns.service.KualiConfigurationService;
031    import org.springframework.transaction.annotation.Transactional;
032    
033    /**
034     * Service implementation of BudgetConstructionLevelSummaryReportService.
035     */
036    @Transactional
037    public class BudgetConstructionAccountMonthlyDetailReportServiceImpl implements BudgetConstructionAccountMonthlyDetailReportService {
038    
039        private KualiConfigurationService kualiConfigurationService;
040        private BudgetConstructionReportsServiceHelper budgetConstructionReportsServiceHelper;
041        
042        /**
043         * @see org.kuali.kfs.module.bc.document.service.BudgetConstructionLevelSummaryReportService#buildReports(java.lang.Integer,
044         *      java.util.Collection)
045         */
046        public Collection<BudgetConstructionAccountMonthlyDetailReport> buildReports(String documentNumber, Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber, String subAccountNumber) {
047            Collection<BudgetConstructionAccountMonthlyDetailReport> reportSet = new ArrayList();
048    
049            BudgetConstructionAccountMonthlyDetailReport accountMonthlyDetailReport;
050            // build searchCriteria
051            Map searchCriteria = new HashMap();
052            searchCriteria.put(KFSPropertyConstants.DOCUMENT_NUMBER, documentNumber);
053            searchCriteria.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, universityFiscalYear);
054            searchCriteria.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
055            searchCriteria.put(KFSPropertyConstants.ACCOUNT_NUMBER, accountNumber);
056            searchCriteria.put(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, subAccountNumber);
057            
058    
059            // build order list
060            List<String> orderList = buildOrderByList();
061            Collection<BudgetConstructionMonthly> budgetConstructionMonthlyList = budgetConstructionReportsServiceHelper.getDataForBuildingReports(BudgetConstructionMonthly.class, searchCriteria, orderList);
062    
063    
064            for (BudgetConstructionMonthly bcMonthly : budgetConstructionMonthlyList) {
065                accountMonthlyDetailReport = new BudgetConstructionAccountMonthlyDetailReport();
066                buildReportsHeader(bcMonthly, accountMonthlyDetailReport);
067                buildReportsBody(bcMonthly, accountMonthlyDetailReport);
068                
069                reportSet.add(accountMonthlyDetailReport);
070            }
071    
072            return reportSet;
073        }
074    
075        /**
076         * builds report Header
077         * 
078         * @param BudgetConstructionObjectSummary bcas
079         */
080        protected void buildReportsHeader(BudgetConstructionMonthly bcMonthly, BudgetConstructionAccountMonthlyDetailReport accountMonthlyDetailReport) {
081            accountMonthlyDetailReport.setUniversityFiscalYear(bcMonthly.getUniversityFiscalYear());
082            accountMonthlyDetailReport.setChartOfAccountsCode(bcMonthly.getChartOfAccountsCode());
083            accountMonthlyDetailReport.setAccountNumber(bcMonthly.getAccountNumber());
084            accountMonthlyDetailReport.setSubAccountNumber(bcMonthly.getSubAccountNumber());
085            accountMonthlyDetailReport.setAccountName(bcMonthly.getAccount().getAccountName());
086            try {
087                accountMonthlyDetailReport.setSubAccountName(bcMonthly.getSubAccount().getSubAccountName());
088                } catch (Exception e){
089                    accountMonthlyDetailReport.setSubAccountName("");
090                }
091        }
092    
093        /**
094         * builds report body
095         * 
096         * @param BudgetConstructionLevelSummary bcas
097         */
098        protected void buildReportsBody(BudgetConstructionMonthly bcMonthly, BudgetConstructionAccountMonthlyDetailReport accountMonthlyDetailReport) {
099            accountMonthlyDetailReport.setFinancialObjectCode(bcMonthly.getFinancialObjectCode());
100            accountMonthlyDetailReport.setFinancialSubObjectCode(bcMonthly.getFinancialSubObjectCode());
101            accountMonthlyDetailReport.setFinancialObjectCodeShortName(bcMonthly.getFinancialObject().getFinancialObjectCodeShortName());
102            accountMonthlyDetailReport.setObjCodeSubObjCode(accountMonthlyDetailReport.getFinancialObjectCode() + accountMonthlyDetailReport.getFinancialSubObjectCode());
103            
104            Integer financialDocumentMonth1LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth1LineAmount());
105            Integer financialDocumentMonth2LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth2LineAmount());
106            Integer financialDocumentMonth3LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth3LineAmount());
107            Integer financialDocumentMonth4LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth4LineAmount());
108            Integer financialDocumentMonth5LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth5LineAmount());
109            Integer financialDocumentMonth6LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth6LineAmount());
110            Integer financialDocumentMonth7LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth7LineAmount());
111            Integer financialDocumentMonth8LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth8LineAmount());
112            Integer financialDocumentMonth9LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth9LineAmount());
113            Integer financialDocumentMonth10LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth10LineAmount());
114            Integer financialDocumentMonth11LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth11LineAmount());
115            Integer financialDocumentMonth12LineAmount = BudgetConstructionReportHelper.convertKualiInteger(bcMonthly.getFinancialDocumentMonth12LineAmount());
116            
117            Integer annualAmount = financialDocumentMonth1LineAmount + financialDocumentMonth2LineAmount + financialDocumentMonth3LineAmount
118                                 + financialDocumentMonth4LineAmount + financialDocumentMonth5LineAmount + financialDocumentMonth6LineAmount
119                                 + financialDocumentMonth7LineAmount + financialDocumentMonth8LineAmount + financialDocumentMonth9LineAmount
120                                 + financialDocumentMonth10LineAmount + financialDocumentMonth11LineAmount +financialDocumentMonth12LineAmount;
121            
122            accountMonthlyDetailReport.setAnnualAmount(annualAmount);
123            accountMonthlyDetailReport.setFinancialDocumentMonth1LineAmount(financialDocumentMonth1LineAmount);
124            accountMonthlyDetailReport.setFinancialDocumentMonth2LineAmount(financialDocumentMonth2LineAmount);
125            accountMonthlyDetailReport.setFinancialDocumentMonth3LineAmount(financialDocumentMonth3LineAmount);
126            accountMonthlyDetailReport.setFinancialDocumentMonth4LineAmount(financialDocumentMonth4LineAmount);
127            accountMonthlyDetailReport.setFinancialDocumentMonth5LineAmount(financialDocumentMonth5LineAmount);
128            accountMonthlyDetailReport.setFinancialDocumentMonth6LineAmount(financialDocumentMonth6LineAmount);
129            accountMonthlyDetailReport.setFinancialDocumentMonth7LineAmount(financialDocumentMonth7LineAmount);
130            accountMonthlyDetailReport.setFinancialDocumentMonth8LineAmount(financialDocumentMonth8LineAmount);
131            accountMonthlyDetailReport.setFinancialDocumentMonth9LineAmount(financialDocumentMonth9LineAmount);
132            accountMonthlyDetailReport.setFinancialDocumentMonth10LineAmount(financialDocumentMonth10LineAmount);
133            accountMonthlyDetailReport.setFinancialDocumentMonth11LineAmount(financialDocumentMonth11LineAmount);
134            accountMonthlyDetailReport.setFinancialDocumentMonth12LineAmount(financialDocumentMonth12LineAmount);
135            
136        }
137    
138        /**
139         * builds orderByList for sort order.
140         * 
141         * @return returnList
142         */
143        protected List<String> buildOrderByList() {
144            List<String> returnList = new ArrayList();
145            returnList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
146            returnList.add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
147            return returnList;
148        }
149    
150        public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
151            this.kualiConfigurationService = kualiConfigurationService;
152        }
153    
154        public void setBudgetConstructionReportsServiceHelper(BudgetConstructionReportsServiceHelper budgetConstructionReportsServiceHelper) {
155            this.budgetConstructionReportsServiceHelper = budgetConstructionReportsServiceHelper;
156        }
157    
158    }