From 9ea31f98372bc897fd0b4d7e63284eecabf27aa2 Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Mon, 17 Sep 2018 21:30:15 -0400 Subject: RT# 78547 Future autobill report - report runs in job queue --- httemplate/search/elements/grid-report.html | 14 ++++- httemplate/search/future_autobill.html | 47 +++++++++++++++-- .../search/report_future_autobill-queued_job.html | 11 ++++ httemplate/search/report_future_autobill.html | 60 ++++++++++++++-------- 4 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 httemplate/search/report_future_autobill-queued_job.html (limited to 'httemplate') diff --git a/httemplate/search/elements/grid-report.html b/httemplate/search/elements/grid-report.html index b1e543012..efc009725 100644 --- a/httemplate/search/elements/grid-report.html +++ b/httemplate/search/elements/grid-report.html @@ -141,13 +141,17 @@ Usage: $m->print($output); % } else { +% unless ( $suppress_header ) { <& /elements/header.html, $title &> +% } <% $head %> % my $myself = $cgi->self_url; +% unless ( $suppress_header ) {

Download full reports
as ">Excel spreadsheet

+% } ', + suppress_header => $job ? 1 : 0, + suppress_footer => $job ? 1 : 0, &> <%init> + use DateTime; + use FS::Misc::Savepoint; + use FS::Report::Queued::FutureAutobill; use FS::UID qw( dbh ); die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Financial reports'); + my $job = $FS::Report::Queued::FutureAutobill::job; + + $job->update_statustext('0,Finding customers') if $job; + my $DEBUG = $cgi->param('DEBUG') || 0; - my $report_title = FS::cust_payby->future_autobill_report_title; my $agentnum = $cgi->param('agentnum') if $cgi->param('agentnum') =~ /^\d+/; @@ -60,16 +73,20 @@ results. # Get target date from form if ($cgi->param('target_date')) { + # DateTime::Format::DateParse would be better my ($mm, $dd, $yy) = split /[\-\/]/,$cgi->param('target_date'); + ( $yy, $mm, $dd ) = ( $mm, $dd, $yy ) if $mm > 1900; + $target_dt = DateTime->new( month => $mm, day => $dd, year => $yy, %noon, - ) if $mm && $dd & $yy; + ) if $mm && $dd && $yy; # Catch a date from the past: time only travels in one direction - $target_dt = undef if $target_dt->epoch < $now_dt->epoch; + $target_dt = undef + unless $target_dt && $now_dt && $now_dt <= $target_dt; } # without a target date, default to tomorrow @@ -77,6 +94,13 @@ results. $target_dt = $now_dt->clone->add( days => 1 ); } + my $report_title = FS::cust_payby->future_autobill_report_title; + my $report_subtitle = sprintf( + '(%s through %s)', + $now_dt->mdy('/'), + $target_dt->mdy('/'), + ); + # Create a range of dates from today until the given report date # (leaving the probably useless 'quick-report' mode, but disabled) if ( 1 || $cgi->param('multiple_billing_dates')) { @@ -104,6 +128,9 @@ results. . ($agentnum ? "AND cust_main.agentnum = $agentnum" : ''), }); + my $completion_target = scalar(keys %cust_payby) * scalar( @target_dates ); + my $completion_progress = 0; + my $fakebill_time = time(); my %abreport; my @rows; @@ -125,6 +152,9 @@ results. local $FS::cust_main::Billing_Realtime::BOP_TESTING = 1; local $FS::cust_main::Billing_Realtime::BOP_TESTING_SUCCESS = 1; + my $savepoint_label = 'future_autobill'; + savepoint_create( $savepoint_label ); + warn sprintf "Report involves %s customers", scalar keys %cust_payby if $DEBUG; @@ -153,8 +183,18 @@ results. ); warn "!!! $error (simulating future billing)\n" if $error; + + my $statustext = sprintf( + '%s,Simulating upcoming invoices and payments', + int( ( ++$completion_progress / $completion_target ) * 100 ) + ); + $job->update_statustext( $statustext ) if $job; + warn "[ $completion_progress / $completion_target ] $statustext\n" + if $DEBUG; + } + # Generate report rows from recorded payments in cust_pay for my $cust_pay ( qsearch( cust_pay => { @@ -206,6 +246,7 @@ results. # locked at a time warn "-- custnum $custnum -- rollback()\n" if $DEBUG; + savepoint_rollback( $savepoint_label ); dbh->rollback if $oldAutoCommit; } # /foreach $custnum diff --git a/httemplate/search/report_future_autobill-queued_job.html b/httemplate/search/report_future_autobill-queued_job.html new file mode 100644 index 000000000..d23efb5b1 --- /dev/null +++ b/httemplate/search/report_future_autobill-queued_job.html @@ -0,0 +1,11 @@ +<% $server->process %> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Financial reports'); + +my $server = new FS::UI::Web::JSRPC + 'FS::Report::Queued::FutureAutobill::make_report', + $cgi; + + diff --git a/httemplate/search/report_future_autobill.html b/httemplate/search/report_future_autobill.html index ccde299e9..28f589ee7 100644 --- a/httemplate/search/report_future_autobill.html +++ b/httemplate/search/report_future_autobill.html @@ -1,6 +1,9 @@ <%doc> -Display date selector for the future_autobill.html report +Display pre-report page for the Future Auto Bill Transactions report + +Report runs in the queue. Once the report is generated, user is +redirected to the report results. <% include('/elements/header.html', $report_title ) %> @@ -14,30 +17,43 @@ Display date selector for the future_autobill.html report % } else { -
- - <& /elements/tr-input-date-field.html, - { - name => 'target_date', - value => $target_date, - label => emt('Target billing date').': ', - required => 1 - } - &> - - <% include('/elements/tr-select-agent.html', - 'label' => 'For agent: ', - 'disable_empty' => 0, + +
+ <& /elements/tr-input-date-field.html, + { + name => 'target_date', + value => $target_date, + label => emt('Target billing date').': ', + required => 1 + } + &> + + <% include('/elements/tr-select-agent.html', + 'label' => 'For agent: ', + 'disable_empty' => 0, + ) + %> +
+
+ + +
+ + <% include( '/elements/progress-init.html', + 'future_autobill', + [ qw( agentnum target_date ) ], + 'report_future_autobill-queued_job.html', ) %> - - -
- - - - + % } -- cgit v1.2.1