1 % if($magic eq 'download') {
3 % $r->content_type('application/pdf');
4 % $r->headers_out->add('Content-Disposition' => 'attachment;filename="invoice_batch_'.$batchnum.'.pdf"');
7 % my $error = $batch->replace;
8 % warn "error deleting cached PDF: '$error'\n" if $error;
11 % elsif ($magic eq 'download_popup') {
13 <& /elements/header-popup.html,
14 { 'etc' => 'BGCOLOR="#ccccff"' } &>
15 <SCRIPT type="text/javascript">
17 window.open('<% $cgi->self_url . ';magic=download' %>');
21 <TABLE WIDTH="100%"><TR><TD STYLE="text-align:center;vertical-align:middle">
23 <A HREF="javascript:start()">Download batch #<% $batchnum %></A>
26 <& /elements/footer.html &>
31 <% include('/search/elements/search.html',
33 "Batch $batchnum closed." :
34 "Invoice Batch $batchnum",
36 'query' => { 'table' => 'cust_bill_batch',
37 'select' => join(', ',
39 FS::UI::Web::cust_sql_fields(),
40 'cust_main.custnum AS cust_main_custnum',
44 'LEFT JOIN cust_bill USING ( invnum ) '.
45 'LEFT JOIN cust_main USING ( custnum )',
46 'extra_sql' => " WHERE batchnum = $batchnum",
48 'count_query' => "SELECT COUNT(*) FROM cust_bill_batch WHERE batchnum = $batchnum",
49 'html_init' => $html_init,
50 'html_foot' => $html_foot,
51 'header' => [ 'Invoice #',
56 'fields' => [ sub { shift->cust_bill->display_invnum },
57 sub { sprintf($money_char.'%.2f',
58 shift->cust_bill->charged ) },
59 sub { time2str('%b %d %Y',
60 shift->cust_bill->_date ) },
61 sub { shift->cust_bill->cust_main->name },
64 'links' => [ ($link) x 3, $clink,
66 'really_disable_download' => 1,
72 unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
74 my $conf = new FS::Conf;
76 my $batchnum = $cgi->param('batchnum');
78 $batch = FS::bill_batch->by_key($batchnum);
79 die "Batch '$batchnum' not found!\n" if !$batch;
81 my $magic = $cgi->param('magic');
82 $cgi->delete('magic');
84 my $close = $cgi->param('close');
85 $batch->close if $close;
90 $html_init .= qq!<FORM NAME="OneTrueForm">
91 <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">!;
92 $html_init .= include('/elements/progress-init.html',
95 $p.'misc/process/bill_batch-print.html',
97 'popup_url' => $cgi->self_url . ';magic=download_popup',
101 $html_init .= '</FORM>
102 <A HREF="javascript:process()">Download this batch</A></BR>';
103 if ( $batch->status eq 'O' ) {
104 $cgi->param('close' => 1);
105 $html_init .= '<A HREF="'.$cgi->self_url.'">Close this batch</A><BR>';
107 $html_init .= '<BR>';
108 if ( $cgi->param('start_download') ) {
109 $cgi->delete('start_download');
110 $html_foot = '<SCRIPT TYPE="text/javascript">process();</SCRIPT>';
114 my $link = [ "$p/view/cust_bill.cgi?", 'invnum' ];
115 my $clink = [ "$p/view/cust_main.cgi?", 'custnum' ];
116 my $money_char = $conf->config('money_char') || '$';