1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.bc.document.service.impl;
20
21 import java.math.BigDecimal;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.kuali.kfs.coa.businessobject.Chart;
29 import org.kuali.kfs.module.bc.BCKeyConstants;
30 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionObjectPick;
31 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionOrgSalaryStatisticsReport;
32 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionSalaryTotal;
33 import org.kuali.kfs.module.bc.document.dataaccess.BudgetConstructionSalaryStatisticsReportDao;
34 import org.kuali.kfs.module.bc.document.service.BudgetConstructionOrganizationReportsService;
35 import org.kuali.kfs.module.bc.document.service.BudgetConstructionReportsServiceHelper;
36 import org.kuali.kfs.module.bc.document.service.BudgetConstructionSalaryStatisticsReportService;
37 import org.kuali.kfs.module.bc.report.BudgetConstructionReportHelper;
38 import org.kuali.kfs.sys.KFSPropertyConstants;
39 import org.kuali.rice.core.api.config.property.ConfigurationService;
40 import org.kuali.rice.krad.service.BusinessObjectService;
41 import org.kuali.rice.krad.service.PersistenceService;
42 import org.springframework.transaction.annotation.Transactional;
43
44
45
46
47 @Transactional
48 public class BudgetConstructionSalaryStatisticsReportServiceImpl implements BudgetConstructionSalaryStatisticsReportService {
49
50 protected BudgetConstructionSalaryStatisticsReportDao budgetConstructionSalaryStatisticsReportDao;
51 protected BudgetConstructionOrganizationReportsService budgetConstructionOrganizationReportsService;
52 protected BudgetConstructionReportsServiceHelper budgetConstructionReportsServiceHelper;
53 protected ConfigurationService kualiConfigurationService;
54 protected BusinessObjectService businessObjectService;
55 protected PersistenceService persistenceServiceOjb;
56
57 public void updateSalaryStatisticsReport(String principalName, Integer universityFiscalYear) {
58 budgetConstructionSalaryStatisticsReportDao.updateReportsSalaryStatisticsTable(principalName, universityFiscalYear-1);
59 }
60
61 public Collection<BudgetConstructionOrgSalaryStatisticsReport> buildReports(Integer universityFiscalYear, String principalName) {
62 Collection<BudgetConstructionOrgSalaryStatisticsReport> reportSet = new ArrayList();
63
64
65
66 persistenceServiceOjb.clearCache();
67
68
69 Map<String, Object> searchCriteria = new HashMap<String, Object>();
70 searchCriteria.put(KFSPropertyConstants.KUALI_USER_PERSON_UNIVERSAL_IDENTIFIER, principalName);
71
72
73 List<String> orderList = buildOrderByList();
74 Collection<BudgetConstructionSalaryTotal> salaryStatisticsList = budgetConstructionOrganizationReportsService.getBySearchCriteriaOrderByList(BudgetConstructionSalaryTotal.class, searchCriteria, orderList);
75
76
77 searchCriteria.clear();
78 searchCriteria.put(KFSPropertyConstants.PERSON_UNIVERSAL_IDENTIFIER, principalName);
79 Collection<BudgetConstructionObjectPick> objectPickList = businessObjectService.findMatching(BudgetConstructionObjectPick.class, searchCriteria);
80
81 String objectCodes = budgetConstructionReportsServiceHelper.getSelectedObjectCodes(principalName);
82
83
84 for (BudgetConstructionSalaryTotal salaryStatisticsEntry : salaryStatisticsList) {
85 BudgetConstructionOrgSalaryStatisticsReport orgSalaryStatisticsReportEntry = new BudgetConstructionOrgSalaryStatisticsReport();
86 buildReportsHeader(universityFiscalYear, objectCodes, orgSalaryStatisticsReportEntry, salaryStatisticsEntry);
87 buildReportsBody(orgSalaryStatisticsReportEntry, salaryStatisticsEntry);
88 reportSet.add(orgSalaryStatisticsReportEntry);
89 }
90
91 return reportSet;
92 }
93
94
95
96
97
98
99
100 public void buildReportsHeader(Integer universityFiscalYear, String objectCodes, BudgetConstructionOrgSalaryStatisticsReport orgSalaryStatisticsReportEntry, BudgetConstructionSalaryTotal salaryTotalEntry) {
101
102
103 Integer prevFiscalyear = universityFiscalYear - 1;
104 orgSalaryStatisticsReportEntry.setFiscalYear(prevFiscalyear.toString() + "-" + universityFiscalYear.toString().substring(2, 4));
105
106 Map searchCriteria = new HashMap();
107 searchCriteria.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, salaryTotalEntry.getOrganizationChartOfAccountsCode());
108 Chart chart = (Chart) businessObjectService.findByPrimaryKey(Chart.class, searchCriteria);
109
110
111 String orgName = salaryTotalEntry.getOrganization().getOrganizationName();
112 orgSalaryStatisticsReportEntry.setOrganizationCode(salaryTotalEntry.getOrganizationCode());
113 if (orgName == null) {
114 orgSalaryStatisticsReportEntry.setOrganizationName(kualiConfigurationService.getPropertyValueAsString(BCKeyConstants.ERROR_REPORT_GETTING_ORGANIZATION_NAME));
115 }
116 else {
117 orgSalaryStatisticsReportEntry.setOrganizationName(orgName);
118 }
119
120 if (chart == null) {
121 orgSalaryStatisticsReportEntry.setChartOfAccountDescription(kualiConfigurationService.getPropertyValueAsString(BCKeyConstants.ERROR_REPORT_GETTING_CHART_DESCRIPTION));
122 orgSalaryStatisticsReportEntry.setChartOfAccountsCode(kualiConfigurationService.getPropertyValueAsString(BCKeyConstants.ERROR_REPORT_GETTING_CHART_DESCRIPTION));
123 }
124 else {
125 orgSalaryStatisticsReportEntry.setChartOfAccountsCode(chart.getChartOfAccountsCode());
126 orgSalaryStatisticsReportEntry.setChartOfAccountDescription(chart.getFinChartOfAccountDescription());
127 }
128 Integer prevPrevFiscalyear = prevFiscalyear - 1;
129 orgSalaryStatisticsReportEntry.setObjectCodes(objectCodes);
130
131
132 orgSalaryStatisticsReportEntry.setThreshold("");
133 }
134
135
136 public void buildReportsBody(BudgetConstructionOrgSalaryStatisticsReport orgSalaryStatisticsReportEntry, BudgetConstructionSalaryTotal salaryTotalEntry) {
137 orgSalaryStatisticsReportEntry.setInitialRequestedFteQuantity(salaryTotalEntry.getInitialRequestedFteQuantity());
138
139 orgSalaryStatisticsReportEntry.setTotalInitialRequestedAmount(BudgetConstructionReportHelper.convertKualiInteger(salaryTotalEntry.getInitialRequestedAmount()));
140
141 BigDecimal averageAmount = BudgetConstructionReportHelper.calculateDivide(salaryTotalEntry.getInitialRequestedAmount().bigDecimalValue(), salaryTotalEntry.getInitialRequestedFteQuantity());
142 orgSalaryStatisticsReportEntry.setTotalAverageAmount(BudgetConstructionReportHelper.setDecimalDigit(averageAmount, 0, false).intValue());
143
144 BigDecimal requestedFteQuantity = salaryTotalEntry.getAppointmentRequestedFteQuantity().setScale(5, BigDecimal.ROUND_HALF_UP);
145 orgSalaryStatisticsReportEntry.setAppointmentRequestedFteQuantity(requestedFteQuantity);
146
147 orgSalaryStatisticsReportEntry.setTotalCsfAmount(BudgetConstructionReportHelper.convertKualiInteger(salaryTotalEntry.getCsfAmount()));
148 orgSalaryStatisticsReportEntry.setTotalAppointmentRequestedAmount(BudgetConstructionReportHelper.convertKualiInteger(salaryTotalEntry.getAppointmentRequestedAmount()));
149
150 BigDecimal csfAmount = new BigDecimal(BudgetConstructionReportHelper.convertKualiInteger(salaryTotalEntry.getCsfAmount()));
151 BigDecimal averageCfsAmount = BudgetConstructionReportHelper.calculateDivide(csfAmount, salaryTotalEntry.getAppointmentRequestedFteQuantity());
152 orgSalaryStatisticsReportEntry.setAverageCsfAmount(BudgetConstructionReportHelper.setDecimalDigit(averageCfsAmount, 0, false));
153
154 BigDecimal appointmentRequestedAmount = new BigDecimal(BudgetConstructionReportHelper.convertKualiInteger(salaryTotalEntry.getAppointmentRequestedAmount()));
155 BigDecimal averageRequestedAmount = BudgetConstructionReportHelper.calculateDivide(appointmentRequestedAmount, requestedFteQuantity);
156 orgSalaryStatisticsReportEntry.setAverageAppointmentRequestedAmount(BudgetConstructionReportHelper.setDecimalDigit(averageRequestedAmount, 0, false));
157
158 BigDecimal averageChange = orgSalaryStatisticsReportEntry.getAverageAppointmentRequestedAmount().subtract(orgSalaryStatisticsReportEntry.getAverageCsfAmount());
159 orgSalaryStatisticsReportEntry.setAverageChange(averageChange);
160
161 BigDecimal percentChange = BudgetConstructionReportHelper.calculatePercent(orgSalaryStatisticsReportEntry.getAverageChange(), orgSalaryStatisticsReportEntry.getAverageCsfAmount());
162 orgSalaryStatisticsReportEntry.setPercentChange(percentChange);
163 }
164
165
166
167
168
169
170 public List<String> buildOrderByList() {
171 List<String> returnList = new ArrayList();
172 returnList.add(KFSPropertyConstants.ORGANIZATION_CHART_OF_ACCOUNTS_CODE);
173 returnList.add(KFSPropertyConstants.ORGANIZATION_CODE);
174 return returnList;
175 }
176
177
178 public void setBudgetConstructionSalaryStatisticsReportDao(BudgetConstructionSalaryStatisticsReportDao budgetConstructionSalaryStatisticsReportDao) {
179 this.budgetConstructionSalaryStatisticsReportDao = budgetConstructionSalaryStatisticsReportDao;
180 }
181
182 public void setBudgetConstructionOrganizationReportsService(BudgetConstructionOrganizationReportsService budgetConstructionOrganizationReportsService) {
183 this.budgetConstructionOrganizationReportsService = budgetConstructionOrganizationReportsService;
184 }
185
186
187 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
188 this.businessObjectService = businessObjectService;
189 }
190
191 public void setConfigurationService(ConfigurationService kualiConfigurationService) {
192 this.kualiConfigurationService = kualiConfigurationService;
193 }
194
195
196
197
198
199 public void setBudgetConstructionReportsServiceHelper(BudgetConstructionReportsServiceHelper budgetConstructionReportsServiceHelper) {
200 this.budgetConstructionReportsServiceHelper = budgetConstructionReportsServiceHelper;
201 }
202
203
204
205
206
207
208
209 public PersistenceService getPersistenceServiceOjb() {
210 return persistenceServiceOjb;
211 }
212
213
214
215
216
217
218 public void setPersistenceServiceOjb(PersistenceService persistenceServiceOjb) {
219 this.persistenceServiceOjb = persistenceServiceOjb;
220 }
221
222 }
223