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.kuali.kfs.coa.businessobject.ObjectCode;
024    import org.kuali.kfs.module.bc.BCConstants;
025    import org.kuali.kfs.module.bc.BCKeyConstants;
026    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionObjectSummary;
027    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionOrgObjectSummaryReport;
028    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionOrgObjectSummaryReportTotal;
029    import org.kuali.kfs.module.bc.document.dataaccess.BudgetConstructionObjectSummaryReportDao;
030    import org.kuali.kfs.module.bc.document.service.BudgetConstructionObjectSummaryReportService;
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 BudgetConstructionObjectSummaryReportServiceImpl implements BudgetConstructionObjectSummaryReportService {
042    
043        private BudgetConstructionObjectSummaryReportDao budgetConstructionObjectSummaryReportDao;
044        private KualiConfigurationService kualiConfigurationService;
045        private BudgetConstructionReportsServiceHelper budgetConstructionReportsServiceHelper;
046    
047        /**
048         * @see org.kuali.kfs.module.bc.document.service.BudgetReportsControlListService#updateRepotsLevelSummaryTable(java.lang.String)
049         */
050        public void updateObjectSummaryReport(String principalName) {
051            budgetConstructionObjectSummaryReportDao.cleanGeneralLedgerObjectSummaryTable(principalName);
052            budgetConstructionObjectSummaryReportDao.updateGeneralLedgerObjectSummaryTable(principalName);
053        }
054    
055        /**
056         * sets budgetConstructionLevelSummaryReportDao
057         * 
058         * @param budgetConstructionLevelSummaryReportDao
059         */
060        public void setBudgetConstructionObjectSummaryReportDao(BudgetConstructionObjectSummaryReportDao budgetConstructionObjectSummaryReportDao) {
061            this.budgetConstructionObjectSummaryReportDao = budgetConstructionObjectSummaryReportDao;
062        }
063    
064        /**
065         * @see org.kuali.kfs.module.bc.document.service.BudgetConstructionLevelSummaryReportService#buildReports(java.lang.Integer,
066         *      java.util.Collection)
067         */
068        public Collection<BudgetConstructionOrgObjectSummaryReport> buildReports(Integer universityFiscalYear, String principalName) {
069            Collection<BudgetConstructionOrgObjectSummaryReport> reportSet = new ArrayList();
070            Collection<BudgetConstructionObjectSummary> objectSummaryList = budgetConstructionReportsServiceHelper.getDataForBuildingReports(BudgetConstructionObjectSummary.class, principalName, buildOrderByList());
071    
072            // 
073            List listForCalculateLevel = BudgetConstructionReportHelper.deleteDuplicated((List) objectSummaryList, fieldsForLevel());
074            List listForCalculateCons = BudgetConstructionReportHelper.deleteDuplicated((List) objectSummaryList, fieldsForCons());
075            List listForCalculateGexpAndType = BudgetConstructionReportHelper.deleteDuplicated((List) objectSummaryList, fieldsForGexpAndType());
076            List listForCalculateTotal = BudgetConstructionReportHelper.deleteDuplicated((List) objectSummaryList, fieldsForTotal());
077    
078            // Calculate Total Section
079            List<BudgetConstructionOrgObjectSummaryReportTotal> objectSummaryTotalLevelList = calculateLevelTotal((List) objectSummaryList, listForCalculateLevel);
080            List<BudgetConstructionOrgObjectSummaryReportTotal> objectSummaryTotalConsList = calculateConsTotal((List) objectSummaryList, listForCalculateCons);
081            List<BudgetConstructionOrgObjectSummaryReportTotal> objectSummaryTotalGexpAndTypeList = calculateGexpAndTypeTotal((List) objectSummaryList, listForCalculateGexpAndType);
082            List<BudgetConstructionOrgObjectSummaryReportTotal> objectSummaryTotalList = calculateTotal((List) objectSummaryList, listForCalculateTotal);
083    
084            for (BudgetConstructionObjectSummary objectSummaryEntry : objectSummaryList) {
085                BudgetConstructionOrgObjectSummaryReport orgObjectSummaryReportEntry = new BudgetConstructionOrgObjectSummaryReport();
086                buildReportsHeader(universityFiscalYear, orgObjectSummaryReportEntry, objectSummaryEntry);
087                buildReportsBody(universityFiscalYear, orgObjectSummaryReportEntry, objectSummaryEntry);
088                buildReportsTotal(orgObjectSummaryReportEntry, objectSummaryEntry, objectSummaryTotalLevelList, objectSummaryTotalConsList, objectSummaryTotalGexpAndTypeList, objectSummaryTotalList);
089                reportSet.add(orgObjectSummaryReportEntry);
090            }
091    
092            return reportSet;
093        }
094    
095        /**
096         * builds report Header
097         * 
098         * @param BudgetConstructionObjectSummary bcas
099         */
100        protected void buildReportsHeader(Integer universityFiscalYear, BudgetConstructionOrgObjectSummaryReport orgObjectSummaryReportEntry, BudgetConstructionObjectSummary objectSummary) {
101            String orgChartDesc = objectSummary.getOrganizationChartOfAccounts().getFinChartOfAccountDescription();
102            String chartDesc = objectSummary.getChartOfAccounts().getFinChartOfAccountDescription();
103            String orgName = objectSummary.getOrganization().getOrganizationName();
104            String reportChartDesc = objectSummary.getChartOfAccounts().getReportsToChartOfAccounts().getFinChartOfAccountDescription();
105            String subFundGroupName = objectSummary.getSubFundGroup().getSubFundGroupCode();
106            String subFundGroupDes = objectSummary.getSubFundGroup().getSubFundGroupDescription();
107            String fundGroupName = objectSummary.getSubFundGroup().getFundGroupCode();
108            String fundGroupDes = objectSummary.getSubFundGroup().getFundGroup().getName();
109    
110            Integer prevFiscalyear = universityFiscalYear - 1;
111            orgObjectSummaryReportEntry.setFiscalYear(prevFiscalyear.toString() + "-" + universityFiscalYear.toString().substring(2, 4));
112            orgObjectSummaryReportEntry.setOrgChartOfAccountsCode(objectSummary.getOrganizationChartOfAccountsCode());
113    
114            if (orgChartDesc == null) {
115                orgObjectSummaryReportEntry.setOrgChartOfAccountDescription(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_CHART_DESCRIPTION));
116            }
117            else {
118                orgObjectSummaryReportEntry.setOrgChartOfAccountDescription(orgChartDesc);
119            }
120    
121            orgObjectSummaryReportEntry.setOrganizationCode(objectSummary.getOrganizationCode());
122            if (orgName == null) {
123                orgObjectSummaryReportEntry.setOrganizationName(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_ORGANIZATION_NAME));
124            }
125            else {
126                orgObjectSummaryReportEntry.setOrganizationName(orgName);
127            }
128    
129            orgObjectSummaryReportEntry.setChartOfAccountsCode(objectSummary.getChartOfAccountsCode());
130            if (chartDesc == null) {
131                orgObjectSummaryReportEntry.setChartOfAccountDescription(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_CHART_DESCRIPTION));
132            }
133            else {
134                orgObjectSummaryReportEntry.setChartOfAccountDescription(chartDesc);
135            }
136    
137            orgObjectSummaryReportEntry.setFundGroupCode(objectSummary.getSubFundGroup().getFundGroupCode());
138            if (fundGroupDes == null) {
139                orgObjectSummaryReportEntry.setFundGroupName(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_FUNDGROUP_NAME));
140            }
141            else {
142                orgObjectSummaryReportEntry.setFundGroupName(fundGroupDes);
143            }
144    
145            orgObjectSummaryReportEntry.setSubFundGroupCode(objectSummary.getSubFundGroupCode());
146            if (subFundGroupDes == null) {
147                orgObjectSummaryReportEntry.setSubFundGroupDescription(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_SUBFUNDGROUP_DESCRIPTION));
148            }
149            else {
150                orgObjectSummaryReportEntry.setSubFundGroupDescription(subFundGroupDes);
151            }
152    
153            Integer prevPrevFiscalyear = prevFiscalyear - 1;
154            orgObjectSummaryReportEntry.setBaseFy(prevPrevFiscalyear.toString() + "-" + prevFiscalyear.toString().substring(2, 4));
155            orgObjectSummaryReportEntry.setReqFy(prevFiscalyear.toString() + "-" + universityFiscalYear.toString().substring(2, 4));
156            orgObjectSummaryReportEntry.setHeader1("Object Name");
157            orgObjectSummaryReportEntry.setHeader2a("Lv. FTE");
158            orgObjectSummaryReportEntry.setHeader2("FTE");
159            orgObjectSummaryReportEntry.setHeader3("Amount");
160            orgObjectSummaryReportEntry.setHeader31("FTE");
161            orgObjectSummaryReportEntry.setHeader40("FTE");
162            orgObjectSummaryReportEntry.setHeader4("Amount");
163            orgObjectSummaryReportEntry.setHeader5(kualiConfigurationService.getPropertyString(BCKeyConstants.MSG_REPORT_HEADER_CHANGE));
164            orgObjectSummaryReportEntry.setHeader6(kualiConfigurationService.getPropertyString(BCKeyConstants.MSG_REPORT_HEADER_CHANGE));
165            orgObjectSummaryReportEntry.setConsHdr("");
166    
167            // For page break for objectObjectCode
168            orgObjectSummaryReportEntry.setFinancialObjectLevelCode(objectSummary.getFinancialObjectLevelCode());
169            orgObjectSummaryReportEntry.setIncomeExpenseCode(objectSummary.getIncomeExpenseCode());
170            orgObjectSummaryReportEntry.setFinancialConsolidationSortCode(objectSummary.getFinancialConsolidationSortCode());
171            orgObjectSummaryReportEntry.setFinancialLevelSortCode(objectSummary.getFinancialLevelSortCode());
172        }
173    
174        /**
175         * builds report body
176         * 
177         * @param BudgetConstructionLevelSummary bcas
178         */
179        protected void buildReportsBody(Integer universityFiscalYear, BudgetConstructionOrgObjectSummaryReport orgObjectSummaryReportEntry, BudgetConstructionObjectSummary objectSummary) {
180    
181            orgObjectSummaryReportEntry.setFinancialObjectCode(objectSummary.getFinancialObjectCode());
182            // To get ObjectName: There is no universityFiscalyear field in BudgetConstructionObjectSummary,
183            // so we can get ObjectName by getting ObjectCode with Primary key.
184            ObjectCode objectCode = budgetConstructionReportsServiceHelper.getObjectCode(universityFiscalYear, objectSummary.getChartOfAccountsCode(), objectSummary.getFinancialObjectCode());
185            String objectName = null;
186    
187            if (objectCode == null) {
188                orgObjectSummaryReportEntry.setFinancialObjectName(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_OBJECT_CODE));
189            }
190            else {
191                objectName = objectCode.getFinancialObjectCodeName();
192                if (objectName == null) {
193                    orgObjectSummaryReportEntry.setFinancialObjectName(kualiConfigurationService.getPropertyString(BCKeyConstants.ERROR_REPORT_GETTING_OBJECT_NAME));
194                }
195                else {
196                    orgObjectSummaryReportEntry.setFinancialObjectName(objectName);
197                }
198            }
199            orgObjectSummaryReportEntry.setPositionCsfLeaveFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(objectSummary.getPositionCsfLeaveFteQuantity(), 2, true));
200            orgObjectSummaryReportEntry.setCsfFullTimeEmploymentQuantity(BudgetConstructionReportHelper.setDecimalDigit(objectSummary.getCsfFullTimeEmploymentQuantity(), 2, true));
201            orgObjectSummaryReportEntry.setAppointmentRequestedCsfFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(objectSummary.getAppointmentRequestedCsfFteQuantity(), 2, true));
202            orgObjectSummaryReportEntry.setAppointmentRequestedFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(objectSummary.getAppointmentRequestedFteQuantity(), 2, true));
203    
204            if (objectSummary.getAccountLineAnnualBalanceAmount() != null) {
205                orgObjectSummaryReportEntry.setAccountLineAnnualBalanceAmount(new Integer(objectSummary.getAccountLineAnnualBalanceAmount().intValue()));
206            }
207    
208            if (objectSummary.getFinancialBeginningBalanceLineAmount() != null) {
209                orgObjectSummaryReportEntry.setFinancialBeginningBalanceLineAmount(new Integer(objectSummary.getFinancialBeginningBalanceLineAmount().intValue()));
210            }
211    
212            if (objectSummary.getAccountLineAnnualBalanceAmount() != null && objectSummary.getFinancialBeginningBalanceLineAmount() != null) {
213                int changeAmount = objectSummary.getAccountLineAnnualBalanceAmount().subtract(objectSummary.getFinancialBeginningBalanceLineAmount()).intValue();
214                orgObjectSummaryReportEntry.setAmountChange(new Integer(changeAmount));
215            }
216    
217            orgObjectSummaryReportEntry.setPercentChange(BudgetConstructionReportHelper.calculatePercent(orgObjectSummaryReportEntry.getAmountChange(), orgObjectSummaryReportEntry.getFinancialBeginningBalanceLineAmount()));
218        }
219    
220        /**
221         * builds report total
222         * 
223         * @param BudgetConstructionObjectSummary bcas
224         * @param List reportTotalList
225         */
226        protected void buildReportsTotal(BudgetConstructionOrgObjectSummaryReport orgObjectSummaryReportEntry, BudgetConstructionObjectSummary objectSummary, List<BudgetConstructionOrgObjectSummaryReportTotal> objectSummaryTotalLevelList, List<BudgetConstructionOrgObjectSummaryReportTotal> objectSummaryTotalConsList, List<BudgetConstructionOrgObjectSummaryReportTotal> objectSummaryTotalGexpAndTypeList, List<BudgetConstructionOrgObjectSummaryReportTotal> objectSummaryTotalList) {
227    
228            for (BudgetConstructionOrgObjectSummaryReportTotal levelTotal : objectSummaryTotalLevelList) {
229                if (BudgetConstructionReportHelper.isSameEntry(objectSummary, levelTotal.getBcos(), fieldsForLevel())) {
230                    orgObjectSummaryReportEntry.setTotalLevelDescription(objectSummary.getFinancialObjectLevel().getFinancialObjectLevelName());
231    
232                    orgObjectSummaryReportEntry.setTotalLevelPositionCsfLeaveFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(levelTotal.getTotalLevelPositionCsfLeaveFteQuantity(), 2, true));
233                    orgObjectSummaryReportEntry.setTotalLevelPositionCsfFullTimeEmploymentQuantity(BudgetConstructionReportHelper.setDecimalDigit(levelTotal.getTotalLevelPositionCsfFullTimeEmploymentQuantity(), 2, true));
234                    orgObjectSummaryReportEntry.setTotalLevelFinancialBeginningBalanceLineAmount(levelTotal.getTotalLevelFinancialBeginningBalanceLineAmount());
235                    orgObjectSummaryReportEntry.setTotalLevelAppointmentRequestedCsfFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(levelTotal.getTotalLevelAppointmentRequestedCsfFteQuantity(), 2, true));
236                    orgObjectSummaryReportEntry.setTotalLevelAppointmentRequestedFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(levelTotal.getTotalLevelAppointmentRequestedFteQuantity(), 2, true));
237                    orgObjectSummaryReportEntry.setTotalLevelAccountLineAnnualBalanceAmount(levelTotal.getTotalLevelAccountLineAnnualBalanceAmount());
238    
239                    Integer totalLevelAmountChange = levelTotal.getTotalLevelAccountLineAnnualBalanceAmount() - levelTotal.getTotalLevelFinancialBeginningBalanceLineAmount();
240                    orgObjectSummaryReportEntry.setTotalLevelAmountChange(totalLevelAmountChange);
241                    orgObjectSummaryReportEntry.setTotalLevelPercentChange(BudgetConstructionReportHelper.calculatePercent(totalLevelAmountChange, levelTotal.getTotalLevelFinancialBeginningBalanceLineAmount()));
242                }
243            }
244    
245            for (BudgetConstructionOrgObjectSummaryReportTotal consTotal : objectSummaryTotalConsList) {
246                if (BudgetConstructionReportHelper.isSameEntry(objectSummary, consTotal.getBcos(), fieldsForCons())) {
247                    orgObjectSummaryReportEntry.setTotalConsolidationDescription(objectSummary.getFinancialConsolidationObject().getFinConsolidationObjectName());
248    
249                    orgObjectSummaryReportEntry.setTotalConsolidationPositionCsfLeaveFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(consTotal.getTotalConsolidationPositionCsfLeaveFteQuantity(), 2, true));
250                    orgObjectSummaryReportEntry.setTotalConsolidationPositionCsfFullTimeEmploymentQuantity(BudgetConstructionReportHelper.setDecimalDigit(consTotal.getTotalConsolidationPositionCsfFullTimeEmploymentQuantity(), 2, true));
251                    orgObjectSummaryReportEntry.setTotalConsolidationFinancialBeginningBalanceLineAmount(consTotal.getTotalConsolidationFinancialBeginningBalanceLineAmount());
252                    orgObjectSummaryReportEntry.setTotalConsolidationAppointmentRequestedCsfFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(consTotal.getTotalConsolidationAppointmentRequestedCsfFteQuantity(), 2, true));
253                    orgObjectSummaryReportEntry.setTotalConsolidationAppointmentRequestedFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(consTotal.getTotalConsolidationAppointmentRequestedFteQuantity(), 2, true));
254                    orgObjectSummaryReportEntry.setTotalConsolidationAccountLineAnnualBalanceAmount(consTotal.getTotalConsolidationAccountLineAnnualBalanceAmount());
255                    Integer totalConsolidationAmountChange = consTotal.getTotalConsolidationAccountLineAnnualBalanceAmount() - consTotal.getTotalConsolidationFinancialBeginningBalanceLineAmount();
256                    orgObjectSummaryReportEntry.setTotalConsolidationAmountChange(totalConsolidationAmountChange);
257                    orgObjectSummaryReportEntry.setTotalConsolidationPercentChange(BudgetConstructionReportHelper.calculatePercent(totalConsolidationAmountChange, consTotal.getTotalConsolidationFinancialBeginningBalanceLineAmount()));
258    
259                }
260            }
261    
262            for (BudgetConstructionOrgObjectSummaryReportTotal gexpAndTypeTotal : objectSummaryTotalGexpAndTypeList) {
263                if (BudgetConstructionReportHelper.isSameEntry(objectSummary, gexpAndTypeTotal.getBcos(), fieldsForGexpAndType())) {
264    
265                    orgObjectSummaryReportEntry.setGrossFinancialBeginningBalanceLineAmount(gexpAndTypeTotal.getGrossFinancialBeginningBalanceLineAmount());
266                    orgObjectSummaryReportEntry.setGrossAccountLineAnnualBalanceAmount(gexpAndTypeTotal.getGrossAccountLineAnnualBalanceAmount());
267                    Integer grossAmountChange = gexpAndTypeTotal.getGrossAccountLineAnnualBalanceAmount() - gexpAndTypeTotal.getGrossFinancialBeginningBalanceLineAmount();
268                    orgObjectSummaryReportEntry.setGrossAmountChange(grossAmountChange);
269                    orgObjectSummaryReportEntry.setGrossPercentChange(BudgetConstructionReportHelper.calculatePercent(grossAmountChange, gexpAndTypeTotal.getGrossFinancialBeginningBalanceLineAmount()));
270    
271                    if (objectSummary.getIncomeExpenseCode().equals(BCConstants.Report.INCOME_EXP_TYPE_A)) {
272                        orgObjectSummaryReportEntry.setTypeDesc(kualiConfigurationService.getPropertyString(BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_UPPERCASE_REVENUE));
273                    }
274                    else {
275                        orgObjectSummaryReportEntry.setTypeDesc(kualiConfigurationService.getPropertyString(BCKeyConstants.MSG_REPORT_INCOME_EXP_DESC_EXPENDITURE_NET_TRNFR));
276                    }
277                    orgObjectSummaryReportEntry.setTypePositionCsfLeaveFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(gexpAndTypeTotal.getTypePositionCsfLeaveFteQuantity(), 2, true));
278                    orgObjectSummaryReportEntry.setTypePositionCsfFullTimeEmploymentQuantity(BudgetConstructionReportHelper.setDecimalDigit(gexpAndTypeTotal.getTypePositionCsfFullTimeEmploymentQuantity(), 2, true));
279                    orgObjectSummaryReportEntry.setTypeFinancialBeginningBalanceLineAmount(gexpAndTypeTotal.getTypeFinancialBeginningBalanceLineAmount());
280                    orgObjectSummaryReportEntry.setTypeAppointmentRequestedCsfFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(gexpAndTypeTotal.getTypeAppointmentRequestedCsfFteQuantity(), 2, true));
281                    orgObjectSummaryReportEntry.setTypeAppointmentRequestedFteQuantity(BudgetConstructionReportHelper.setDecimalDigit(gexpAndTypeTotal.getTypeAppointmentRequestedFteQuantity(), 2, true));
282                    orgObjectSummaryReportEntry.setTypeAccountLineAnnualBalanceAmount(gexpAndTypeTotal.getTypeAccountLineAnnualBalanceAmount());
283                    Integer typeAmountChange = gexpAndTypeTotal.getTypeAccountLineAnnualBalanceAmount() - gexpAndTypeTotal.getTypeFinancialBeginningBalanceLineAmount();
284                    orgObjectSummaryReportEntry.setTypeAmountChange(typeAmountChange);
285                    orgObjectSummaryReportEntry.setTypePercentChange(BudgetConstructionReportHelper.calculatePercent(typeAmountChange, gexpAndTypeTotal.getTypeFinancialBeginningBalanceLineAmount()));
286                }
287            }
288    
289            for (BudgetConstructionOrgObjectSummaryReportTotal total : objectSummaryTotalList) {
290                if (BudgetConstructionReportHelper.isSameEntry(objectSummary, total.getBcos(), fieldsForTotal())) {
291                    orgObjectSummaryReportEntry.setTotalSubFundGroupDesc(objectSummary.getSubFundGroup().getSubFundGroupDescription());
292                    orgObjectSummaryReportEntry.setRevenueFinancialBeginningBalanceLineAmount(total.getRevenueFinancialBeginningBalanceLineAmount());
293                    orgObjectSummaryReportEntry.setRevenueAccountLineAnnualBalanceAmount(total.getRevenueAccountLineAnnualBalanceAmount());
294                    orgObjectSummaryReportEntry.setExpenditureFinancialBeginningBalanceLineAmount(total.getExpenditureFinancialBeginningBalanceLineAmount());
295                    orgObjectSummaryReportEntry.setExpenditureAccountLineAnnualBalanceAmount(total.getExpenditureAccountLineAnnualBalanceAmount());
296    
297                    Integer revenueAmountChange = total.getRevenueAccountLineAnnualBalanceAmount() - total.getRevenueFinancialBeginningBalanceLineAmount();
298                    orgObjectSummaryReportEntry.setRevenueAmountChange(revenueAmountChange);
299                    orgObjectSummaryReportEntry.setRevenuePercentChange(BudgetConstructionReportHelper.calculatePercent(revenueAmountChange, total.getRevenueFinancialBeginningBalanceLineAmount()));
300    
301                    Integer expenditureAmountChange = total.getExpenditureAccountLineAnnualBalanceAmount() - total.getExpenditureFinancialBeginningBalanceLineAmount();
302                    orgObjectSummaryReportEntry.setExpenditureAmountChange(expenditureAmountChange);
303                    orgObjectSummaryReportEntry.setExpenditurePercentChange(BudgetConstructionReportHelper.calculatePercent(expenditureAmountChange, total.getExpenditureFinancialBeginningBalanceLineAmount()));
304    
305                    orgObjectSummaryReportEntry.setDifferenceFinancialBeginningBalanceLineAmount(total.getDifferenceFinancialBeginningBalanceLineAmount());
306                    orgObjectSummaryReportEntry.setDifferenceAccountLineAnnualBalanceAmount(total.getDifferenceAccountLineAnnualBalanceAmount());
307    
308                    Integer differenceAmountChange = total.getDifferenceAccountLineAnnualBalanceAmount() - total.getDifferenceFinancialBeginningBalanceLineAmount();
309                    orgObjectSummaryReportEntry.setDifferenceAmountChange(differenceAmountChange);
310                    orgObjectSummaryReportEntry.setDifferencePercentChange(BudgetConstructionReportHelper.calculatePercent(differenceAmountChange, total.getDifferenceFinancialBeginningBalanceLineAmount()));
311                }
312            }
313        }
314    
315        protected List calculateLevelTotal(List<BudgetConstructionObjectSummary> bcosList, List<BudgetConstructionObjectSummary> simpleList) {
316    
317            BigDecimal totalLevelPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
318            BigDecimal totalLevelPositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
319            Integer totalLevelFinancialBeginningBalanceLineAmount = new Integer(0);
320            BigDecimal totalLevelAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
321            BigDecimal totalLevelAppointmentRequestedFteQuantity = BigDecimal.ZERO;
322            Integer totalLevelAccountLineAnnualBalanceAmount = new Integer(0);
323    
324            List returnList = new ArrayList();
325    
326            for (BudgetConstructionObjectSummary simpleBcosEntry : simpleList) {
327                BudgetConstructionOrgObjectSummaryReportTotal bcObjectTotal = new BudgetConstructionOrgObjectSummaryReportTotal();
328                for (BudgetConstructionObjectSummary bcosListEntry : bcosList) {
329                    if (BudgetConstructionReportHelper.isSameEntry(simpleBcosEntry, bcosListEntry, fieldsForLevel())) {
330                        totalLevelFinancialBeginningBalanceLineAmount += new Integer(bcosListEntry.getFinancialBeginningBalanceLineAmount().intValue());
331                        totalLevelAccountLineAnnualBalanceAmount += new Integer(bcosListEntry.getAccountLineAnnualBalanceAmount().intValue());
332                        totalLevelPositionCsfLeaveFteQuantity = totalLevelPositionCsfLeaveFteQuantity.add(bcosListEntry.getPositionCsfLeaveFteQuantity());
333                        totalLevelPositionCsfFullTimeEmploymentQuantity = totalLevelPositionCsfFullTimeEmploymentQuantity.add(bcosListEntry.getCsfFullTimeEmploymentQuantity());
334                        totalLevelAppointmentRequestedCsfFteQuantity = totalLevelAppointmentRequestedCsfFteQuantity.add(bcosListEntry.getAppointmentRequestedCsfFteQuantity());
335                        totalLevelAppointmentRequestedFteQuantity = totalLevelAppointmentRequestedFteQuantity.add(bcosListEntry.getAppointmentRequestedFteQuantity());
336                    }
337                }
338                bcObjectTotal.setBcos(simpleBcosEntry);
339                bcObjectTotal.setTotalLevelPositionCsfLeaveFteQuantity(totalLevelPositionCsfLeaveFteQuantity);
340                bcObjectTotal.setTotalLevelPositionCsfFullTimeEmploymentQuantity(totalLevelPositionCsfFullTimeEmploymentQuantity);
341                bcObjectTotal.setTotalLevelFinancialBeginningBalanceLineAmount(totalLevelFinancialBeginningBalanceLineAmount);
342                bcObjectTotal.setTotalLevelAppointmentRequestedCsfFteQuantity(totalLevelAppointmentRequestedCsfFteQuantity);
343                bcObjectTotal.setTotalLevelAppointmentRequestedFteQuantity(totalLevelAppointmentRequestedFteQuantity);
344                bcObjectTotal.setTotalLevelAccountLineAnnualBalanceAmount(totalLevelAccountLineAnnualBalanceAmount);
345                returnList.add(bcObjectTotal);
346    
347                totalLevelPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
348                totalLevelPositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
349                totalLevelFinancialBeginningBalanceLineAmount = new Integer(0);
350                totalLevelAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
351                totalLevelAppointmentRequestedFteQuantity = BigDecimal.ZERO;
352                totalLevelAccountLineAnnualBalanceAmount = new Integer(0);
353            }
354            return returnList;
355    
356        }
357    
358        protected List calculateConsTotal(List<BudgetConstructionObjectSummary> bcosList, List<BudgetConstructionObjectSummary> simpleList) {
359    
360            BigDecimal totalConsolidationPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
361            BigDecimal totalConsolidationPositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
362            Integer totalConsolidationFinancialBeginningBalanceLineAmount = new Integer(0);
363            BigDecimal totalConsolidationAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
364            BigDecimal totalConsolidationAppointmentRequestedFteQuantity = BigDecimal.ZERO;
365            Integer totalConsolidationAccountLineAnnualBalanceAmount = new Integer(0);
366    
367            List returnList = new ArrayList();
368            for (BudgetConstructionObjectSummary simpleBcosEntry : simpleList) {
369                BudgetConstructionOrgObjectSummaryReportTotal bcObjectTotal = new BudgetConstructionOrgObjectSummaryReportTotal();
370                for (BudgetConstructionObjectSummary bcosListEntry : bcosList) {
371                    if (BudgetConstructionReportHelper.isSameEntry(simpleBcosEntry, bcosListEntry, fieldsForCons())) {
372                        totalConsolidationFinancialBeginningBalanceLineAmount += new Integer(bcosListEntry.getFinancialBeginningBalanceLineAmount().intValue());
373                        totalConsolidationAccountLineAnnualBalanceAmount += new Integer(bcosListEntry.getAccountLineAnnualBalanceAmount().intValue());
374                        totalConsolidationPositionCsfLeaveFteQuantity = totalConsolidationPositionCsfLeaveFteQuantity.add(bcosListEntry.getPositionCsfLeaveFteQuantity());
375                        totalConsolidationPositionCsfFullTimeEmploymentQuantity = totalConsolidationPositionCsfFullTimeEmploymentQuantity.add(bcosListEntry.getCsfFullTimeEmploymentQuantity());
376                        totalConsolidationAppointmentRequestedCsfFteQuantity = totalConsolidationAppointmentRequestedCsfFteQuantity.add(bcosListEntry.getAppointmentRequestedCsfFteQuantity());
377                        totalConsolidationAppointmentRequestedFteQuantity = totalConsolidationAppointmentRequestedFteQuantity.add(bcosListEntry.getAppointmentRequestedFteQuantity());
378                    }
379                }
380                bcObjectTotal.setBcos(simpleBcosEntry);
381                bcObjectTotal.setTotalConsolidationPositionCsfLeaveFteQuantity(totalConsolidationPositionCsfLeaveFteQuantity);
382                bcObjectTotal.setTotalConsolidationPositionCsfFullTimeEmploymentQuantity(totalConsolidationPositionCsfFullTimeEmploymentQuantity);
383                bcObjectTotal.setTotalConsolidationFinancialBeginningBalanceLineAmount(totalConsolidationFinancialBeginningBalanceLineAmount);
384                bcObjectTotal.setTotalConsolidationAppointmentRequestedCsfFteQuantity(totalConsolidationAppointmentRequestedCsfFteQuantity);
385                bcObjectTotal.setTotalConsolidationAppointmentRequestedFteQuantity(totalConsolidationAppointmentRequestedFteQuantity);
386                bcObjectTotal.setTotalConsolidationAccountLineAnnualBalanceAmount(totalConsolidationAccountLineAnnualBalanceAmount);
387                returnList.add(bcObjectTotal);
388    
389                totalConsolidationPositionCsfLeaveFteQuantity = BigDecimal.ZERO;
390                totalConsolidationPositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
391                totalConsolidationFinancialBeginningBalanceLineAmount = new Integer(0);
392                totalConsolidationAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
393                totalConsolidationAppointmentRequestedFteQuantity = BigDecimal.ZERO;
394                totalConsolidationAccountLineAnnualBalanceAmount = new Integer(0);
395            }
396            return returnList;
397        }
398    
399        protected List calculateGexpAndTypeTotal(List<BudgetConstructionObjectSummary> bcosList, List<BudgetConstructionObjectSummary> simpleList) {
400    
401            Integer grossFinancialBeginningBalanceLineAmount = new Integer(0);
402            Integer grossAccountLineAnnualBalanceAmount = new Integer(0);
403    
404            BigDecimal typePositionCsfLeaveFteQuantity = BigDecimal.ZERO;
405            BigDecimal typePositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
406            Integer typeFinancialBeginningBalanceLineAmount = new Integer(0);
407            BigDecimal typeAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
408            BigDecimal typeAppointmentRequestedFteQuantity = BigDecimal.ZERO;
409            Integer typeAccountLineAnnualBalanceAmount = new Integer(0);
410    
411            List returnList = new ArrayList();
412            for (BudgetConstructionObjectSummary simpleBcosEntry : simpleList) {
413                BudgetConstructionOrgObjectSummaryReportTotal bcObjectTotal = new BudgetConstructionOrgObjectSummaryReportTotal();
414                for (BudgetConstructionObjectSummary bcosListEntry : bcosList) {
415                    if (BudgetConstructionReportHelper.isSameEntry(simpleBcosEntry, bcosListEntry, fieldsForGexpAndType())) {
416    
417                        typeFinancialBeginningBalanceLineAmount += new Integer(bcosListEntry.getFinancialBeginningBalanceLineAmount().intValue());
418                        typeAccountLineAnnualBalanceAmount += new Integer(bcosListEntry.getAccountLineAnnualBalanceAmount().intValue());
419                        typePositionCsfLeaveFteQuantity = typePositionCsfLeaveFteQuantity.add(bcosListEntry.getPositionCsfLeaveFteQuantity());
420                        typePositionCsfFullTimeEmploymentQuantity = typePositionCsfFullTimeEmploymentQuantity.add(bcosListEntry.getCsfFullTimeEmploymentQuantity());
421                        typeAppointmentRequestedCsfFteQuantity = typeAppointmentRequestedCsfFteQuantity.add(bcosListEntry.getAppointmentRequestedCsfFteQuantity());
422                        typeAppointmentRequestedFteQuantity = typeAppointmentRequestedFteQuantity.add(bcosListEntry.getAppointmentRequestedFteQuantity());
423    
424                        if (bcosListEntry.getIncomeExpenseCode().equals("B") && !bcosListEntry.getFinancialObjectLevelCode().equals("CORI") && !bcosListEntry.getFinancialObjectLevelCode().equals("TRIN")) {
425                            grossFinancialBeginningBalanceLineAmount += new Integer(bcosListEntry.getFinancialBeginningBalanceLineAmount().intValue());
426                            grossAccountLineAnnualBalanceAmount += new Integer(bcosListEntry.getAccountLineAnnualBalanceAmount().intValue());
427                        }
428                    }
429                }
430                bcObjectTotal.setBcos(simpleBcosEntry);
431    
432                bcObjectTotal.setGrossFinancialBeginningBalanceLineAmount(grossFinancialBeginningBalanceLineAmount);
433                bcObjectTotal.setGrossAccountLineAnnualBalanceAmount(grossAccountLineAnnualBalanceAmount);
434    
435                bcObjectTotal.setTypePositionCsfLeaveFteQuantity(typePositionCsfLeaveFteQuantity);
436                bcObjectTotal.setTypePositionCsfFullTimeEmploymentQuantity(typePositionCsfFullTimeEmploymentQuantity);
437                bcObjectTotal.setTypeFinancialBeginningBalanceLineAmount(typeFinancialBeginningBalanceLineAmount);
438                bcObjectTotal.setTypeAppointmentRequestedCsfFteQuantity(typeAppointmentRequestedCsfFteQuantity);
439                bcObjectTotal.setTypeAppointmentRequestedFteQuantity(typeAppointmentRequestedFteQuantity);
440                bcObjectTotal.setTypeAccountLineAnnualBalanceAmount(typeAccountLineAnnualBalanceAmount);
441    
442                returnList.add(bcObjectTotal);
443                grossFinancialBeginningBalanceLineAmount = new Integer(0);
444                grossAccountLineAnnualBalanceAmount = new Integer(0);
445    
446                typePositionCsfLeaveFteQuantity = BigDecimal.ZERO;
447                typePositionCsfFullTimeEmploymentQuantity = BigDecimal.ZERO;
448                typeFinancialBeginningBalanceLineAmount = new Integer(0);
449                typeAppointmentRequestedCsfFteQuantity = BigDecimal.ZERO;
450                typeAppointmentRequestedFteQuantity = BigDecimal.ZERO;
451                typeAccountLineAnnualBalanceAmount = new Integer(0);
452            }
453    
454            return returnList;
455        }
456    
457    
458        protected List calculateTotal(List<BudgetConstructionObjectSummary> bcosList, List<BudgetConstructionObjectSummary> simpleList) {
459    
460            Integer revenueFinancialBeginningBalanceLineAmount = new Integer(0);
461            Integer revenueAccountLineAnnualBalanceAmount = new Integer(0);
462    
463            Integer expenditureFinancialBeginningBalanceLineAmount = new Integer(0);
464            Integer expenditureAccountLineAnnualBalanceAmount = new Integer(0);
465    
466            Integer differenceFinancialBeginningBalanceLineAmount = new Integer(0);
467            Integer differenceAccountLineAnnualBalanceAmount = new Integer(0);
468    
469            List returnList = new ArrayList();
470    
471            for (BudgetConstructionObjectSummary simpleBcosEntry : simpleList) {
472                BudgetConstructionOrgObjectSummaryReportTotal bcObjectTotal = new BudgetConstructionOrgObjectSummaryReportTotal();
473                for (BudgetConstructionObjectSummary bcosListEntry : bcosList) {
474                    if (BudgetConstructionReportHelper.isSameEntry(simpleBcosEntry, bcosListEntry, fieldsForTotal())) {
475    
476                        if (bcosListEntry.getIncomeExpenseCode().equals("A")) {
477                            revenueFinancialBeginningBalanceLineAmount += new Integer(bcosListEntry.getFinancialBeginningBalanceLineAmount().intValue());
478                            revenueAccountLineAnnualBalanceAmount += new Integer(bcosListEntry.getAccountLineAnnualBalanceAmount().intValue());
479                        }
480                        else {
481                            expenditureFinancialBeginningBalanceLineAmount += new Integer(bcosListEntry.getFinancialBeginningBalanceLineAmount().intValue());
482                            expenditureAccountLineAnnualBalanceAmount += new Integer(bcosListEntry.getAccountLineAnnualBalanceAmount().intValue());
483                        }
484                    }
485                }
486    
487                bcObjectTotal.setBcos(simpleBcosEntry);
488    
489                bcObjectTotal.setRevenueFinancialBeginningBalanceLineAmount(revenueFinancialBeginningBalanceLineAmount);
490                bcObjectTotal.setRevenueAccountLineAnnualBalanceAmount(revenueAccountLineAnnualBalanceAmount);
491    
492                bcObjectTotal.setExpenditureFinancialBeginningBalanceLineAmount(expenditureFinancialBeginningBalanceLineAmount);
493                bcObjectTotal.setExpenditureAccountLineAnnualBalanceAmount(expenditureAccountLineAnnualBalanceAmount);
494    
495                differenceFinancialBeginningBalanceLineAmount = revenueFinancialBeginningBalanceLineAmount - expenditureFinancialBeginningBalanceLineAmount;
496                differenceAccountLineAnnualBalanceAmount = revenueAccountLineAnnualBalanceAmount - expenditureAccountLineAnnualBalanceAmount;
497                bcObjectTotal.setDifferenceFinancialBeginningBalanceLineAmount(differenceFinancialBeginningBalanceLineAmount);
498                bcObjectTotal.setDifferenceAccountLineAnnualBalanceAmount(differenceAccountLineAnnualBalanceAmount);
499    
500                returnList.add(bcObjectTotal);
501    
502                revenueFinancialBeginningBalanceLineAmount = new Integer(0);
503                revenueAccountLineAnnualBalanceAmount = new Integer(0);
504    
505                expenditureFinancialBeginningBalanceLineAmount = new Integer(0);
506                expenditureAccountLineAnnualBalanceAmount = new Integer(0);
507    
508                differenceFinancialBeginningBalanceLineAmount = new Integer(0);
509                differenceAccountLineAnnualBalanceAmount = new Integer(0);
510            }
511            return returnList;
512        }
513    
514    
515        protected List<String> fieldsForLevel() {
516            List<String> fieldList = new ArrayList();
517            fieldList.addAll(fieldsForCons());
518            fieldList.add(KFSPropertyConstants.FINANCIAL_LEVEL_SORT_CODE);
519            return fieldList;
520        }
521    
522        protected List<String> fieldsForCons() {
523            List<String> fieldList = new ArrayList();
524            fieldList.addAll(fieldsForGexpAndType());
525            fieldList.add(KFSPropertyConstants.FINANCIAL_CONSOLIDATION_SORT_CODE);
526            return fieldList;
527        }
528    
529    
530        protected List<String> fieldsForGexpAndType() {
531            List<String> fieldList = new ArrayList();
532            fieldList.addAll(fieldsForTotal());
533            fieldList.add(KFSPropertyConstants.INCOME_EXPENSE_CODE);
534            return fieldList;
535        }
536    
537    
538        protected List<String> fieldsForTotal() {
539            List<String> fieldList = new ArrayList();
540            fieldList.add(KFSPropertyConstants.ORGANIZATION_CHART_OF_ACCOUNTS_CODE);
541            fieldList.add(KFSPropertyConstants.ORGANIZATION_CODE);
542            fieldList.add(KFSPropertyConstants.SUB_FUND_GROUP_CODE);
543            fieldList.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
544            /*
545             * fieldList.add(KFSPropertyConstants.INCOME_EXPENSE_CODE);
546             * fieldList.add(KFSPropertyConstants.FINANCIAL_CONSOLIDATION_SORT_CODE);
547             * fieldList.add(KFSPropertyConstants.FINANCIAL_LEVEL_SORT_CODE); fieldList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
548             */
549            return fieldList;
550        }
551    
552        /**
553         * builds orderByList for sort order.
554         * 
555         * @return returnList
556         */
557        protected List<String> buildOrderByList() {
558            List<String> returnList = new ArrayList();
559            returnList.add(KFSPropertyConstants.ORGANIZATION_CHART_OF_ACCOUNTS_CODE);
560            returnList.add(KFSPropertyConstants.ORGANIZATION_CODE);
561            returnList.add(KFSPropertyConstants.SUB_FUND_GROUP_CODE);
562            returnList.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
563            returnList.add(KFSPropertyConstants.INCOME_EXPENSE_CODE);
564            returnList.add(KFSPropertyConstants.FINANCIAL_CONSOLIDATION_SORT_CODE);
565            returnList.add(KFSPropertyConstants.FINANCIAL_LEVEL_SORT_CODE);
566            returnList.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE);
567    
568            return returnList;
569        }
570    
571        public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) {
572            this.kualiConfigurationService = kualiConfigurationService;
573        }
574    
575        public void setBudgetConstructionReportsServiceHelper(BudgetConstructionReportsServiceHelper budgetConstructionReportsServiceHelper) {
576            this.budgetConstructionReportsServiceHelper = budgetConstructionReportsServiceHelper;
577        }
578    }