<%doc> Parameters: - reportname: the report name (per FS::report_batch) <& /elements/header-popup.html, { title => $report_info->{name} } &>
<& /elements/tr-select-agent.html &> <& /elements/tr-td-label.html, label => emt('Message template') &> <& /elements/tr-input-beginning_ending.html &> <& /elements/progress-init.html, 'OneTrueForm', [ qw( reportname msgnum agentnum beginning ending ) ], $p.'misc/process/send-report.html', { message => 'Reports sent', url => $cgi->referer } &>
<& /elements/select-msg_template.html, field => 'msgnum' &>
% if ( @report_history ) {
% my $row = 0; % foreach my $report (@report_history) { % my $agent = ($report->agentnum ? % $report->agent->agent : 'All agents'); % $row++; % }
<% emt('Report history') %>
Agent Sent on Date range User
<% $agent %> <% time2str($date_format, $report->send_date) %> <% time2str($date_format, $report->sdate) %> <% time2str($date_format, $report->edate) %> <% $report->access_user->username %>
% } <& /elements/footer.html &> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Send reports to customers'); $cgi->param('reportname') =~ /^(\w+)$/ or die "bad reportname"; my $reportname = $1; my $report_info = $FS::report_batch::sendable_reports{$reportname} or die "bad reportname"; my $date_format = FS::Conf->new->config('date_format') || '%x'; my @report_history = qsearch({ table => 'report_batch', hashref => { reportname => $reportname }, order_by => ' ORDER BY send_date DESC', }); # defaults per agent that could be selected for the report my %agent; foreach my $report ( @report_history ) { my $agentnum = $report->agentnum; next if $agent{$agentnum}; # estimate the width of the report period, in months my $last_sdate = DateTime->from_epoch( epoch => $report->sdate ); my $last_edate = DateTime->from_epoch( epoch => $report->edate ); my $days = $last_sdate->delta_days( $last_edate )->delta_days; my $months = sprintf('%.0f', $days / 6) / 5; my $next_sdate = $last_edate->clone->add(days => 1); my $next_edate = $next_sdate->clone; if ( $months >= 1 ) { # then treat as an interval in months $next_edate->add( months => sprintf('%.0f', $months) ); $next_edate->subtract(days => 1); } else { # treat as a number of days $next_edate->add( days => $days ); } my $name = $agentnum ? FS::agent->by_key($agentnum)->agent : 'All agents'; $agent{$agentnum} = { name => $name, beginning => $next_sdate->strftime($date_format), ending => $next_edate->strftime($date_format), msgnum => $report->msgnum, }; }