remove invoice deletion (and ancient & unused config settings), RT#37157
[freeside.git] / httemplate / view / cust_bill.cgi
1 <& /elements/header.html, mt('Invoice View'), menubar(
2   emt("View this customer (#[_1])",$display_custnum) => "${p}view/cust_main.cgi?$custnum",
3 ) &>
4
5 <SCRIPT TYPE="text/javascript">
6 function areyousure(href, message) {
7   if (confirm(message) == true)
8     window.location.href = href;
9 }
10 </SCRIPT>
11
12 % if ( !$cust_bill->closed && $curuser->access_right('Void invoices') ) {
13     <& /elements/popup_link.html,
14       'label'       => emt('Void this invoice'),
15       'actionlabel' => emt('Void this invoice'),
16       'action'      => $p.'misc/void-cust_bill.html?invnum='.$invnum,
17     &>
18     <BR><BR>
19 % }
20
21 % if ( $cust_bill->owed > 0
22 %      && scalar( grep $payby{$_}, qw(BILL CASH WEST MCRD MCHK) )
23 %      && $curuser->access_right(['Post payment', 'Post check payment', 'Post cash payment'])
24 %      && ! $conf->exists('pkg-balances')
25 %    )
26 % {
27 %     my $s = 0;
28
29       <% mt('Post') |h %> 
30
31 %     if ( $payby{'BILL'} && $curuser->access_right(['Post payment', 'Post check payment']) ) { 
32           <% $s++ ? ' | ' : '' %>
33           <A HREF="<% $p %>edit/cust_pay.cgi?payby=BILL;invnum=<% $invnum %>"><% mt('check') |h %></A>
34 %     } 
35
36 %     if ( $payby{'CASH'} && $curuser->access_right(['Post payment', 'Post cash payment']) ) { 
37           <% $s++ ? ' | ' : '' %>
38           <A HREF="<% $p %>edit/cust_pay.cgi?payby=CASH;invnum=<% $invnum %>"><% mt('cash') |h %></A>
39 %     } 
40
41 %     if ( $payby{'WEST'} && $curuser->access_right(['Post payment']) ) { 
42           <% $s++ ? ' | ' : '' %>
43           <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;invnum=<% $invnum %>"><% mt('Western Union') |h %></A>
44 %     } 
45
46 %     if ( $payby{'MCRD'} && $curuser->access_right(['Post payment']) ) { 
47           <% $s++ ? ' | ' : '' %>
48           <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;invnum=<% $invnum %>"><% mt('manual credit card') |h %></A>
49 %     } 
50
51 %     if ( $payby{'MCHK'} && $curuser->access_right(['Post payment']) ) { 
52           <% $s++ ? ' | ' : '' %>
53           <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCHK;invnum=<% $invnum %>"><% mt('manual electronic check') |h %></A>
54 %     } 
55
56       <% mt('payment against this invoice') |h %><BR><BR>
57
58 % } 
59
60 % if ( $conf->exists('cust_bill-enable_promised_date') ) {
61 %   my $onclick = include('/elements/popup_link_onclick.html',
62 %      'action'      => $p.'misc/cust_bill-promised_date.html?'.$invnum,
63 %      'actionlabel' => emt('Set promised payment date'),
64 %      'width'       => 320,
65 %      'height'      => 240,
66 %   );
67 %   $onclick = '<A HREF="#" onclick="'.$onclick.'">';
68 %   if ( $cust_bill->promised_date ) {
69 %     my $date_format = $conf->config('date_format') || '%b %o, %Y';
70       <% mt('Payment promised by [_1]', 
71             time2str($date_format, $cust_bill->promised_date) ) %>
72       (&nbsp;<% $onclick %><% mt('change') |h %></A>&nbsp;)
73       <BR><BR>
74 %   }
75 %   elsif ( $cust_bill->owed > 0 ) {
76     <% $onclick %><% mt('Set promised payment date' ) |h %></A>
77     <BR><BR>
78 %   }
79 % }
80
81 % if ( $curuser->access_right('Resend invoices') ) {
82
83     <A HREF="<% $p %>misc/send-invoice.cgi?method=print;<% $link %>"><% mt('Re-print this invoice') |h %></A>
84
85 %   if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
86         | <A HREF="<% $p %>misc/send-invoice.cgi?method=email;<% $link %>"><% mt('Re-email this invoice') |h %></A>
87 %   } 
88
89 %   if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
90         | <A HREF="<% $p %>misc/send-invoice.cgi?method=fax;<% $link %>"><% mt('Re-fax this invoice') |h %></A>
91 %   } 
92
93     <BR><BR>
94
95 % } 
96
97 % if ( $conf->exists('invoice_latex') ) { 
98
99   <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $link %>"><% mt('View typeset invoice PDF') |h %></A>
100   <BR><BR>
101 % } 
102
103 % my $br = 0;
104 % if ( $cust_bill->num_cust_event ) { $br++;
105 <A HREF="<%$p%>search/cust_event.html?invnum=<% $cust_bill->invnum %>">( <% mt('View invoice events') |h %> )</A> 
106 % }
107
108 % my @modes = grep {! $_->disabled} 
109 %   $cust_bill->cust_main->agent->invoice_modes;
110 % if ( @modes ) {
111 ( <% mt('View as:') %>
112 <FORM STYLE="display:inline" ACTION="<% $cgi->url %>" METHOD="GET">
113 <INPUT NAME="invnum" VALUE="<% $invnum %>" TYPE="hidden">
114 <& /elements/select-table.html,
115   table       => 'invoice_mode',
116   field       => 'mode',
117   curr_value  => scalar($cgi->param('mode')),
118   records     => \@modes,
119   name_col    => 'modename',
120   onchange    => 'change_invoice_mode',
121   empty_label => '(default)',
122 &> )
123 <SCRIPT TYPE="text/javascript">
124 function change_invoice_mode(obj) {
125   obj.form.submit();
126 }
127 </SCRIPT>
128 % $br++;
129 % }
130
131 <% $br ? '<BR><BR>' : '' %>
132
133 % if ( $conf->exists('invoice_html') && ! $cgi->param('plaintext') ) { 
134   <% join('', $cust_bill->print_html(\%opt) ) %>
135 % } else { 
136   <PRE><% join('', $cust_bill->print_text(\%opt) ) |h %></PRE>
137 % } 
138
139 <& /elements/footer.html &>
140 <%init>
141
142 my $curuser = $FS::CurrentUser::CurrentUser;
143
144 die "access denied"
145   unless $curuser->access_right('View invoices');
146
147 my $conf = FS::Conf->new;
148
149 my( $invnum, $mode, $template, $notice_name );
150 my($query) = $cgi->keywords;
151 if ( $query =~ /^((.+)-)?(\d+)$/ ) {
152   $template = $2;
153   $invnum = $3;
154   $notice_name = 'Invoice';
155 } else {
156   $invnum = $cgi->param('invnum');
157   $template = $cgi->param('template');
158   $notice_name = $cgi->param('notice_name');
159   $mode = $cgi->param('mode');
160 }
161
162 my %opt = (
163   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
164   'template'      => $template,
165   'notice_name'   => $notice_name,
166 );
167
168 $opt{'barcode_img'} = 1 if $conf->exists('invoice-barcode');
169
170 my @payby =  grep /\w/, $conf->config('payby');
171 @payby = (qw( CARD DCRD CHEK DCHK BILL CASH ))
172   unless @payby;
173 my %payby = map { $_=>1 } @payby;
174
175 my $cust_bill = qsearchs({
176   'select'    => 'cust_bill.*',
177   'table'     => 'cust_bill',
178   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
179   'hashref'   => { 'invnum' => $invnum },
180   'extra_sql' => ' AND '. $curuser->agentnums_sql,
181 });
182 # if we're asked for a voided invnum, redirect appropriately
183 if (!$cust_bill and FS::cust_bill_void->row_exists("invnum = $invnum") ) {
184   $m->clear_buffer;
185   my $url = $p.'view/cust_bill_void.html?'.$cgi->query_string;
186   $m->print( $cgi->redirect($url) );
187   $m->abort;
188 }
189 die "Invoice #$invnum not found!" unless $cust_bill;
190
191 $cust_bill->set('mode' => $mode);
192
193 my $custnum = $cust_bill->custnum;
194 my $display_custnum = $cust_bill->cust_main->display_custnum;
195
196 my $link = "invnum=$invnum";
197 $link .= ';mode=' . $mode if $mode;
198 $link .= ';template='. uri_escape($template) if $template;
199 $link .= ';notice_name='. $notice_name if $notice_name;
200
201 </%init>