invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / httemplate / view / cust_bill.cgi
1 <& /elements/header-cust_main.html, view=>'payment_history', custnum=>$custnum &>
2
3 <h2>Invoice #<% $invnum %></h2>
4
5 % if ( !$cust_bill->closed ) { # otherwise allow no changes
6 %   my $can_delete = $conf->exists('deleteinvoices')
7 %                    && $curuser->access_right('Delete invoices');
8 %   my $can_void = $curuser->access_right('Void invoices');
9 %   if ( $can_void ) {
10     <& /elements/popup_link.html,
11       'label'       => emt('Void this invoice'),
12       'actionlabel' => emt('Void this invoice'),
13       'action'      => $p.'misc/void-cust_bill.html?invnum='.$invnum,
14     &>
15 %   }
16 %   if ( $can_void and $can_delete ) {
17   &nbsp;|&nbsp;
18 %   }
19 %   if ( $can_delete ) {
20     <A href="" onclick="areyousure(\
21       '<%$p%>misc/delete-cust_bill.html?<% $invnum %>',\
22       <% mt('Are you sure you want to delete this invoice?') |js_string %>)"\
23     TITLE = "<% mt('Delete this invoice from the database completely') |h %>">\
24     <% emt('Delete this invoice') |h %></A>
25 %   }
26 %   if ( $can_void or $can_delete ) {
27   <BR><BR>
28 %   }
29 % }
30
31 % if ( $cust_bill->owed > 0
32 %      && $curuser->access_right(['Post payment', 'Post check payment', 'Post cash payment'])
33 %      && ! $conf->exists('pkg-balances')
34 %    )
35 % {
36 %     my $s = 0;
37
38       <% mt('Post') |h %> 
39
40 %     if ( $curuser->access_right(['Post payment', 'Post check payment']) ) { 
41           <% $s++ ? ' | ' : '' %>
42           <A HREF="<% $p %>edit/cust_pay.cgi?payby=BILL;invnum=<% $invnum %>"><% mt('check') |h %></A>
43 %     } 
44
45 %     if ( $curuser->access_right(['Post payment', 'Post cash payment']) ) { 
46           <% $s++ ? ' | ' : '' %>
47           <A HREF="<% $p %>edit/cust_pay.cgi?payby=CASH;invnum=<% $invnum %>"><% mt('cash') |h %></A>
48 %     } 
49
50 %#  %     if ( $payby{'WEST'} && $curuser->access_right(['Post payment']) ) { 
51 %#            <% $s++ ? ' | ' : '' %>
52 %#            <A HREF="<% $p %>edit/cust_pay.cgi?payby=WEST;invnum=<% $invnum %>"><% mt('Western Union') |h %></A>
53 %#  %     } 
54 %#  
55 %#  %     if ( $payby{'MCRD'} && $curuser->access_right(['Post payment']) ) { 
56 %#            <% $s++ ? ' | ' : '' %>
57 %#            <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCRD;invnum=<% $invnum %>"><% mt('manual credit card') |h %></A>
58 %#  %     } 
59 %#  
60 %#  %     if ( $payby{'MCHK'} && $curuser->access_right(['Post payment']) ) { 
61 %#            <% $s++ ? ' | ' : '' %>
62 %#            <A HREF="<% $p %>edit/cust_pay.cgi?payby=MCHK;invnum=<% $invnum %>"><% mt('manual electronic check') |h %></A>
63 %#  %     } 
64
65       <% mt('payment against this invoice') |h %><BR><BR>
66
67 % } 
68
69 % if ( $conf->exists('cust_bill-enable_promised_date') ) {
70 %   my $onclick = include('/elements/popup_link_onclick.html',
71 %      'action'      => $p.'misc/cust_bill-promised_date.html?'.$invnum,
72 %      'actionlabel' => emt('Set promised payment date'),
73 %      'width'       => 320,
74 %      'height'      => 240,
75 %   );
76 %   $onclick = '<A HREF="#" onclick="'.$onclick.'">';
77 %   if ( $cust_bill->promised_date ) {
78 %     my $date_format = $conf->config('date_format') || '%b %o, %Y';
79       <% emt('Payment promised by [_1]', 
80             time2str($date_format, $cust_bill->promised_date) ) %>
81       (&nbsp;<% $onclick %><% mt('change') |h %></A>&nbsp;)
82       <BR><BR>
83 %   }
84 %   elsif ( $cust_bill->owed > 0 ) {
85     <% $onclick %><% mt('Set promised payment date' ) |h %></A>
86     <BR><BR>
87 %   }
88 % }
89
90 % if ( $curuser->access_right('Resend invoices') ) {
91         <A HREF="<% $p %>misc/send-invoice.cgi?method=print;<% $link %>"><% mt('Print this invoice') |h %></A>
92 % }
93
94 % if ( $conf->exists('support-key')
95 %        && $curuser->access_right('Print and mail invoices')
96 %    )
97 % {
98         | <& /elements/popup_link.html,
99                'action'      => $p."misc/post_fsinc-invoice.cgi?$link",
100                'label'       => 'Print and mail this invoice online',
101                'actionlabel' => 'Invoice printing and mailing',
102           &>
103 % }
104
105 % if ( $curuser->access_right('Resend invoices') ) {
106
107 %   if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
108         | <A HREF="<% $p %>misc/send-invoice.cgi?method=email;<% $link %>"><% mt('Re-email this invoice') |h %></A>
109 %   } 
110
111 %   if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
112         | <A HREF="<% $p %>misc/send-invoice.cgi?method=fax;<% $link %>"><% mt('Re-fax this invoice') |h %></A>
113 %   } 
114
115 % }
116
117 % if (    $curuser->access_right('Resend invoices')
118 %      || $curuser->access_right('Print and mail invoices') ) {
119         <BR><BR>
120 % } 
121
122 % my $br = 0;
123 % if ( $conf->exists('invoice_latex') ) {
124
125   <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $link %>"><% mt('View typeset invoice PDF') |h %></A>
126
127 %   $br++;
128 % }
129
130 % my @modes = grep {! $_->disabled} 
131 %   $cust_bill->cust_main->agent->invoice_modes;
132 % if ( @modes || $include_statement_template ) {
133 <% $br ? '|' : '' %>
134 <% emt('View as:') %>
135 <FORM STYLE="display:inline" ACTION="<% $cgi->url %>" METHOD="GET">
136 <INPUT NAME="invnum" VALUE="<% $invnum %>" TYPE="hidden">
137 <& /elements/select-table.html,
138   table       => 'invoice_mode',
139   field       => 'mode',
140   curr_value  => scalar($cgi->param('mode')),
141   records     => \@modes,
142   name_col    => 'modename',
143   onchange    => 'change_invoice_mode',
144   empty_label => '(default)',
145   $include_statement_template ? (
146     'post_options' => [ 'statement', '(statement)' ]
147   ) : ()
148 &>
149 <SCRIPT TYPE="text/javascript">
150 function change_invoice_mode(obj) {
151   obj.form.submit();
152 }
153 </SCRIPT>
154 </FORM>
155 % }
156
157 % if ( $cust_bill->num_cust_event ) {
158 <% $br ? '|' : '' %>
159 <A HREF="<%$p%>search/cust_event.html?invnum=<% $cust_bill->invnum %>"><% mt('View invoice events') |h %></A> 
160 %   $br++;
161 % }
162 % if ( $cust_bill->tax > 0 ) { # inefficient
163 <% $br ? '|' : '' %>
164 <& /elements/popup_link.html,
165   'action'      => 'cust_bill_tax_matrix.html?' . $cust_bill->invnum,
166   'label'       => mt('View tax details'),
167   'actionlabel' => mt('Tax details'),
168   'width'       => 1050,
169   'height'      => 500,
170   'title'       => emt('Tax details'),
171 &>
172 %   $br++;
173 % }
174 % if ( $cust_bill->taxengine_request ) { # inefficient
175 <% $br ? '|' : '' %>
176 <& /elements/popup_link.html,
177   'action'      => 'cust_bill-taxengine_request.html?invnum=' . $cust_bill->invnum,
178   'label'       => mt('View raw tax engine request'),
179   'actionlabel' => mt('Tax engine request'),
180   'width'       => 1050,
181   'height'      => 600,
182   'title'       => emt('Tax engine request'),
183 &>
184 %   $br++;
185 % }
186
187 <BR><BR>
188
189 % if ( $conf->exists('invoice_html') && ! $cgi->param('plaintext') ) { 
190   <% join('', $cust_bill->print_html(\%opt) ) %>
191 % } else { 
192   <PRE><% join('', $cust_bill->print_text(\%opt) ) |h %></PRE>
193 % } 
194
195 <& /elements/footer-cust_main.html &>
196 <%init>
197
198 my $curuser = $FS::CurrentUser::CurrentUser;
199
200 die "access denied"
201   unless $curuser->access_right('View invoices');
202
203 my $conf = FS::Conf->new;
204
205 my( $invnum, $mode, $template, $notice_name, $no_coupon );
206 my($query) = $cgi->keywords;
207 if ( $query =~ /^((.+)-)?(\d+)$/ ) {
208   $template = $2;
209   $invnum = $3;
210   $notice_name = 'Invoice';
211 } else {
212   $invnum = $cgi->param('invnum');
213   $template = $cgi->param('template');
214   $notice_name = $cgi->param('notice_name');
215   $mode = $cgi->param('mode');
216 }
217
218 if ($mode eq 'statement') {
219   $mode = undef;
220   $template = 'statement';
221   $notice_name = 'Statement';
222   $no_coupon = 1;
223 }
224
225 my $include_statement_template = $conf->config('payment_receipt_statement_mode') ? 0 : 1;
226
227 my %opt = (
228   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
229   'template'      => $template,
230   'notice_name'   => $notice_name,
231 );
232
233 $opt{'barcode_img'} = 1 if $conf->exists('invoice-barcode');
234
235 my $cust_bill = qsearchs({
236   'select'    => 'cust_bill.*',
237   'table'     => 'cust_bill',
238   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
239   'hashref'   => { 'invnum' => $invnum },
240   'extra_sql' => ' AND '. $curuser->agentnums_sql,
241 });
242 # if we're asked for a voided invnum, redirect appropriately
243 if (!$cust_bill and FS::cust_bill_void->row_exists("invnum = $invnum") ) {
244   $m->clear_buffer;
245   my $url = $p.'view/cust_bill_void.html?'.$cgi->query_string;
246   $m->print( $cgi->redirect($url) );
247   $m->abort;
248 }
249 die "Invoice #$invnum not found!" unless $cust_bill;
250
251 $cust_bill->set('mode' => $mode);
252
253 my $custnum = $cust_bill->custnum;
254 my $display_custnum = $cust_bill->cust_main->display_custnum;
255
256 my $link = "invnum=$invnum";
257 $link .= ';mode=' . $mode if $mode;
258 $link .= ';template='. uri_escape($template) if $template;
259 $link .= ';notice_name='. $notice_name if $notice_name;
260 $link .= ';no_coupon=1' if $no_coupon;
261
262 </%init>