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 ( $curuser->access_right('Print and mail invoices') ) {
102         | <& /elements/popup_link.html,
103                'action'      => $p."misc/post_fsinc-invoice.cgi?$link",
104                'label'       => 'Print and mail this invoice online',
105                'actionlabel' => 'Invoice printing and mailing',
106           &>
107 % }
108
109 % if ( $curuser->access_right('Resend invoices') ) {
110
111 %   if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) { 
112         | <A HREF="<% $p %>misc/send-invoice.cgi?method=email;<% $link %>"><% mt('Re-email this invoice') |h %></A>
113 %   } 
114
115 %   if ( $conf->exists('hylafax') && length($cust_bill->cust_main->fax) ) { 
116         | <A HREF="<% $p %>misc/send-invoice.cgi?method=fax;<% $link %>"><% mt('Re-fax this invoice') |h %></A>
117 %   } 
118
119 % }
120
121 % if (    $curuser->access_right('Resend invoices')
122 %      || $curuser->access_right('Print and mail invoices') ) {
123         <BR><BR>
124 % } 
125
126 % my $br = 0;
127 % if ( $conf->exists('invoice_latex') ) {
128
129   <A HREF="<% $p %>view/cust_bill-pdf.cgi?<% $link %>"><% mt('View typeset invoice PDF') |h %></A>
130
131 %   $br++;
132 % } 
133
134 % if ( $cust_bill->num_cust_event ) {
135 <% $br ? '|' : '' %>
136 <A HREF="<%$p%>search/cust_event.html?invnum=<% $cust_bill->invnum %>"><% mt('View invoice events') |h %></A> 
137 %   $br++;
138 % }
139
140 % my @modes = grep {! $_->disabled} 
141 %   $cust_bill->cust_main->agent->invoice_modes;
142 % if ( @modes || $include_statement_template ) {
143 <% $br ? '|' : '' %>
144 <% mt('View as:') %>
145 <FORM STYLE="display:inline" ACTION="<% $cgi->url %>" METHOD="GET">
146 <INPUT NAME="invnum" VALUE="<% $invnum %>" TYPE="hidden">
147 <& /elements/select-table.html,
148   table       => 'invoice_mode',
149   field       => 'mode',
150   curr_value  => scalar($cgi->param('mode')),
151   records     => \@modes,
152   name_col    => 'modename',
153   onchange    => 'change_invoice_mode',
154   empty_label => '(default)',
155   $include_statement_template ? (
156     'post_options' => [ 'statement', '(statement)' ]
157   ) : ()
158 &>
159 <SCRIPT TYPE="text/javascript">
160 function change_invoice_mode(obj) {
161   obj.form.submit();
162 }
163 </SCRIPT>
164 % }
165
166 <BR><BR>
167
168 % if ( $conf->exists('invoice_html') && ! $cgi->param('plaintext') ) { 
169   <% join('', $cust_bill->print_html(\%opt) ) %>
170 % } else { 
171   <PRE><% join('', $cust_bill->print_text(\%opt) ) |h %></PRE>
172 % } 
173
174 <& /elements/footer.html &>
175 <%init>
176
177 my $curuser = $FS::CurrentUser::CurrentUser;
178
179 die "access denied"
180   unless $curuser->access_right('View invoices');
181
182 my $conf = FS::Conf->new;
183
184 my( $invnum, $mode, $template, $notice_name, $no_coupon );
185 my($query) = $cgi->keywords;
186 if ( $query =~ /^((.+)-)?(\d+)$/ ) {
187   $template = $2;
188   $invnum = $3;
189   $notice_name = 'Invoice';
190 } else {
191   $invnum = $cgi->param('invnum');
192   $template = $cgi->param('template');
193   $notice_name = $cgi->param('notice_name');
194   $mode = $cgi->param('mode');
195 }
196
197 if ($mode eq 'statement') {
198   $mode = undef;
199   $template = 'statement';
200   $notice_name = 'Statement';
201   $no_coupon = 1;
202 }
203
204 my $include_statement_template = $conf->config('payment_receipt_statement_mode') ? 0 : 1;
205
206 my %opt = (
207   'unsquelch_cdr' => $conf->exists('voip-cdr_email'),
208   'template'      => $template,
209   'notice_name'   => $notice_name,
210 );
211
212 $opt{'barcode_img'} = 1 if $conf->exists('invoice-barcode');
213
214 my $cust_bill = qsearchs({
215   'select'    => 'cust_bill.*',
216   'table'     => 'cust_bill',
217   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
218   'hashref'   => { 'invnum' => $invnum },
219   'extra_sql' => ' AND '. $curuser->agentnums_sql,
220 });
221 # if we're asked for a voided invnum, redirect appropriately
222 if (!$cust_bill and FS::cust_bill_void->row_exists("invnum = $invnum") ) {
223   $m->clear_buffer;
224   my $url = $p.'view/cust_bill_void.html?'.$cgi->query_string;
225   $m->print( $cgi->redirect($url) );
226   $m->abort;
227 }
228 die "Invoice #$invnum not found!" unless $cust_bill;
229
230 $cust_bill->set('mode' => $mode);
231
232 my $custnum = $cust_bill->custnum;
233 my $display_custnum = $cust_bill->cust_main->display_custnum;
234
235 my $link = "invnum=$invnum";
236 $link .= ';mode=' . $mode if $mode;
237 $link .= ';template='. uri_escape($template) if $template;
238 $link .= ';notice_name='. $notice_name if $notice_name;
239 $link .= ';no_coupon=1' if $no_coupon;
240
241 </%init>