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