5 - reportname: the report name (per FS::report_batch)
8 <& /elements/header-popup.html, { title => $report_info->{name} } &>
9 <script type="text/javascript">
11 $().ready(function() {
12 var agent_info = <% encode_json(\%agent) %>;
14 $('#agentnum').on('change', function() {
15 var agentnum = this.value;
16 if ( agent_info[agentnum] ) {
17 $('#msgnum').prop('value', agent_info[agentnum]['msgnum']);
18 $('#beginning_text').prop('value', agent_info[agentnum]['beginning']);
19 $('#ending_text').prop('value', agent_info[agentnum]['ending']);
21 $('#msgnum').prop('value', '');
22 $('#beginning_text').prop('value', '');
23 $('#ending_text').prop('value', '');
27 $('#agentnum').trigger('change');
32 <FORM NAME="OneTrueForm" ACTION="process/send-report.html" METHOD="POST">
35 <input type="hidden" name="reportname" value="<% $cgi->param('reportname') |h %>">
37 <& /elements/tr-select-agent.html &>
39 <& /elements/tr-td-label.html, label => emt('Message template') &>
41 <& /elements/select-msg_template.html, field => 'msgnum' &>
45 <& /elements/tr-input-beginning_ending.html &>
47 <& /elements/progress-init.html,
49 [ qw( reportname msgnum agentnum beginning ending ) ],
50 $p.'misc/process/send-report.html',
51 { message => 'Reports sent',
52 url => $cgi->referer }
57 <INPUT TYPE="button" onclick="process()" VALUE="<% emt('Send reports') %>" />
62 border-collapse: collapse;
79 border-bottom: 1px solid #999999;
81 vertical-align: bottom;
85 % if ( @report_history ) {
88 <caption><% emt('Report history') %></caption>
92 <th colspan=2>Date range</th>
97 % foreach my $report (@report_history) {
98 % my $agent = ($report->agentnum ?
99 % $report->agent->agent : 'All agents');
100 <tr class="row<% $row % 2 %>">
101 <td><% $agent %></td>
102 <td><% time2str($date_format, $report->send_date) %></td>
103 <td><% time2str($date_format, $report->sdate) %></td>
104 <td><% time2str($date_format, $report->edate) %></td>
105 <td><% $report->access_user->username %></td>
113 <& /elements/footer.html &>
118 unless $FS::CurrentUser::CurrentUser->access_right('Send reports to customers');
120 $cgi->param('reportname') =~ /^(\w+)$/
121 or die "bad reportname";
123 my $report_info = $FS::report_batch::sendable_reports{$reportname}
124 or die "bad reportname";
126 my $date_format = FS::Conf->new->config('date_format') || '%x';
128 my @report_history = qsearch({
129 table => 'report_batch',
130 hashref => { reportname => $reportname },
131 order_by => ' ORDER BY send_date DESC',
134 # defaults per agent that could be selected for the report
137 foreach my $report ( @report_history ) {
138 my $agentnum = $report->agentnum;
139 next if $agent{$agentnum};
141 # estimate the width of the report period, in months
142 my $last_sdate = DateTime->from_epoch( epoch => $report->sdate );
143 my $last_edate = DateTime->from_epoch( epoch => $report->edate );
145 my $days = $last_sdate->delta_days( $last_edate )->delta_days;
146 my $months = sprintf('%.0f', $days / 6) / 5;
148 my $next_sdate = $last_edate->clone->add(days => 1);
149 my $next_edate = $next_sdate->clone;
150 if ( $months >= 1 ) { # then treat as an interval in months
151 $next_edate->add( months => sprintf('%.0f', $months) );
152 $next_edate->subtract(days => 1);
153 } else { # treat as a number of days
154 $next_edate->add( days => $days );
157 my $name = $agentnum ? FS::agent->by_key($agentnum)->agent : 'All agents';
158 $agent{$agentnum} = {
160 beginning => $next_sdate->strftime($date_format),
161 ending => $next_edate->strftime($date_format),
162 msgnum => $report->msgnum,