1 package FS::Report::Queued::FutureAutobill;
8 use FS::cust_main::Location;
12 use FS::Mason qw(mason_interps);
13 use FS::Record qw( qsearch );
15 use FS::UID qw( dbh );
20 use HTML::Entities qw( encode_entities );
24 FS::Report::Queued::FutureAutobill - Future Auto-Bill Transactions Report
28 Future Autobill report generated within the job queue.
30 Report results are saved to temp storage as a Mason fragment
31 that is rendered by the queued report viewer.
33 For every customer with a valid auto-bill payment method,
34 report runs bill_and_collect() for each day, from today through
35 the report target date. After recording the results, all
36 operations are rolled back.
38 This report relies on the ability to safely run bill_and_collect(),
39 with all exports and messaging disabled, and then to roll back the
44 C<agentnum>, C<target_date>
54 my $time_begin = time();
56 my $report_fh = File::Temp->new(
57 TEMPLATE => 'report.future_autobill.XXXXXXXX',
58 DIR => sprintf( '%s/cache.%s', $FS::Conf::base_dir, $FS::UID::datasrc ),
60 ) or die "Cannot create report file: $!";
64 warn Dumper( $param );
66 warn $report_fh->filename;
69 my $curuser = FS::CurrentUser->load_user( $param->{CurrentUser} )
70 or die 'Unable to set report user';
72 my ( $fs_interp ) = FS::Mason::mason_interps(
76 $fs_interp->error_mode('fatal');
77 $fs_interp->error_format('text');
79 $FS::Mason::Request::QUERY_STRING = sprintf(
80 'target_date=%s&agentnum=%s',
81 encode_entities( $param->{target_date} ),
82 encode_entities( $param->{agentnum} || '' ),
84 $FS::Mason::Request::FSURL = $param->{RootURL};
86 my $mason_request = $fs_interp->make_request(
87 comp => '/search/future_autobill.html'
92 eval{ $mason_request->exec() };
94 my $error = ref $@ eq 'HTML::Mason::Exception' ? $@->error : $@;
96 my $log = FS::Log->new('FS::Report::Queued::FutureAutobill');
98 "Error generating report: $FS::Mason::Request::QUERY_STRING $error"
105 if ( $report_fh->filename =~ /report\.(future_autobill.+)$/ ) {
108 die 'Error parsing report filename '.$report_fh->filename;
111 my $report_title = FS::cust_payby->future_autobill_report_title();
112 my $time_rendered = time() - $time_begin;
115 warn "Generated content:\n";
121 print $report_fh qq{<% include("/elements/header.html", '$report_title') %>\n};
122 print $report_fh $outbuf;
123 print $report_fh qq{<!-- Time to render report $time_rendered seconds -->};
124 print $report_fh qq{<% include("/elements/footer.html") %>\n};
127 "<a href=%s/misc/queued_report.html?report=%s>view</a>\n",