1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.pdp.batch.service.impl;
20
21 import java.text.MessageFormat;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.List;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.kuali.kfs.pdp.PdpKeyConstants;
28 import org.kuali.kfs.pdp.batch.service.DailyReportService;
29 import org.kuali.kfs.pdp.businessobject.DailyReport;
30 import org.kuali.kfs.pdp.dataaccess.PaymentDetailDao;
31 import org.kuali.kfs.pdp.service.PaymentGroupService;
32 import org.kuali.kfs.sys.service.ReportWriterService;
33 import org.kuali.rice.core.api.config.property.ConfigurationService;
34 import org.kuali.rice.core.api.datetime.DateTimeService;
35 import org.springframework.transaction.annotation.Transactional;
36
37 @Transactional
38 public class DailyReportServiceImpl implements DailyReportService {
39 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DailyReportServiceImpl.class);
40
41 protected PaymentDetailDao paymentDetailDao;
42 protected DateTimeService dateTimeService;
43 protected PaymentGroupService paymentGroupService;
44 protected ConfigurationService kualiConfigurationService;
45 protected ReportWriterService dailyReportReportWriterService;
46
47 protected List<DailyReport> getData() {
48 LOG.debug("getData() started");
49
50 return paymentDetailDao.getDailyReportData(dateTimeService.getCurrentSqlDate());
51 }
52
53 @Override
54 public void runReport() {
55 LOG.debug("runReport() started");
56
57 Collection<DailyReport> data = getData();
58 Date today = dateTimeService.getCurrentDate();
59
60
61 dailyReportReportWriterService.writeSubTitle(dateTimeService.toDateTimeStringForFilename(today));
62 dailyReportReportWriterService.writeNewLines(1);
63 dailyReportReportWriterService.writeTableHeader(DailyReport.class);
64
65
66 DailyReport dailyReportSortTotal = new DailyReport();
67 DailyReport dailyReportTotal = new DailyReport();
68 dailyReportTotal.setSortOrder(this.kualiConfigurationService.getPropertyValueAsString(PdpKeyConstants.DAILY_REPORT_SERVICE_TOTAL_SUBTITLE));
69
70 final String DAILY_REPORT_SORT_TOTAL_PROPERTY_STRING = this.kualiConfigurationService.getPropertyValueAsString(PdpKeyConstants.DAILY_REPORT_SERVICE_TOTAL_FOR_SUBTITLE);
71
72
73 boolean first = true;
74 boolean firstSortTotal = true;
75
76 for (DailyReport dailyReport : data) {
77 if (!first
78 && this.paymentGroupService.getSortGroupId(dailyReportSortTotal.getPaymentGroup()) != this.paymentGroupService.getSortGroupId(dailyReport.getPaymentGroup())) {
79
80
81 firstSortTotal = true;
82
83
84 dailyReportReportWriterService.writeTableRow(dailyReportSortTotal);
85 dailyReportReportWriterService.writeNewLines(1);
86
87
88 dailyReportSortTotal = new DailyReport();
89 } else if (first) {
90 first = false;
91 }
92
93 if (firstSortTotal) {
94
95 dailyReport.setSortOrder(this.paymentGroupService.getSortGroupName(this.paymentGroupService.getSortGroupId(dailyReport.getPaymentGroup())));
96 firstSortTotal = false;
97 }
98
99
100 dailyReportReportWriterService.writeTableRow(dailyReport);
101
102
103 dailyReportSortTotal.addRow(dailyReport);
104 dailyReportTotal.addRow(dailyReport);
105
106
107 if (StringUtils.isEmpty(dailyReportSortTotal.getSortOrder())) {
108 String newTotalForSubtitle = MessageFormat.format(DAILY_REPORT_SORT_TOTAL_PROPERTY_STRING, new Object[] { this.paymentGroupService.getSortGroupName(this.paymentGroupService.getSortGroupId(dailyReportSortTotal.getPaymentGroup())) });
109 dailyReportSortTotal.setSortOrder(newTotalForSubtitle);
110 }
111 }
112
113
114 if (!first) {
115
116 dailyReportReportWriterService.writeTableRow(dailyReportSortTotal);
117 dailyReportReportWriterService.writeNewLines(1);
118 }
119
120
121 dailyReportReportWriterService.writeTableRowSeparationLine(dailyReportTotal);
122 dailyReportReportWriterService.writeTableRow(dailyReportTotal);
123 }
124
125 public void setDateTimeService(DateTimeService dts) {
126 dateTimeService = dts;
127 }
128
129 public void setPaymentDetailDao(PaymentDetailDao pdd) {
130 paymentDetailDao = pdd;
131 }
132
133
134
135
136 @Override
137 public void setPaymentGroupService(PaymentGroupService paymentGroupService) {
138 this.paymentGroupService = paymentGroupService;
139 }
140
141 public void setConfigurationService(ConfigurationService kualiConfigurationService) {
142 this.kualiConfigurationService = kualiConfigurationService;
143 }
144
145 public ReportWriterService getDailyReportReportWriterService() {
146 return dailyReportReportWriterService;
147 }
148
149 public void setDailyReportReportWriterService(ReportWriterService dailyReportReportWriterService) {
150 this.dailyReportReportWriterService = dailyReportReportWriterService;
151 }
152 }