add per-customer "Invoice reports" link, RT#13802
[freeside.git] / httemplate / view / bill_batch.cgi
1 % if($magic eq 'download') {
2 %   my $content = $batch->pdf;
3 %   $batch->pdf('');
4 %   my $error = $batch->replace;
5 %   warn "error deleting cached PDF: '$error'\n" if $error;
6 %
7 %   $m->clear_buffer;
8 %   $r->content_type('application/pdf');
9 %   $r->headers_out->add('Content-Disposition' => 'attachment;filename="invoice_batch_'.$batchnum.'.pdf"');
10 <% $content %>
11 % }
12 %
13 % elsif ($magic eq 'download_popup') {
14 %
15 <& /elements/header-popup.html,
16   { 'etc' => 'BGCOLOR="#ccccff"' } &>
17 <SCRIPT type="text/javascript">
18 function start() {
19 window.open('<% $cgi->self_url . ';magic=download' %>');
20 parent.nd(1);
21 }
22 </SCRIPT>
23 <TABLE WIDTH="100%"><TR><TD STYLE="text-align:center;vertical-align:middle">
24 <FONT SIZE="+1">
25 <A HREF="javascript:start()">Download batch #<% $batchnum %></A>
26 </FONT>
27 </TD></TR></TABLE>
28 <& /elements/footer.html &>
29 %
30 % }
31 %
32 % else {
33 <% include('/search/elements/search.html', 
34               'title'     => $close ?
35                               "Batch $batchnum closed." :
36                               "Invoice Batch $batchnum",
37               'name'      => 'invoices',
38               'query'     => { 'table'   => 'cust_bill_batch',
39                                'select'  => join(', ',
40                                           'cust_bill.*',
41                                           FS::UI::Web::cust_sql_fields(),
42                                           'cust_main.custnum AS cust_main_custnum',
43                                 ),
44                                'hashref' => { },
45                                'addl_from' => 
46                                  'LEFT JOIN cust_bill USING ( invnum ) '.
47                                  'LEFT JOIN cust_main USING ( custnum )',
48                                'extra_sql' => " WHERE batchnum = $batchnum",
49                              },
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 #',
54                                'Amount',
55                                'Date',
56                                'Customer',
57                              ],
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 },
64                              ],
65               'align'     => 'rrll',
66               'links'     => [ ($link) x 3, $clink,
67                              ],
68               'really_disable_download' => 1,
69 ) %>
70 % }
71 <%init>
72
73 die "access denied"
74   unless $FS::CurrentUser::CurrentUser->access_right('View invoices');
75
76 my $conf = new FS::Conf;
77 my $batch;
78 my $batchnum = $cgi->param('batchnum');
79
80 $batch = FS::bill_batch->by_key($batchnum);
81 die "Batch '$batchnum' not found!\n" if !$batch;
82
83 my $magic = $cgi->param('magic');
84 $cgi->delete('magic');
85
86 my $close = $cgi->param('close');
87 $batch->close if $close;
88
89 my $html_init = '';
90 my $html_foot = '';
91 if ( !$magic ) {
92   $html_init .= qq!<FORM NAME="OneTrueForm">
93     <INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">!;
94   $html_init .= include('/elements/progress-init.html',
95                   'OneTrueForm',
96                   [ 'batchnum' ],
97                   $p.'misc/process/bill_batch-print.html',
98                   {
99                     'popup_url' => $cgi->self_url . ';magic=download_popup',
100                   },
101                   '',
102   );
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>';
108   }
109   $html_init .= '<BR>';
110   if ( $cgi->param('start_download') ) {
111     $cgi->delete('start_download');
112     $html_foot = '<SCRIPT TYPE="text/javascript">process();</SCRIPT>';
113   }
114 }
115
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') || '$';
119
120 </%init>