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.math.BigDecimal;
019    import java.util.ArrayList;
020    import java.util.Collection;
021    import java.util.List;
022    
023    import org.apache.ojb.broker.PersistenceBrokerException;
024    import org.kuali.kfs.module.bc.BCConstants;
025    import org.kuali.kfs.module.bc.BCKeyConstants;
026    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionAccountObjectDetailReport;
027    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionAccountObjectDetailReportTotal;
028    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionBalanceByAccount;
029    import org.kuali.kfs.module.bc.document.dataaccess.BudgetConstructionDocumentAccountObjectDetailReportDao;
030    import org.kuali.kfs.module.bc.document.service.BudgetConstructionDocumentAccountObjectDetailReportService;
031    import org.kuali.kfs.module.bc.document.service.BudgetConstructionReportsServiceHelper;
032    import org.kuali.kfs.module.bc.report.BudgetConstructionReportHelper;
033    import org.kuali.kfs.sys.KFSPropertyConstants;
034    import org.kuali.rice.kns.service.KualiConfigurationService;
035    import org.springframework.transaction.annotation.Transactional;
036    
037    /**
038     * Service implementation of BudgetConstructionLevelSummaryReportService.
039     */
040    @Transactional
041    public class BudgetConstructionDocumentAccountObjectDetailReportServiceImpl implements BudgetConstructionDocumentAccountObjectDetailReportService {
042        private BudgetConstructionDocumentAccountObjectDetailReportDao budgetConstructionDocumentAccountObjectDetailReportDao;
043        private KualiConfigurationService kualiConfigurationService;
044        private BudgetConstructionReportsServiceHelper budgetConstructionReportsServiceHelper;
045    
046        public void updateDocumentAccountObjectDetailReportTable(String principalName, String documentNumber, Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber, String subAccountNumber) {
047            budgetConstructionDocumentAccountObjectDetailReportDao.updateDocumentAccountObjectDetailReportTable(principalName, documentNumber, universityFiscalYear, chartOfAccountsCode, accountNumber, subAccountNumber);
048        }
049    
050        /**
051         * @see org.kuali.kfs.module.bc.document.service.BudgetConstructionLevelSummaryReportService#buildReports(java.lang.Integer,
052         *      java.util.Collection)
053         */
054        public Collection<BudgetConstructionAccountObjectDetailReport> buildReports(String principalName) {
055            Collection<BudgetConstructionAccountObjectDetailReport> reportSet = new ArrayList();
056    
057            // build order list
058            List<String> orderList = buildOrderByList();
059            Collection<BudgetConstructionBalanceByAccount> balanceByAccountList = budgetConstructionReportsServiceHelper.getDataForBuildingReports(BudgetConstructionBalanceByAccount.class, principalName, orderList);
060    
061            
062            
063            
064            List listForCalculateObject = BudgetConstructionReportHelper.deleteDuplicated((List) balanceByAccountList, fieldsForObject());
065            List listForCalculateLevel = BudgetConstructionReportHelper.deleteDuplicated((List) balanceByAccountList, fieldsForLevel());
066            List listForCalculateType = BudgetConstructionReportHelper.deleteDuplicated((List) balanceByAccountList, fieldsForType());
067            
068            // Calculate Total Section
069            List<BudgetConstructionAccountObjectDetailReportTotal> accountObjectDetailTotalObjectList;
070            List<BudgetConstructionAccountObjectDetailReportTotal> accountObjectDetailTotalLevelList;
071            List<BudgetConstructionAccountObjectDetailReportTotal> accountObjectDetailTotalTypeList;
072            
073            accountObjectDetailTotalObjectList = calculateObjectTotal((List) balanceByAccountList, listForCalculateObject);
074            accountObjectDetailTotalLevelList = calculateLevelTotal((List) balanceByAccountList, listForCalculateLevel);
075            accountObjectDetailTotalTypeList = calculateTypeTotal((List) balanceByAccountList, listForCalculateType);
076            
077            
078            
079            
080    
081            for (BudgetConstructionBalanceByAccount balanceByAccount : balanceByAccountList) {
082                BudgetConstructionAccountObjectDetailReport accountObjectDetailReport = new BudgetConstructionAccountObjectDetailReport();
083                buildReportsHeader(balanceByAccount, accountObjectDetailReport);
084                buildReportsBody(balanceByAccount, accountObjectDetailReport);
085                buildReportsTotal(balanceByAccount, accountObjectDetailReport, accountObjectDetailTotalObjectList, accountObjectDetailTotalLevelList, accountObjectDetailTotalTypeList);
086                reportSet.add(accountObjectDetailReport);
087            }
088    
089            return reportSet;
090        }
091    
092        /**
093         * builds report Header
094         * 
095         * @param BudgetConstructionObjectSummary bcas
096         */
097        protected void buildReportsHeader(BudgetConstructionBalanceByAccount balanceByAccount, BudgetConstructionAccountObjectDetailReport accountObjectDetailReport) {
098            Integer prevFiscalyear = balanceByAccount.getUniversityFiscalYear() - 1;
099            accountObjectDetailReport.setFiscalYear(prevFiscalyear.toString() + "-" + balanceByAccount.getUniversityFiscalYear().toString().substring(2, 4));
100            
101            Integer prevPrevFiscalyear = prevFiscalyear - 1;
102            accountObjectDetailReport.setBaseFy(prevPrevFiscalyear.toString() + "-" + prevFiscalyear.toString().substring(2, 4));
103            accountObjectDetailReport.setReqFy(prevFiscalyear.toString() + "-" + balanceByAccount.getUniversityFiscalYear().toString().substring(2, 4));
104            
105            accountObjectDetailReport.setAccountNumber(balanceByAccount.getAccountNumber());
106            accountObjectDetailReport.setSubAccountNumber(balanceByAccount.getSubAccountNumber());
107            accountObjectDetailReport.setChartOfAccountsCode(balanceByAccount.getChartOfAccountsCode());
108            accountObjectDetailReport.setOrganizationCode(balanceByAccount.getAccount().getOrganizationCode());
109            
110            
111            String orgName = null;
112            try {
113                orgName = balanceByAccount.getAccount().getOrganization().getOrganizationName();
114            }
115            catch (PersistenceBrokerException e) {
116            }
117            String accountName = balanceByAccount.getAccount().getAccountName();
118            String fundGroupCode = balanceByAccount.getAccount().getSubFundGroup().getFundGroupCode();
119            String fundGroupName = balanceByAccount.getAccount().getSubFundGroup().getFundGroup().getName();
120            
121            
122            if (orgName == null) {
123                accountObjectDetailReport.setOrganizationName(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_ORGANIZATION_NAME));
124            }
125            else {
126                accountObjectDetailReport.setOrganizationName(orgName);
127            }
128            
129            if (fundGroupCode == null) {
130                accountObjectDetailReport.setFundGroupCode(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_FUNDGROUP_CODE));
131            }
132            else {
133                accountObjectDetailReport.setFundGroupCode(fundGroupCode);
134            }
135            
136            if (fundGroupName == null) {
137                accountObjectDetailReport.setFundGroupName(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_FUNDGROUP_NAME));
138            }
139            else {
140                accountObjectDetailReport.setFundGroupName(fundGroupName);
141            }
142            
143            
144            if (accountName == null) {
145                accountObjectDetailReport.setAccountName(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_ACCOUNT_DESCRIPTION));
146            }
147            else {
148                accountObjectDetailReport.setAccountName(accountName);
149            }
150            
151            String chartOfAccountDescription = "";
152            if (balanceByAccount.getChartOfAccounts() != null){
153                try {
154                    chartOfAccountDescription = balanceByAccount.getChartOfAccounts().getFinChartOfAccountDescription();
155                }
156                catch (PersistenceBrokerException e) {
157                    chartOfAccountDescription = kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_CHART_DESCRIPTION);
158                }
159            } else {
160                chartOfAccountDescription = BCConstants.Report.CHART + BCConstants.Report.NOT_DEFINED;
161            }
162            
163            accountObjectDetailReport.setChartOfAccountDescription(chartOfAccountDescription);
164            
165            String subAccountName = "";
166            
167            if (!balanceByAccount.getSubAccountNumber().equals(BCConstants.Report.DASHES_SUB_ACCOUNT_CODE)){
168                try {
169                    subAccountName = balanceByAccount.getSubAccount().getSubAccountName();
170                }
171                catch (PersistenceBrokerException e) {
172                    subAccountName = kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_SUB_ACCOUNT_DESCRIPTION);
173                }
174            }
175            accountObjectDetailReport.setSubAccountName(subAccountName);
176            
177            
178            //group
179            accountObjectDetailReport.setTypeFinancialReportSortCode(balanceByAccount.getTypeFinancialReportSortCode());
180            accountObjectDetailReport.setLevelFinancialReportSortCode(balanceByAccount.getLevelFinancialReportSortCode());
181            accountObjectDetailReport.setFinancialSubObjectCode(balanceByAccount.getFinancialSubObjectCode());
182        }
183    
184        /**
185         * builds report body
186         * 
187         * @param BudgetConstructionLevelSummary bcas
188         */
189        protected void buildReportsBody(BudgetConstructionBalanceByAccount balanceByAccount, BudgetConstructionAccountObjectDetailReport accountObjectDetailReport) {
190            accountObjectDetailReport.setFinancialObjectCode(balanceByAccount.getFinancialObjectCode());
191    
192            if (balanceByAccount.getFinancialSubObjectCode().equals(BCConstants.DASH_SUB_OBJECT_CODE)){
193                accountObjectDetailReport.setFinancialObjectName(balanceByAccount.getFinancialObject().getFinancialObjectCodeName());
194            }
195            else {
196                accountObjectDetailReport.setFinancialObjectName(balanceByAccount.getFinancialSubObject().getFinancialSubObjectCodeName());
197            }
198    
199            accountObjectDetailReport.setPositionCsfLeaveFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(balanceByAccount.getPositionCsfLeaveFteQuantity(), 2, true));
200    
201            accountObjectDetailReport.setCsfFullTimeEmploymentQuantity(BudgetConstructionReportHelper.setDecimalDigit(balanceByAccount.getCsfFullTimeEmploymentQuantity(), 2, true));
202    
203            accountObjectDetailReport.setAppointmentRequestedCsfFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(balanceByAccount.getAppointmentRequestedCsfFteQuantity(), 2, true));
204    
205            accountObjectDetailReport.setAppointmentRequestedFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(balanceByAccount.getAppointmentRequestedFteQuantity(), 2, true));
206    
207            accountObjectDetailReport.setAccountLineAnnualBalanceAmount(BudgetConstructionReportHelper.convertKualiInteger(balanceByAccount.getAccountLineAnnualBalanceAmount()));
208    
209            accountObjectDetailReport.setFinancialBeginningBalanceLineAmount(BudgetConstructionReportHelper.convertKualiInteger(balanceByAccount.getFinancialBeginningBalanceLineAmount()));
210    
211            Integer changeAmount = BudgetConstructionReportHelper.convertKualiInteger(balanceByAccount.getAccountLineAnnualBalanceAmount()) - BudgetConstructionReportHelper.convertKualiInteger(balanceByAccount.getFinancialBeginningBalanceLineAmount());
212            accountObjectDetailReport.setAmountChange(changeAmount);
213            accountObjectDetailReport.setPercentChange(BudgetConstructionReportHelper.calculatePercent(changeAmount, accountObjectDetailReport.getFinancialBeginningBalanceLineAmount()));
214    
215        }
216        
217        
218            
219        
220        
221        /**
222         * builds report total
223         */
224    
225        protected void buildReportsTotal(BudgetConstructionBalanceByAccount balanceByAccount, BudgetConstructionAccountObjectDetailReport accountObjectDetailReport, List<BudgetConstructionAccountObjectDetailReportTotal> accountObjectDetailTotalObjectList, List<BudgetConstructionAccountObjectDetailReportTotal> accountObjectDetailTotalLevelList, List<BudgetConstructionAccountObjectDetailReportTotal> accountObjectDetailTotalTypeList) {
226    
227            for (BudgetConstructionAccountObjectDetailReportTotal objectTotal : accountObjectDetailTotalObjectList) {
228                if (BudgetConstructionReportHelper.isSameEntry(balanceByAccount, objectTotal.getBudgetConstructionBalanceByAccount(), fieldsForObject())) {
229                    accountObjectDetailReport.setTotalObjectDescription(balanceByAccount.getFinancialObject().getFinancialObjectCodeName());
230    
231                    accountObjectDetailReport.setTotalObjectPositionCsfLeaveFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(objectTotal.getTotalObjectPositionCsfLeaveFteQuantity(), 2, true));
232                    accountObjectDetailReport.setTotalObjectCsfFullTimeEmploymentQuantity(BudgetConstructionReportHelper.setDecimalDigit(objectTotal.getTotalObjectCsfFullTimeEmploymentQuantity(), 2, true));
233                    accountObjectDetailReport.setTotalObjectFinancialBeginningBalanceLineAmount(objectTotal.getTotalObjectFinancialBeginningBalanceLineAmount());
234                    accountObjectDetailReport.setTotalObjectAppointmentRequestedCsfFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(objectTotal.getTotalObjectAppointmentRequestedCsfFteQuantity(), 2, true));
235                    accountObjectDetailReport.setTotalObjectAppointmentRequestedFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(objectTotal.getTotalObjectAppointmentRequestedFteQuantity(), 2, true));
236                    accountObjectDetailReport.setTotalObjectAccountLineAnnualBalanceAmount(objectTotal.getTotalObjectAccountLineAnnualBalanceAmount());
237    
238                    Integer totalObjectAmountChange = objectTotal.getTotalObjectAccountLineAnnualBalanceAmount() - objectTotal.getTotalObjectFinancialBeginningBalanceLineAmount();
239                    accountObjectDetailReport.setTotalObjectAmountChange(totalObjectAmountChange);
240                    accountObjectDetailReport.setTotalObjectPercentChange(BudgetConstructionReportHelper.calculatePercent(totalObjectAmountChange, objectTotal.getTotalObjectFinancialBeginningBalanceLineAmount()));
241                }
242            }
243    
244            for (BudgetConstructionAccountObjectDetailReportTotal levelTotal : accountObjectDetailTotalLevelList) {
245                if (BudgetConstructionReportHelper.isSameEntry(balanceByAccount, levelTotal.getBudgetConstructionBalanceByAccount(), fieldsForLevel())) {
246                    accountObjectDetailReport.setTotalLevelDescription(balanceByAccount.getFinancialObjectLevel().getFinancialObjectLevelName());
247    
248                    accountObjectDetailReport.setTotalLevelPositionCsfLeaveFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(levelTotal.getTotalLevelPositionCsfLeaveFteQuantity(), 2, true));
249                    accountObjectDetailReport.setTotalLevelCsfFullTimeEmploymentQuantity(BudgetConstructionReportHelper.setDecimalDigit(levelTotal.getTotalLevelCsfFullTimeEmploymentQuantity(), 2, true));
250                    accountObjectDetailReport.setTotalLevelFinancialBeginningBalanceLineAmount(levelTotal.getTotalLevelFinancialBeginningBalanceLineAmount());
251                    accountObjectDetailReport.setTotalLevelAppointmentRequestedCsfFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(levelTotal.getTotalLevelAppointmentRequestedCsfFteQuantity(), 2, true));
252                    accountObjectDetailReport.setTotalLevelAppointmentRequestedFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(levelTotal.getTotalLevelAppointmentRequestedFteQuantity(), 2, true));
253                    accountObjectDetailReport.setTotalLevelAccountLineAnnualBalanceAmount(levelTotal.getTotalLevelAccountLineAnnualBalanceAmount());
254    
255                    Integer totalLevelAmountChange = levelTotal.getTotalLevelAccountLineAnnualBalanceAmount() - levelTotal.getTotalLevelFinancialBeginningBalanceLineAmount();
256                    accountObjectDetailReport.setTotalLevelAmountChange(totalLevelAmountChange);
257                    accountObjectDetailReport.setTotalLevelPercentChange(BudgetConstructionReportHelper.calculatePercent(totalLevelAmountChange, levelTotal.getTotalLevelFinancialBeginningBalanceLineAmount()));
258                }
259            }
260    
261    
262            
263            for (BudgetConstructionAccountObjectDetailReportTotal typeTotal : accountObjectDetailTotalTypeList) {
264                if (BudgetConstructionReportHelper.isSameEntry(balanceByAccount, typeTotal.getBudgetConstructionBalanceByAccount(), fieldsForType())) {
265                    
266                    if (balanceByAccount.getTypeFinancialReportSortCode().equals(BCConstants.Report.INCOME_EXP_TYPE_A)) {
267                        accountObjectDetailReport.setTotalTypeDescription(BCConstants.Report.TOTAL_REVENUES);
268                    }
269                    else {
270                        accountObjectDetailReport.setTotalTypeDescription(BCConstants.Report.TOTAL_EXPENDITURES_MARGIN);
271                    }
272                    accountObjectDetailReport.setTotalTypePositionCsfLeaveFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(typeTotal.getTotalTypePositionCsfLeaveFteQuantity(), 2, true));
273                    accountObjectDetailReport.setTotalTypeCsfFullTimeEmploymentQuantity(BudgetConstructionReportHelper.setDecimalDigit(typeTotal.getTotalTypeCsfFullTimeEmploymentQuantity(), 2, true));
274                    accountObjectDetailReport.setTotalTypeFinancialBeginningBalanceLineAmount(typeTotal.getTotalTypeFinancialBeginningBalanceLineAmount());
275                    accountObjectDetailReport.setTotalTypeAppointmentRequestedCsfFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(typeTotal.getTotalTypeAppointmentRequestedCsfFteQuantity(), 2, true));
276                    accountObjectDetailReport.setTotalTypeAppointmentRequestedFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(typeTotal.getTotalTypeAppointmentRequestedFteQuantity(), 2, true));
277                    accountObjectDetailReport.setTotalTypeAccountLineAnnualBalanceAmount(typeTotal.getTotalTypeAccountLineAnnualBalanceAmount());
278    
279                    Integer totalTypeAmountChange = typeTotal.getTotalTypeAccountLineAnnualBalanceAmount() - typeTotal.getTotalTypeFinancialBeginningBalanceLineAmount();
280                    accountObjectDetailReport.setTotalTypeAmountChange(totalTypeAmountChange);
281                    accountObjectDetailReport.setTotalTypePercentChange(BudgetConstructionReportHelper.calculatePercent(totalTypeAmountChange, typeTotal.getTotalTypeFinancialBeginningBalanceLineAmount()));
282                }
283            }
284    
285    
286        }
287    
288        
289        
290        
291        
292        protected List calculateObjectTotal(List<BudgetConstructionBalanceByAccount> balanceByAccountList, List<BudgetConstructionBalanceByAccount> simpleList) {
293    
294            BigDecimal totalObjectPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
295            BigDecimal totalObjectCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
296            Integer totalObjectFinancialBeginningBalanceLineAmount = new Integer(0);
297            BigDecimal totalObjectAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
298            BigDecimal totalObjectAppointmentRequestedFteQuantity = BigDecimal.ZERO;
299            Integer totalObjectAccountLineAnnualBalanceAmount = new Integer(0);
300            
301            List returnList = new ArrayList();
302            
303            for (BudgetConstructionBalanceByAccount simpleBalanceByAccountEntry : simpleList) {
304                
305                BudgetConstructionAccountObjectDetailReportTotal bcObjectTotal = new BudgetConstructionAccountObjectDetailReportTotal();
306                for (BudgetConstructionBalanceByAccount balanceByAccountEntry : balanceByAccountList) {
307                    if (BudgetConstructionReportHelper.isSameEntry(simpleBalanceByAccountEntry, balanceByAccountEntry, fieldsForObject()) /* && !balanceByAccountEntry.getFinancialSubObjectCode().endsWith("---") */) {
308                        totalObjectFinancialBeginningBalanceLineAmount += new Integer(balanceByAccountEntry.getFinancialBeginningBalanceLineAmount().intValue());
309                        totalObjectAccountLineAnnualBalanceAmount += new Integer(balanceByAccountEntry.getAccountLineAnnualBalanceAmount().intValue());
310                        totalObjectPositionCsfLeaveFteQuantity = totalObjectPositionCsfLeaveFteQuantity.add(balanceByAccountEntry.getPositionCsfLeaveFteQuantity());
311                        totalObjectCsfFullTimeEmploymentQuantity = totalObjectCsfFullTimeEmploymentQuantity.add(balanceByAccountEntry.getCsfFullTimeEmploymentQuantity());
312                        totalObjectAppointmentRequestedCsfFteQuantity = totalObjectAppointmentRequestedCsfFteQuantity.add(balanceByAccountEntry.getAppointmentRequestedCsfFteQuantity());
313                        totalObjectAppointmentRequestedFteQuantity = totalObjectAppointmentRequestedFteQuantity.add(balanceByAccountEntry.getAppointmentRequestedFteQuantity());
314                    }
315                }
316                bcObjectTotal.setBudgetConstructionBalanceByAccount(simpleBalanceByAccountEntry);
317                bcObjectTotal.setTotalObjectPositionCsfLeaveFteQuantity(totalObjectPositionCsfLeaveFteQuantity);
318                bcObjectTotal.setTotalObjectCsfFullTimeEmploymentQuantity(totalObjectCsfFullTimeEmploymentQuantity);
319                bcObjectTotal.setTotalObjectFinancialBeginningBalanceLineAmount(totalObjectFinancialBeginningBalanceLineAmount);
320                bcObjectTotal.setTotalObjectAppointmentRequestedCsfFteQuantity(totalObjectAppointmentRequestedCsfFteQuantity);
321                bcObjectTotal.setTotalObjectAppointmentRequestedFteQuantity(totalObjectAppointmentRequestedFteQuantity);
322                bcObjectTotal.setTotalObjectAccountLineAnnualBalanceAmount(totalObjectAccountLineAnnualBalanceAmount);
323    
324                returnList.add(bcObjectTotal);
325    
326                totalObjectPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
327                totalObjectCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
328                totalObjectFinancialBeginningBalanceLineAmount = new Integer(0);
329                totalObjectAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
330                totalObjectAppointmentRequestedFteQuantity = BigDecimal.ZERO;
331                totalObjectAccountLineAnnualBalanceAmount = new Integer(0);
332    
333            }
334            return returnList;
335            
336        }
337    
338        
339        
340        
341        protected List calculateLevelTotal(List<BudgetConstructionBalanceByAccount> balanceByAccountList, List<BudgetConstructionBalanceByAccount> simpleList) {
342    
343            BigDecimal totalLevelPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
344            BigDecimal totalLevelCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
345            Integer totalLevelFinancialBeginningBalanceLineAmount = new Integer(0);
346            BigDecimal totalLevelAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
347            BigDecimal totalLevelAppointmentRequestedFteQuantity = BigDecimal.ZERO;
348            Integer totalLevelAccountLineAnnualBalanceAmount = new Integer(0);
349            
350            List returnList = new ArrayList();
351            
352            for (BudgetConstructionBalanceByAccount simpleBcosEntry : simpleList) {
353                
354                BudgetConstructionAccountObjectDetailReportTotal bcObjectTotal = new BudgetConstructionAccountObjectDetailReportTotal();
355                for (BudgetConstructionBalanceByAccount balanceByAccountEntry : balanceByAccountList) {
356                    if (BudgetConstructionReportHelper.isSameEntry(simpleBcosEntry, balanceByAccountEntry, fieldsForLevel())) {
357                        totalLevelFinancialBeginningBalanceLineAmount += new Integer(balanceByAccountEntry.getFinancialBeginningBalanceLineAmount().intValue());
358                        totalLevelAccountLineAnnualBalanceAmount += new Integer(balanceByAccountEntry.getAccountLineAnnualBalanceAmount().intValue());
359                        totalLevelPositionCsfLeaveFteQuantity = totalLevelPositionCsfLeaveFteQuantity.add(balanceByAccountEntry.getPositionCsfLeaveFteQuantity());
360                        totalLevelCsfFullTimeEmploymentQuantity = totalLevelCsfFullTimeEmploymentQuantity.add(balanceByAccountEntry.getCsfFullTimeEmploymentQuantity());
361                        totalLevelAppointmentRequestedCsfFteQuantity = totalLevelAppointmentRequestedCsfFteQuantity.add(balanceByAccountEntry.getAppointmentRequestedCsfFteQuantity());
362                        totalLevelAppointmentRequestedFteQuantity = totalLevelAppointmentRequestedFteQuantity.add(balanceByAccountEntry.getAppointmentRequestedFteQuantity());
363                    }
364                }
365                bcObjectTotal.setBudgetConstructionBalanceByAccount(simpleBcosEntry);
366                bcObjectTotal.setTotalLevelPositionCsfLeaveFteQuantity(totalLevelPositionCsfLeaveFteQuantity);
367                bcObjectTotal.setTotalLevelCsfFullTimeEmploymentQuantity(totalLevelCsfFullTimeEmploymentQuantity);
368                bcObjectTotal.setTotalLevelFinancialBeginningBalanceLineAmount(totalLevelFinancialBeginningBalanceLineAmount);
369                bcObjectTotal.setTotalLevelAppointmentRequestedCsfFteQuantity(totalLevelAppointmentRequestedCsfFteQuantity);
370                bcObjectTotal.setTotalLevelAppointmentRequestedFteQuantity(totalLevelAppointmentRequestedFteQuantity);
371                bcObjectTotal.setTotalLevelAccountLineAnnualBalanceAmount(totalLevelAccountLineAnnualBalanceAmount);
372    
373                returnList.add(bcObjectTotal);
374    
375                totalLevelPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
376                totalLevelCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
377                totalLevelFinancialBeginningBalanceLineAmount = new Integer(0);
378                totalLevelAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
379                totalLevelAppointmentRequestedFteQuantity = BigDecimal.ZERO;
380                totalLevelAccountLineAnnualBalanceAmount = new Integer(0);
381            }
382            return returnList;
383            
384        }
385    
386        
387        protected List calculateTypeTotal(List<BudgetConstructionBalanceByAccount> balanceByAccountList, List<BudgetConstructionBalanceByAccount> simpleList) {
388    
389            BigDecimal totalTypePositionCsfLeaveFteQuantity = BigDecimal.ZERO;
390            BigDecimal totalTypeCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
391            Integer totalTypeFinancialBeginningBalanceLineAmount = new Integer(0);
392            BigDecimal totalTypeAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
393            BigDecimal totalTypeAppointmentRequestedFteQuantity = BigDecimal.ZERO;
394            Integer totalTypeAccountLineAnnualBalanceAmount = new Integer(0);
395    
396            List returnList = new ArrayList();
397            for (BudgetConstructionBalanceByAccount simpleBcosEntry : simpleList) {
398                BudgetConstructionAccountObjectDetailReportTotal bcObjectTotal = new BudgetConstructionAccountObjectDetailReportTotal();
399                for (BudgetConstructionBalanceByAccount balanceByAccountEntry : balanceByAccountList) {
400                    if (BudgetConstructionReportHelper.isSameEntry(simpleBcosEntry, balanceByAccountEntry, fieldsForType())) {
401    
402                        totalTypeFinancialBeginningBalanceLineAmount += new Integer(balanceByAccountEntry.getFinancialBeginningBalanceLineAmount().intValue());
403                        totalTypeAccountLineAnnualBalanceAmount += new Integer(balanceByAccountEntry.getAccountLineAnnualBalanceAmount().intValue());
404                        totalTypePositionCsfLeaveFteQuantity = totalTypePositionCsfLeaveFteQuantity.add(balanceByAccountEntry.getPositionCsfLeaveFteQuantity());
405                        totalTypeCsfFullTimeEmploymentQuantity = totalTypeCsfFullTimeEmploymentQuantity.add(balanceByAccountEntry.getCsfFullTimeEmploymentQuantity());
406                        totalTypeAppointmentRequestedCsfFteQuantity = totalTypeAppointmentRequestedCsfFteQuantity.add(balanceByAccountEntry.getAppointmentRequestedCsfFteQuantity());
407                        totalTypeAppointmentRequestedFteQuantity = totalTypeAppointmentRequestedFteQuantity.add(balanceByAccountEntry.getAppointmentRequestedFteQuantity());
408                    }
409                }
410                
411                bcObjectTotal.setBudgetConstructionBalanceByAccount(simpleBcosEntry);
412                bcObjectTotal.setTotalTypePositionCsfLeaveFteQuantity(totalTypePositionCsfLeaveFteQuantity);
413                bcObjectTotal.setTotalTypeCsfFullTimeEmploymentQuantity(totalTypeCsfFullTimeEmploymentQuantity);
414                bcObjectTotal.setTotalTypeFinancialBeginningBalanceLineAmount(totalTypeFinancialBeginningBalanceLineAmount);
415                bcObjectTotal.setTotalTypeAppointmentRequestedCsfFteQuantity(totalTypeAppointmentRequestedCsfFteQuantity);
416                bcObjectTotal.setTotalTypeAppointmentRequestedFteQuantity(totalTypeAppointmentRequestedFteQuantity);
417                bcObjectTotal.setTotalTypeAccountLineAnnualBalanceAmount(totalTypeAccountLineAnnualBalanceAmount);
418    
419                returnList.add(bcObjectTotal);
420    
421                totalTypePositionCsfLeaveFteQuantity = BigDecimal.ZERO;
422                totalTypeCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
423                totalTypeFinancialBeginningBalanceLineAmount = new Integer(0);
424                totalTypeAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
425                totalTypeAppointmentRequestedFteQuantity = BigDecimal.ZERO;
426                totalTypeAccountLineAnnualBalanceAmount = new Integer(0);
427            }
428    
429            return returnList;
430        }
431    
432        
433        
434        
435        
436        
437    
438        /**
439         * builds orderByList for sort order.
440         * 
441         * @return returnList
442         */
443        protected List<String> buildOrderByList() {
444            List<String> returnList = new ArrayList();
445            returnList.add(KFSPropertyConstants.ACCOUNT_NUMBER);
446            returnList.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
447            returnList.add(KFSPropertyConstants.TYPE_FINANCIAL_REPORT_SORT_CODE);
448            returnList.add(KFSPropertyConstants.FINANCIAL_CONSOLIDATION_SORT_CODE);
449            returnList.add(KFSPropertyConstants.LEVEL_FINANCIAL_REPORT_SORT_CODE);
450            returnList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
451            returnList.add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
452            return returnList;
453        }
454        
455        /**
456         * builds list of fields for comparing entry of Object
457         * @return List<String>
458         */
459        protected List<String> fieldsForObject() {
460            List<String> fieldList = new ArrayList();
461            fieldList.addAll(fieldsForLevel());
462            fieldList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
463            //fieldList.add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
464            return fieldList;
465        }    
466        
467        /**
468         * builds list of fields for comparing entry of Level
469         * @return List<String>
470         */
471        protected List<String> fieldsForLevel() {
472            List<String> fieldList = new ArrayList();
473            fieldList.addAll(fieldsForType());
474            fieldList.add(KFSPropertyConstants.LEVEL_FINANCIAL_REPORT_SORT_CODE);
475            return fieldList;
476        }    
477    
478        /**
479         * builds list of fields for comparing entry of GexpAndType
480         * @return List<String>
481         */
482        protected List<String> fieldsForType() {
483            List<String> fieldList = new ArrayList();
484            fieldList.add(KFSPropertyConstants.TYPE_FINANCIAL_REPORT_SORT_CODE);
485            return fieldList;
486        }
487        
488        /*protected List<String> commonFields(){
489            List<String> fieldList = new ArrayList();
490            fieldList.add(KFSPropertyConstants.TYPE_FINANCIAL_REPORT_SORT_CODE);
491            fieldList.add(KFSPropertyConstants.LEVEL_FINANCIAL_REPORT_SORT_CODE);
492            fieldList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
493            fieldList.add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
494            
495            returnList.add(KFSPropertyConstants.ACCOUNT_NUMBER);
496            returnList.add(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
497            returnList.add(KFSPropertyConstants.TYPE_FINANCIAL_REPORT_SORT_CODE);
498            returnList.add(KFSPropertyConstants.FINANCIAL_CONSOLIDATION_SORT_CODE);
499            returnList.add(KFSPropertyConstants.LEVEL_FINANCIAL_REPORT_SORT_CODE);
500            returnList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
501            returnList.add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
502            
503            
504            return fieldList;
505        }
506    
507    */    
508    
509        public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
510            this.kualiConfigurationService = kualiConfigurationService;
511        }
512    
513        public void setBudgetConstructionReportsServiceHelper(BudgetConstructionReportsServiceHelper budgetConstructionReportsServiceHelper) {
514            this.budgetConstructionReportsServiceHelper = budgetConstructionReportsServiceHelper;
515        }
516    
517        public void setBudgetConstructionDocumentAccountObjectDetailReportDao(BudgetConstructionDocumentAccountObjectDetailReportDao budgetConstructionDocumentAccountObjectDetailReportDao) {
518            this.budgetConstructionDocumentAccountObjectDetailReportDao = budgetConstructionDocumentAccountObjectDetailReportDao;
519        }
520    
521    }
522