From: mark Date: Wed, 16 Jun 2010 02:19:13 +0000 (+0000) Subject: RT#5683: payment batch upload uses job queue and progressbar X-Git-Tag: root_of_svc_elec_features~164 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=e37126c4d8a3eea4d27c855733a77cba026565c4 RT#5683: payment batch upload uses job queue and progressbar --- diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm index 6a2755494..d73c05293 100644 --- a/FS/FS/pay_batch.pm +++ b/FS/FS/pay_batch.pm @@ -195,6 +195,9 @@ sub import_results { my $info = $import_info{$format} or die "unknown format $format"; + my $job = $param->{'job'}; + $job->update_statustext(0) if $job; + my $filetype = $info->{'filetype'}; # CSV or fixed my @fields = @{ $info->{'fields'}}; my $formatre = $info->{'formatre'}; # for fixed @@ -286,7 +289,12 @@ sub import_results { } } + my $num = 0; foreach (@all_values) { + if($job) { + $num++; + $job->update_statustext(int(100 * $num/scalar(@all_values))); + } my @values = @$_; my %hash; @@ -404,6 +412,29 @@ sub import_results { } +use MIME::Base64; +use Storable 'thaw'; +use Data::Dumper; +sub process_import_results { + my $job = shift; + my $param = thaw(decode_base64(shift)); + $param->{'job'} = $job; + warn Dumper($param) if $DEBUG; + my $batchnum = delete $param->{'batchnum'} or die "no batchnum specified\n"; + my $batch = FS::pay_batch->by_key($batchnum) or die "batchnum '$batchnum' not found\n"; + + my $file = $param->{'uploaded_files'} or die "no files provided\n"; + $file =~ s/^(\w+):([\.\w]+)$/$2/; + my $dir = '%%%FREESIDE_CACHE%%%/cache.' . $FS::UID::datasrc; + open( $param->{'filehandle'}, + '<', + "$dir/$file" ) + or die "unable to open '$file'.\n"; + my $error = $batch->import_results($param); + unlink $file; + die $error if $error; +} + # Formerly httemplate/misc/download-batch.cgi sub export_batch { my $self = shift; diff --git a/httemplate/elements/file-upload.html b/httemplate/elements/file-upload.html index 7e2eeefcd..034eaec38 100644 --- a/httemplate/elements/file-upload.html +++ b/httemplate/elements/file-upload.html @@ -54,10 +54,15 @@ % foreach (@field) { +% if($param{'no_table'}) { + <% shift @label %> +% } +% else { <% shift @label %> +% } % }
diff --git a/httemplate/misc/upload-batch.cgi b/httemplate/misc/upload-batch.cgi index d1a84fd02..be80b1ff7 100644 --- a/httemplate/misc/upload-batch.cgi +++ b/httemplate/misc/upload-batch.cgi @@ -1,36 +1,10 @@ -% if ( $error ) { -% errorpage($error); -% } else { - <% include('/elements/header.html','Batch results upload successful') %> - <% include('/elements/footer.html') %> -% } +<% $server->process %> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Process batches'); -my $error; - -my $fh = $cgi->upload('batch_results'); -$error = 'No file uploaded' unless defined($fh); - -unless ( $error ) { - - $cgi->param('batchnum') =~ /^(\d+)$/; - my $batchnum = $1; - - my $pay_batch = qsearchs( 'pay_batch', { 'batchnum' => $batchnum } ); - if ( ! $pay_batch ) { - $error = "batchnum $batchnum not found"; - } elsif ( $pay_batch->status ne 'I' ) { - $error = "batch $batchnum is not in transit"; - } else { - $error = $pay_batch->import_results( - 'filehandle' => $fh, - 'format' => $cgi->param('format'), - ); - } - -} +my $server = + new FS::UI::Web::JSRPC 'FS::pay_batch::process_import_results', $cgi; diff --git a/httemplate/search/cust_pay_batch.cgi b/httemplate/search/cust_pay_batch.cgi index 7376e9dcb..825d21c8a 100755 --- a/httemplate/search/cust_pay_batch.cgi +++ b/httemplate/search/cust_pay_batch.cgi @@ -124,7 +124,7 @@ $sql_query = "SELECT paybatchnum,invnum,custnum,cpb.last,cpb.first," . 'LEFT JOIN pay_batch USING ( batchnum ) ' . "$search ORDER BY $orderby"; -my $html_init = ''; +my $html_init = ''; if ( $pay_batch ) { my $fixed = $conf->config('batch-fixed_format-'. $pay_batch->payby); if ( @@ -136,11 +136,12 @@ if ( $pay_batch ) { && $FS::CurrentUser::CurrentUser->access_right('Redownload resolved batches') ) ) { - $html_init .= qq!!; + $html_init .= qq!!; if ( $fixed ) { $html_init .= qq!!; } else { - $html_init .= qq!Download batch in format !. qq!!. qq!!. qq!!. @@ -151,7 +152,7 @@ if ( $pay_batch ) { qq!!. qq!!; } - $html_init .= qq!
!; + $html_init .= qq!

!; } if ( @@ -160,13 +161,28 @@ if ( $pay_batch ) { && $FS::CurrentUser::CurrentUser->access_right('Reprocess batches') ) ) { - $html_init .= qq!!. - qq!Upload results
!. - qq!Filename
!; + $html_init .= ''. + include('/elements/form-file_upload.html', + 'name' => 'FileUpload', + 'action' => "$p/misc/upload-batch.cgi", + 'num_files' => 1, + 'fields' => [ 'batchnum', 'format' ], + 'message' => 'Batch results uploaded.', + ) . + 'Upload results
'. + include('/elements/file-upload.html', + 'field' => 'file', + 'label' => 'Filename', + 'no_table'=> 1 + ). + '
' + ; if ( $fixed ) { $html_init .= qq!!; } else { - $html_init .= qq!Format Format !. + qq!
!; + qq!
!; } $html_init .= qq!!; - $html_init .= '
'; + $html_init .= '
'; } - + $html_init .= '
' } if ($pay_batch) {