5 - reportname: the report name (per FS::report_batch)
8 <& /elements/header-popup.html, { title => $report_info->{name} } &>
9 <script src="<% $fsurl %>elements/jquery.js"></script>
10 <script type="text/javascript">
12 $().ready(function() {
13 var agent_info = <% encode_json(\%agent) %>;
15 $('#agentnum').on('change', function() {
16 var agentnum = this.value;
17 if ( agent_info[agentnum] ) {
18 $('#msgnum').prop('value', agent_info[agentnum]['msgnum']);
19 $('#beginning_text').prop('value', agent_info[agentnum]['beginning']);
20 $('#ending_text').prop('value', agent_info[agentnum]['ending']);
22 $('#msgnum').prop('value', '');
23 $('#beginning_text').prop('value', '');
24 $('#ending_text').prop('value', '');
28 $('#agentnum').trigger('change');
33 <FORM NAME="OneTrueForm" ACTION="process/send-report.html" METHOD="POST">
36 <input type="hidden" name="reportname" value="<% $cgi->param('reportname') |h %>">
38 <& /elements/tr-select-agent.html &>
40 <& /elements/tr-td-label.html, label => emt('Message template') &>
42 <& /elements/select-msg_template.html, field => 'msgnum' &>
46 <& /elements/tr-input-beginning_ending.html &>
48 <& /elements/progress-init.html,
50 [ qw( reportname msgnum agentnum beginning ending ) ],
51 $p.'misc/process/send-report.html',
52 { message => 'Reports sent',
53 url => $cgi->referer }
58 <INPUT TYPE="button" onclick="process()" VALUE="<% emt('Send reports') %>" />
63 border-collapse: collapse;
80 border-bottom: 1px solid #999999;
82 vertical-align: bottom;
86 % if ( @report_history ) {
89 <caption><% emt('Report history') %></caption>
93 <th colspan=2>Date range</th>
98 % foreach my $report (@report_history) {
99 % my $agent = ($report->agentnum ?
100 % $report->agent->agent : 'All agents');
101 <tr class="row<% $row % 2 %>">
102 <td><% $agent %></td>
103 <td><% time2str($date_format, $report->send_date) %></td>
104 <td><% time2str($date_format, $report->sdate) %></td>
105 <td><% time2str($date_format, $report->edate) %></td>
106 <td><% $report->access_user->username %></td>
114 <& /elements/footer.html &>
119 unless $FS::CurrentUser::CurrentUser->access_right('Send reports to customers');
121 $cgi->param('reportname') =~ /^(\w+)$/
122 or die "bad reportname";
124 my $report_info = $FS::report_batch::sendable_reports{$reportname}
125 or die "bad reportname";
127 my $date_format = FS::Conf->new->config('date_format') || '%x';
129 my @report_history = qsearch({
130 table => 'report_batch',
131 hashref => { reportname => $reportname },
132 order_by => ' ORDER BY send_date DESC',
135 # defaults per agent that could be selected for the report
138 foreach my $report ( @report_history ) {
139 my $agentnum = $report->agentnum;
140 next if $agent{$agentnum};
142 # estimate the width of the report period, in months
143 my $last_sdate = DateTime->from_epoch( epoch => $report->sdate );
144 my $last_edate = DateTime->from_epoch( epoch => $report->edate );
146 my $days = $last_sdate->delta_days( $last_edate )->delta_days;
147 my $months = sprintf('%.0f', $days / 6) / 5;
149 my $next_sdate = $last_edate->clone->add(days => 1);
150 my $next_edate = $next_sdate->clone;
151 if ( $months >= 1 ) { # then treat as an interval in months
152 $next_edate->add( months => sprintf('%.0f', $months) );
153 $next_edate->subtract(days => 1);
154 } else { # treat as a number of days
155 $next_edate->add( days => $days );
158 my $name = $agentnum ? FS::agent->by_key($agentnum)->agent : 'All agents';
159 $agent{$agentnum} = {
161 beginning => $next_sdate->strftime($date_format),
162 ending => $next_edate->strftime($date_format),
163 msgnum => $report->msgnum,