summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authormark <mark>2010-06-08 22:25:01 +0000
committermark <mark>2010-06-08 22:25:01 +0000
commitb7dbecfb82aea90a4289089927d0b17436b2ed5a (patch)
tree8f22377f952d54aba7efcde11a2cd3f2e8a8cf40 /httemplate
parent3d0320979331ac4b68fc07fd4203d74c1b05aff4 (diff)
RT#947: batch download of invoice PDFs
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/elements/menu.html2
-rw-r--r--httemplate/elements/progress-init.html44
-rw-r--r--httemplate/misc/process/bill_batch-print.html5
-rwxr-xr-xhttemplate/search/bill_batch.cgi65
-rw-r--r--httemplate/view/bill_batch.cgi102
5 files changed, 218 insertions, 0 deletions
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index 5ce49c3..ef105b1 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -357,6 +357,8 @@ $tools_menu{'Quick payment entry'} = [ $fsurl.'misc/batch-cust_pay.html', 'Ente
$tools_menu{'Process payment batches'} = [ $fsurl.'search/pay_batch.cgi?magic=_date;open=1;intransit=1', 'Process credit card and electronic check batches' ]
if ( $conf->exists('batch-enable') || $conf->config('batch-enable_payby') )
&& $curuser->access_right('Process batches');
+$tools_menu{'Process invoice batches'} = [ $fsurl.'search/bill_batch.cgi' ]
+ if ( $conf->exists('invoice_print_pdf') );
$tools_menu{'Job Queue'} = [ $fsurl.'search/queue.html', 'View pending job queue' ]
if $curuser->access_right('Job queue');
$tools_menu{'Ticketing'} = [ \%tools_ticketing, 'Ticketing tools' ]
diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html
index 194fc74..20eb9bf 100644
--- a/httemplate/elements/progress-init.html
+++ b/httemplate/elements/progress-init.html
@@ -1,3 +1,47 @@
+<%doc>
+Example:
+In misc/something.html:
+
+ <FORM NAME="MyForm">
+ <INPUT TYPE="hidden" NAME="recordnum" VALUE="42">
+ <INPUT TYPE="hidden" NAME="what_to_do" VALUE="delete">
+ <% include( '/elements/progress-init.html',
+ 'MyForm',
+ [ 'recordnum', 'what_to_do' ],
+ $p.'misc/process_something.html',
+ { url => $p.'where_to_go_next.html' },
+ #or { message => 'Finished!' },
+ );
+ </FORM>
+ <SCRIPT TYPE="text/javascript>process();</SCRIPT>
+
+In misc/process_something.html:
+
+<%init>
+my $server = FS::UI::Web::JSRPC->new('FS::something::process_whatever', $cgi);
+</%init>
+<% $server->process %>
+
+In FS/something.pm:
+
+sub process_whatever { #class method
+ my $job = shift;
+ my $param = thaw(base64_decode(shift));
+ # param = { 'recordnum' => 42, 'what_to_do' => delete }
+ # make use of this as you like
+ do_phase1;
+ $job->update_statustext(20);
+ do_phase2;
+ $job->update_statustext(40);
+ do_phase3;
+ $job->update_statustext(60);
+ # etc.
+ return 'BLAH BLAH NOBODY WILL EVER SEE THIS RETURN VALUE';
+}
+
+I am not responsible for errors in the above documentation.
+
+</%doc>
<% include('/elements/xmlhttp.html',
'method' => 'POST',
'url' => $action,
diff --git a/httemplate/misc/process/bill_batch-print.html b/httemplate/misc/process/bill_batch-print.html
new file mode 100644
index 0000000..54d639e
--- /dev/null
+++ b/httemplate/misc/process/bill_batch-print.html
@@ -0,0 +1,5 @@
+% die "access denied"
+% unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
+% my $server = FS::UI::Web::JSRPC->new('FS::bill_batch::process_print_pdf', $cgi);
+<% $server->process %>
+<%init></%init>
diff --git a/httemplate/search/bill_batch.cgi b/httemplate/search/bill_batch.cgi
new file mode 100755
index 0000000..e5abc89
--- /dev/null
+++ b/httemplate/search/bill_batch.cgi
@@ -0,0 +1,65 @@
+<% include( 'elements/search.html',
+ 'title' => 'Invoice Batches',
+ 'name_singular' => 'batch',
+ 'query' => { 'table' => 'bill_batch',
+ 'hashref' => $hashref,
+ 'extra_sql' => $extra_sql.
+ 'ORDER BY batchnum DESC',
+ },
+ 'count_query' => "$count_query $extra_sql",
+ 'header' => [ 'Batch',
+ 'Item Count',
+ 'Status',
+ '',
+ ],
+ 'align' => 'rrcc',
+ 'fields' => [ 'batchnum',
+ sub {
+ my $st = "SELECT COUNT(*) from cust_bill_batch WHERE batchnum=" . shift->batchnum;
+ my $sth = dbh->prepare($st)
+ or die dbh->errstr. "doing $st";
+ $sth->execute
+ or die "Error executing \"$st\": ". $sth->errstr;
+ $sth->fetchrow_arrayref->[0];
+ },
+ sub {
+ $statusmap{shift->status};
+ },
+ sub { shift->status eq 'O' ?
+ 'Download and close' : 'Download'
+ },
+ ],
+ 'links' => [
+ $link,
+ $link,
+ $link,
+ $dlink,
+ ],
+ 'style' => [
+ '',
+ '',
+ '',
+ sub { shift->status eq 'O' ? "b" : '' },
+ ],
+ 'really_disable_download' => 1,
+ )
+
+%>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
+
+my %statusmap = ('O'=>'Open', 'R'=>'Closed');
+my $hashref = {};
+my $count_query = 'SELECT COUNT(*) FROM bill_batch';
+
+my $extra_sql = ''; # may add something here later
+my $link = [ "${p}view/bill_batch.cgi?batchnum=", 'batchnum' ];
+my $dlink = sub {
+ [ "${p}view/bill_batch.cgi?magic=print;".
+ (shift->status eq 'O' ? 'close=1;' : '').
+ 'batchnum=',
+ 'batchnum']
+};
+</%init>
diff --git a/httemplate/view/bill_batch.cgi b/httemplate/view/bill_batch.cgi
new file mode 100644
index 0000000..7275756
--- /dev/null
+++ b/httemplate/view/bill_batch.cgi
@@ -0,0 +1,102 @@
+% if($magic eq 'print') {
+<% include('/elements/header.html', "Download Batch") %>
+<FORM NAME="OneTrueForm">
+<INPUT TYPE="hidden" NAME="batchnum" VALUE="<% $batchnum %>">
+% $cgi->delete('magic');
+<% include('/elements/progress-init.html',
+ 'OneTrueForm',
+ [ 'batchnum' ],
+ $p.'misc/process/bill_batch-print.html',
+ {'url' => $cgi->self_url . ';magic=download'},
+ '',
+) %></FORM>
+<SCRIPT TYPE="text/javascript">process();</SCRIPT>
+<% include('/elements/footer.html') %>
+% }
+%
+% elsif($magic eq 'download') {
+% $m->clear_buffer;
+% $r->content_type('application/pdf');
+% $r->headers_out->add('Content-Disposition' => 'attachment;filename="invoice_batch_'.$batchnum.'.pdf"');
+<% $batch->pdf %>
+% $batch->pdf('');
+% my $error = $batch->replace;
+% warn "error deleting cached PDF: '$error'\n" if $error;
+% }
+% else {
+<% include('/search/elements/search.html',
+ 'title' => $close ?
+ "Batch $batchnum closed." :
+ "Invoice Batch $batchnum",
+ 'name' => 'invoices',
+ 'query' => { 'table' => 'cust_bill_batch',
+ 'select' => join(', ',
+ 'cust_bill.*',
+ FS::UI::Web::cust_sql_fields(),
+ 'cust_main.custnum AS cust_main_custnum',
+ ),
+ 'hashref' => { },
+ 'addl_from' =>
+ 'LEFT JOIN cust_bill USING ( invnum ) '.
+ 'LEFT JOIN cust_main USING ( custnum )',
+ 'extra_sql' => '',
+ " WHERE batchnum = $batchnum",
+ },
+ 'count_query' => "SELECT COUNT(*) FROM cust_bill_batch WHERE batchnum = $batchnum",
+ 'html_init' => $html_init,
+ 'header' => [ 'Invoice #',
+ 'Amount',
+ 'Date',
+ 'Customer',
+ ],
+ 'fields' => [ sub { shift->cust_bill->display_invnum },
+ sub { sprintf($money_char.'%.2f',
+ shift->cust_bill->charged ) },
+ sub { time2str('%b %d %Y',
+ shift->cust_bill->_date ) },
+ sub { shift->cust_bill->cust_main->name },
+ ],
+ 'align' => 'rrll',
+ 'links' => [ ($link) x 3, $clink,
+ ],
+ 'really_disable_download' => 1,
+) %>
+% }
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
+
+use Data::Dumper;
+warn Dumper($cgi->Vars);
+
+my $conf = new FS::Conf;
+my $batch;
+my $batchnum = $cgi->param('batchnum');
+
+$batch = FS::bill_batch->by_key($batchnum);
+die "Batch '$batchnum' not found!\n" if !$batch;
+
+my $magic = $cgi->param('magic');
+my $html_init = '';
+
+my $close = $cgi->param('close');
+$batch->close if $close;
+
+if(!$magic) {
+ $cgi->param('magic' => 'print');
+ $cgi->delete('close');
+ $html_init = '<A HREF="'.$cgi->self_url.'">Download this batch</A><BR>';
+ if($batch->status eq 'O') {
+ $cgi->param('close' => 1);
+ $cgi->delete('magic');
+ $html_init .= '<A HREF="'.$cgi->self_url.'">Close this batch</A><BR>';
+ }
+ $html_init .= '<BR>';
+}
+
+my $link = [ "$p/view/cust_bill.cgi?", 'invnum' ];
+my $clink = [ "$p/view/cust_main.cgi?", 'custnum' ];
+my $money_char = $conf->config('money_char') || '$';
+
+</%init>