1 % if($magic eq 'download') {
2 % my $content = $batch->pdf;
4 % my $error = $batch->replace;
5 % warn "error deleting cached PDF: '$error'\n" if $error;
8 % $r->content_type('application/pdf');
9 % $r->headers_out->add('Content-Disposition' => 'attachment;filename="invoice_batch_'.$batchnum.'.pdf"');
13 % elsif ($magic eq 'download_popup') {
15 <& /elements/header-popup.html,
16 { 'etc' => 'BGCOLOR="#ccccff"' } &>
17 <SCRIPT type="text/javascript">
19 window.open('<% $cgi->self_url . ';magic=download' %>');
23 <TABLE WIDTH="100%"><TR><TD STYLE="text-align:center;vertical-align:middle">
25 <A HREF="javascript:start()">Download batch #<% $batchnum %></A>
28 <& /elements/footer.html &>
33 <% include('/search/elements/search.html',
35 "Batch $batchnum closed." :
36 "Invoice Batch $batchnum",
38 'query' => { 'table' => 'cust_bill_batch',
39 'select' => join(', ',
41 FS::UI::Web::cust_sql_fields(),
42 'cust_main.custnum AS cust_main_custnum',
46 'LEFT JOIN cust_bill USING ( invnum ) '.
47 'LEFT JOIN cust_main USING ( custnum )',
48 'extra_sql' => " WHERE batchnum = $batchnum",
50 'count_query' => "SELECT COUNT(*) FROM cust_bill_batch WHERE batchnum = $batchnum",
51 'html_init' => $html_init,
52 'html_foot' => $html_foot,
53 'header' => [ 'Invoice #',
58 'fields' => [ sub { shift->cust_bill->display_invnum },
59 sub { sprintf($money_char.'%.2f',
60 shift->cust_bill->charged ) },
61 sub { time2str('%b %d %Y',
62 shift->cust_bill->_date ) },
63 sub { shift->cust_bill->cust_main->name },
66 'links' => [ ($link) x 3, $clink,
68 'really_disable_download' => 1,
74 unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
76 my $conf = new FS::Conf;
78 my $batchnum = $cgi->param('batchnum');
80 $batch = FS::bill_batch->by_key($batchnum);
81 die "Batch '$batchnum' not found!\n" if !$batch;
83 my $magic = $cgi->param('magic');
84 $cgi->delete('magic');
86 my $close = $cgi->param('close');
87 $batch->close if $close;
92 $html_init .= qq!<FORM NAME="OneTrueForm">
93 <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">!;
94 $html_init .= include('/elements/progress-init.html',
97 $p.'misc/process/bill_batch-print.html',
99 'popup_url' => $cgi->self_url . ';magic=download_popup',
103 $html_init .= '</FORM>
104 <A HREF="javascript:process()">Download this batch</A></BR>';
105 if ( $batch->status eq 'O' ) {
106 $cgi->param('close' => 1);
107 $html_init .= '<A HREF="'.$cgi->self_url.'">Close this batch</A><BR>';
109 $html_init .= '<BR>';
110 if ( $cgi->param('start_download') ) {
111 $cgi->delete('start_download');
112 $html_foot = '<SCRIPT TYPE="text/javascript">process();</SCRIPT>';
116 my $link = [ "$p/view/cust_bill.cgi?", 'invnum' ];
117 my $clink = [ "$p/view/cust_main.cgi?", 'custnum' ];
118 my $money_char = $conf->config('money_char') || '$';