1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.batch;
17
18 import java.io.File;
19 import java.text.SimpleDateFormat;
20 import java.util.ArrayList;
21 import java.util.Date;
22 import java.util.List;
23
24 import org.apache.commons.io.filefilter.RegexFileFilter;
25 import org.kuali.ole.gl.GeneralLedgerConstants;
26 import org.kuali.ole.gl.batch.service.impl.OriginEntryFileIterator;
27 import org.kuali.ole.gl.businessobject.GlSummary;
28 import org.kuali.ole.gl.businessobject.OriginEntryInformation;
29 import org.kuali.ole.gl.businessobject.Reversal;
30 import org.kuali.ole.gl.report.PosterOutputSummaryReport;
31 import org.kuali.ole.gl.service.BalanceService;
32 import org.kuali.ole.gl.service.ReversalService;
33 import org.kuali.ole.sys.FileUtil;
34 import org.kuali.ole.sys.batch.AbstractWrappedBatchStep;
35 import org.kuali.ole.sys.batch.service.WrappedBatchExecutorService.CustomBatchExecutor;
36 import org.kuali.ole.sys.batch.service.WrappingBatchService;
37 import org.kuali.ole.sys.businessobject.SystemOptions;
38 import org.kuali.ole.sys.service.FiscalYearAwareReportWriterService;
39 import org.kuali.ole.sys.service.OptionsService;
40 import org.kuali.ole.sys.service.ReportWriterService;
41
42
43
44
45 public class PosterSummaryReportStep extends AbstractWrappedBatchStep {
46 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PosterSummaryReportStep.class);
47 private static final String DATE_FORMAT = "MMdd";
48 private static final String BUD = "bud";
49 private static final String ACT = "act";
50 private static final String ENC = "enc";
51 private OptionsService optionsService;
52 private ReportWriterService posterOutputSummaryReportWriterService;
53 private FiscalYearAwareReportWriterService posterActualBalanceSummaryReportWriterService;
54 private FiscalYearAwareReportWriterService posterBudgetBalanceSummaryReportWriterService;
55 private FiscalYearAwareReportWriterService posterEncumbranceSummaryReportWriterService;
56 private ReversalService reversalService;
57 private BalanceService balanceService;
58 private String batchFileDirectoryName;
59
60
61
62
63 @Override
64 protected CustomBatchExecutor getCustomBatchExecutor() {
65 return new CustomBatchExecutor() {
66
67
68
69
70
71
72 public boolean execute() {
73 synchronized(this) {
74 final String CURRENT_YEAR_LOWER = getCurrentYearLowerParameter();
75 final String CURRENT_YEAR_UPPER = getCurrentYearUpperParameter();
76 final String CURRENT_AND_LAST_YEAR = getCurrentAndLastYearParameter();
77
78 SystemOptions currentYear = optionsService.getCurrentYearOptions();
79 SystemOptions nextYear = optionsService.getOptions(currentYear.getUniversityFiscalYear() + 1);
80 SystemOptions previousYear = optionsService.getOptions(currentYear.getUniversityFiscalYear() - 1);
81
82 Date runDate = getDateTimeService().getCurrentDate();
83 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
84 String md = sdf.format(runDate);
85 generatePosterOutputReport(runDate);
86 if ((md.compareTo(CURRENT_YEAR_UPPER) > 0) || (md.compareTo(CURRENT_YEAR_LOWER) < 0)) {
87
88 generateGlSummary(runDate, currentYear, BUD);
89 generateGlSummary(runDate, currentYear, ACT);
90 generateGlSummary(runDate, currentYear, ENC);
91 }
92 else if ((md.compareTo(CURRENT_AND_LAST_YEAR) > 0)) {
93
94 generateGlSummary(runDate, currentYear, BUD);
95 generateGlSummary(runDate, previousYear, BUD);
96 generateGlSummary(runDate, currentYear, ACT);
97 generateGlSummary(runDate, previousYear, ACT);
98 generateGlSummary(runDate, currentYear, ENC);
99 generateGlSummary(runDate, previousYear, ENC);
100 }
101 else {
102
103 generateGlSummary(runDate, currentYear, BUD);
104 generateGlSummary(runDate, nextYear, BUD);
105 generateGlSummary(runDate, currentYear, ACT);
106 generateGlSummary(runDate, nextYear, ACT);
107 generateGlSummary(runDate, currentYear, ENC);
108 generateGlSummary(runDate, nextYear, ENC);
109 }
110 }
111 return true;
112 }
113 };
114 }
115
116
117
118
119
120
121 private void generatePosterOutputReport(Date runDate) {
122 PosterOutputSummaryReport posterOutputSummaryReport = new PosterOutputSummaryReport();
123
124
125 File mainPosterFile = FileUtil.getNewestFile(new File(batchFileDirectoryName), new RegexFileFilter((GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE + "\\.[0-9_\\-]+\\" + GeneralLedgerConstants.BatchFileSystem.EXTENSION)));
126 if (mainPosterFile != null && mainPosterFile.exists()) {
127 OriginEntryFileIterator mainPosterIterator = new OriginEntryFileIterator(mainPosterFile);
128 while (mainPosterIterator.hasNext()) {
129 final OriginEntryInformation originEntry = mainPosterIterator.next();
130 posterOutputSummaryReport.summarize(originEntry);
131 }
132 } else {
133 LOG.warn("Could not Main Poster Input file with prefix "+GeneralLedgerConstants.BatchFileSystem.POSTER_INPUT_FILE+" for tabulation in the Poster Output Summary Report");
134 }
135
136
137 File reversalPosterFile = FileUtil.getNewestFile(new File(batchFileDirectoryName), new RegexFileFilter((GeneralLedgerConstants.BatchFileSystem.REVERSAL_POSTER_VALID_OUTPUT_FILE + "\\.[0-9_\\-]+\\" + GeneralLedgerConstants.BatchFileSystem.EXTENSION)));
138 if (reversalPosterFile != null && reversalPosterFile.exists()) {
139 OriginEntryFileIterator reversalOriginEntryIterator = new OriginEntryFileIterator(reversalPosterFile);
140 while (reversalOriginEntryIterator.hasNext()) {
141 final Reversal reversal = new Reversal (reversalOriginEntryIterator.next());
142 posterOutputSummaryReport.summarize(reversal);
143 }
144 } else {
145 LOG.warn("Could not Reversal Output file with prefix "+GeneralLedgerConstants.BatchFileSystem.REVERSAL_POSTER_VALID_OUTPUT_FILE+" for tabulation in the Poster Output Summary Report");
146 }
147
148
149 File icrPosterFile = FileUtil.getNewestFile(new File(batchFileDirectoryName), new RegexFileFilter(GeneralLedgerConstants.BatchFileSystem.ICR_POSTER_INPUT_FILE + "\\.[0-9_\\-]+\\" + GeneralLedgerConstants.BatchFileSystem.EXTENSION));
150 if (icrPosterFile != null && icrPosterFile.exists()) {
151 OriginEntryFileIterator icrIterator = new OriginEntryFileIterator(icrPosterFile);
152 while (icrIterator.hasNext()) {
153 final OriginEntryInformation originEntry = icrIterator.next();
154 posterOutputSummaryReport.summarize(originEntry);
155 }
156 } else {
157 LOG.warn("Could not Indirect Cost Recovery Poster Input file with prefix "+GeneralLedgerConstants.BatchFileSystem.ICR_POSTER_INPUT_FILE+" for tabulation in the Poster Output Summary Report");
158 }
159
160 posterOutputSummaryReport.writeReport(posterOutputSummaryReportWriterService);
161 }
162
163
164
165
166
167
168
169
170 protected void generateGlSummary(Date runDate, SystemOptions year, String reportType) {
171 LOG.debug("generateGlSummary() started");
172
173 FiscalYearAwareReportWriterService fiscalYearAwareReportWriterService;
174
175 List<String> balanceTypeCodes = new ArrayList<String>();
176 if (ACT.equals(reportType)) {
177 fiscalYearAwareReportWriterService = posterActualBalanceSummaryReportWriterService;
178 balanceTypeCodes.add(year.getActualFinancialBalanceTypeCd());
179 }
180 else if (BUD.equals(reportType)) {
181 fiscalYearAwareReportWriterService = posterBudgetBalanceSummaryReportWriterService;
182 balanceTypeCodes.add(year.getBudgetCheckingBalanceTypeCd());
183 balanceTypeCodes.add(year.getBaseBudgetFinancialBalanceTypeCd());
184 balanceTypeCodes.add(year.getMonthlyBudgetFinancialBalanceTypeCd());
185 } else {
186 fiscalYearAwareReportWriterService = posterEncumbranceSummaryReportWriterService;
187 balanceTypeCodes.add(year.getExtrnlEncumFinBalanceTypCd());
188 balanceTypeCodes.add(year.getIntrnlEncumFinBalanceTypCd());
189 balanceTypeCodes.add(year.getPreencumbranceFinBalTypeCd());
190 balanceTypeCodes.add(year.getCostShareEncumbranceBalanceTypeCd());
191 }
192
193 List<GlSummary> balances = balanceService.getGlSummary(year.getUniversityFiscalYear(), balanceTypeCodes);
194
195 GlSummary totals = new GlSummary();
196 for(GlSummary balance : balances) {
197 totals.add(balance);
198 }
199 totals.setFundGroup("Total");
200
201 try {
202 fiscalYearAwareReportWriterService.setFiscalYear(year.getUniversityFiscalYear());
203 ((WrappingBatchService) fiscalYearAwareReportWriterService).initialize();
204
205 fiscalYearAwareReportWriterService.writeSubTitle("Balance Type of " + balanceTypeCodes + " for Fiscal Year " + year.getUniversityFiscalYearName());
206 fiscalYearAwareReportWriterService.writeNewLines(1);
207
208 fiscalYearAwareReportWriterService.writeTableRowSeparationLine(totals);
209 fiscalYearAwareReportWriterService.writeTable(balances, true, false);
210
211 fiscalYearAwareReportWriterService.writeTableRowSeparationLine(totals);
212 fiscalYearAwareReportWriterService.writeTableRow(totals);
213 } finally {
214 ((WrappingBatchService) fiscalYearAwareReportWriterService).destroy();
215 }
216 }
217
218
219
220
221 public String getCurrentYearLowerParameter() {
222 return getParameterService().getParameterValueAsString(getClass(), GeneralLedgerConstants.GlSummaryReport.CURRENT_YEAR_LOWER);
223 }
224
225
226
227
228 public String getCurrentYearUpperParameter() {
229 return getParameterService().getParameterValueAsString(PosterSummaryReportStep.this.getClass(), GeneralLedgerConstants.GlSummaryReport.CURRENT_YEAR_UPPER);
230 }
231
232
233
234
235 public String getCurrentAndLastYearParameter() {
236 return getParameterService().getParameterValueAsString(PosterSummaryReportStep.this.getClass(), GeneralLedgerConstants.GlSummaryReport.CURRENT_AND_LAST_YEAR);
237 }
238
239
240
241
242
243
244
245 public void setOptionsService(OptionsService os) {
246 optionsService = os;
247 }
248
249
250
251
252
253 public ReportWriterService getPosterOutputSummaryReportWriterService() {
254 return posterOutputSummaryReportWriterService;
255 }
256
257
258
259
260
261 public void setPosterOutputSummaryReportWriterService(ReportWriterService posterOutputSummaryReportWriterService) {
262 this.posterOutputSummaryReportWriterService = posterOutputSummaryReportWriterService;
263 }
264
265
266
267
268
269 public void setPosterActualBalanceSummaryReportWriterService(FiscalYearAwareReportWriterService posterActualBalanceSummaryReportWriterService) {
270 this.posterActualBalanceSummaryReportWriterService = posterActualBalanceSummaryReportWriterService;
271 }
272
273
274
275
276
277 public void setPosterBudgetBalanceSummaryReportWriterService(FiscalYearAwareReportWriterService posterBudgetBalanceSummaryReportWriterService) {
278 this.posterBudgetBalanceSummaryReportWriterService = posterBudgetBalanceSummaryReportWriterService;
279 }
280
281
282
283
284
285 public void setPosterEncumbranceSummaryReportWriterService(FiscalYearAwareReportWriterService posterEncumbranceSummaryReportWriterService) {
286 this.posterEncumbranceSummaryReportWriterService = posterEncumbranceSummaryReportWriterService;
287 }
288
289
290
291
292
293 public ReversalService getReversalService() {
294 return reversalService;
295 }
296
297
298
299
300
301 public void setReversalService(ReversalService reversalService) {
302 this.reversalService = reversalService;
303 }
304
305
306
307
308
309 public void setBalanceService(BalanceService balanceService) {
310 this.balanceService = balanceService;
311 }
312
313
314
315
316
317 public String getBatchFileDirectoryName() {
318 return batchFileDirectoryName;
319 }
320
321
322
323
324
325 public void setBatchFileDirectoryName(String batchFileDirectoryName) {
326 this.batchFileDirectoryName = batchFileDirectoryName;
327 }
328 }