6c4524476f113877c24c7b7af68e8cba30bc5715
[freeside.git] / httemplate / view / cust_main / billing.html
1 <FONT CLASS="fsinnerbox-title"><% mt('Billing information') |h %></FONT>
2 %# If we can't see the unencrypted card, then bill now is an exercise in
3 %# frustration (without some sort of job queue magic to send it to a secure
4 %# machine, anyway)
5 %if (  $FS::CurrentUser::CurrentUser->access_right('Bill customer now')
6 %      && ! $cust_main->is_encrypted($cust_main->payinfo)
7 %   ) { 
8 %#  (<A HREF="<% $p %>misc/bill.cgi?<% $cust_main->custnum %>"><% mt('Bill now') |h %></A>)
9   <& /elements/bill.html,
10        custnum   => $cust_main->custnum,
11        label     => emt('Bill now'),
12        url       => $p.'view/cust_main.cgi?'.$cust_main->custnum,
13   &>
14 % } 
15
16 <TABLE CLASS="fsinnerbox">
17
18 %( my $balance = $cust_main->balance )
19 %  =~ s/^(\-?)(.*)$/<FONT SIZE=+1>$1<\/FONT>$money_char$2/;
20
21 <TR>
22   <TD ALIGN="right"><% mt('Balance due') |h %></TD>
23   <TD BGCOLOR="#ffffff"><B><% $balance %></B></TD>
24 </TR>
25
26 <TR ID="recurring_row">
27   <TD ID="recurring_label" ALIGN="right"><% emt( 'Recurring' ) %></TD>
28   <TD ID="recurring_value" BGCOLOR="#ffffff"><IMG SRC="<% $fsurl %>images/wait-orange.gif"></TD>
29 </TR>
30
31 <& '/elements/xmlhttp.html',
32      'url'  => $fsurl.'misc/xmlhttp-cust_main-display_recurring.html',
33      'subs' => [ 'get_display_recurring'] &>
34
35 <SCRIPT>
36 <&| /elements/onload.js &>
37 get_display_recurring('custnum',<% $cust_main->custnum %>, function (xmlresult) {
38   var recurring = JSON.parse(xmlresult);
39   var rlabel = document.getElementById('recurring_label');
40   var rvalue = document.getElementById('recurring_value');
41   var rrow   = document.getElementById('recurring_row');
42   if (recurring['error']) {
43     rvalue.innerHTML = '<SPAN STYLE="color: red">Error</SPAN>';
44     console.log('display_recurring error: ' + recurring['error']);
45   } else if (recurring['display_recurring'].length) {
46     for (var ri = 0; ri < recurring['display_recurring'].length; ri++) {
47       var robj = recurring['display_recurring'][ri];
48       var freq_pretty = robj['freq_pretty'].charAt(0).toUpperCase()+robj['freq_pretty'].slice(1)+' recurring';
49       var amount = '<% $money_char %>'+parseFloat(robj['amount']).toFixed(2);
50       if (ri + 1 < recurring['display_recurring'].length) {
51         var rr = document.createElement('TR');
52         var rl = document.createElement('TD');
53         rl.style.textAlign = 'right';
54         rl.innerHTML = freq_pretty;
55         rr.appendChild(rl);
56         var rv = document.createElement('TD');
57         rv.style.backgroundColor = '#ffffff';
58         rv.innerHTML = amount;
59         rr.appendChild(rv);
60         rrow.parentNode.insertBefore(rr,rrow);
61       } else {
62         rlabel.innerHTML = freq_pretty;
63         rvalue.innerHTML = amount;
64       }
65     }
66   } else {
67     rrow.parentNode.removeChild(rrow);
68   }
69 });
70 </&>
71 </SCRIPT>
72
73 % if ( $conf->exists('cust_main-select-prorate_day') ) {
74 <TR>
75   <TD ALIGN="right"><% mt('Prorate day of month') |h %></TD>
76   <TD BGCOLOR="#ffffff"><% $cust_main->prorate_day %>
77   </TD>
78 </TR>
79 % }
80
81 % if ( $conf->exists('cust_main-select-billday') 
82 %    && ($cust_main->payby eq 'CARD' || $cust_main->payby eq 'CHEK') ) {
83 <TR>
84   <TD ALIGN="right"><% mt('Billing day of month') |h %></TD>
85   <TD BGCOLOR="#ffffff"><% $cust_main->billday %>
86   </TD>
87 </TR>
88 % }
89
90 <TR>
91   <TD ALIGN="right"><% mt('Billing type') |h %></TD>
92   <TD BGCOLOR="#ffffff">
93 % if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) { 
94
95 %   my $autodemand = $cust_main->payby eq 'CARD' ? 'automatic' : 'on-demand';
96     <% mt("Credit card ([_1])",$autodemand) |h %>
97   </TD>
98 </TR>
99 <TR>
100   <TD ALIGN="right"><% mt('Card number') |h %></TD>
101   <TD BGCOLOR="#ffffff"><% $cust_main->paymask %></TD>
102 </TR>
103 %
104 %#false laziness w/elements/select-month_year.html & edit/cust_main/billing.html
105 %my( $mon, $year );
106 %my $date = $cust_main->paydate || '12-2037';
107 %if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
108 %  ( $mon, $year ) = ( $2, $1 );
109 %} elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
110 %  ( $mon, $year ) = ( $1, $3 );
111 %} else {
112 %  warn "unrecognized expiration date format: $date";
113 %  ( $mon, $year ) = ( '', '' );
114 %}
115 %
116
117 <TR>
118   <TD ALIGN="right"><% mt('Expiration') |h %></TD>
119   <TD BGCOLOR="#ffffff"><% "$mon/$year" %></TD>
120 </TR>
121 % if ( $cust_main->paystart_month ) { 
122
123   <TR>
124     <TD ALIGN="right"><% mt('Start date') |h %></TD>
125     <TD BGCOLOR="#ffffff"><% $cust_main->paystart_month. '/'. $cust_main->paystart_year %>
126   </TR>
127 % } elsif ( $cust_main->payissue ) { 
128
129   <TR>
130     <TD ALIGN="right"><% mt('Issue #') |h %></TD>
131     <TD BGCOLOR="#ffffff"><% $cust_main->payissue %>
132   </TR>
133 % } 
134
135
136 <TR>
137   <TD ALIGN="right"><% mt('Name on card') |h %></TD>
138   <TD BGCOLOR="#ffffff"><% $cust_main->payname %></TD>
139 </TR>
140 % } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') {
141 %     my( $account, $aba ) = split('@', $cust_main->paymask );
142 %  my $branch = '';
143 %  ($branch,$aba) = split('\.',$aba) if $conf->config('echeck-country') eq 'CA';
144
145
146 % my $autodemand = $cust_main->payby eq 'CHEK' ? 'automatic' : 'on-demand';
147     <% mt("Electronic check ([_1])",$autodemand) |h %>
148   </TD>
149 </TR>
150
151 %  #false laziness w/edit/cust_main/billing.html and misc/payment.cgi
152 %  my $routing_label = $conf->config('echeck-country') eq 'US'
153 %                        ? 'ABA/Routing number'
154 %                        : 'Routing number';
155
156 <TR>
157   <TD ALIGN="right"><% mt($routing_label) |h %></TD>
158   <TD BGCOLOR="#ffffff"><% $aba %></TD>
159 </TR>
160
161 % if ( $conf->config('echeck-country') eq 'CA' ) {
162 <TR>
163   <TD ALIGN="right"><% mt('Branch number') |h %></TD>
164   <TD BGCOLOR="#ffffff"><% $branch %></TD>
165 <TR>
166 % }
167
168   <TD ALIGN="right"><% mt('Account number') |h %></TD>
169   <TD BGCOLOR="#ffffff"><% $account %></TD>
170 </TR>
171 <TR>
172   <TD ALIGN="right"><% mt('Account type') |h %></TD>
173   <TD BGCOLOR="#ffffff"><% $cust_main->paytype %></TD>
174 </TR>
175 <TR>
176   <TD ALIGN="right"><% mt('Bank name') |h %></TD>
177   <TD BGCOLOR="#ffffff"><% $cust_main->payname %></TD>
178 </TR>
179 % if ( $conf->exists('show_bankstate') ) {
180 <TR>
181   <TD ALIGN="right"><% $paystate_label %></TD>
182   <TD BGCOLOR="#ffffff"><% $cust_main->paystate || '&nbsp;&nbsp;&nbsp;' %></TD>
183 </TR>
184 % }
185 % } elsif ( $cust_main->payby eq 'LECB' ) {
186 %     $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
187 %     my $payinfo = "$1-$2-$3";
188
189     <% mt('Phone bill billing') |h %> 
190   </TD>
191 </TR>
192 <TR>
193   <TD ALIGN="right"><% mt('Phone number') |h %></TD>
194   <TD BGCOLOR="#ffffff"><% $payinfo %></TD>
195 </TR>
196 % } elsif ( $cust_main->payby eq 'BILL' ) { 
197
198     <% mt('Billing') |h %> 
199   </TD>
200 </TR>
201 % if ( $cust_main->payinfo ) { 
202
203 <TR>
204   <TD ALIGN="right"><% mt('P.O.') |h %></TD>
205   <TD BGCOLOR="#ffffff"><% $cust_main->payinfo %></TD>
206 </TR>
207 % } 
208
209
210 <TR>
211   <TD ALIGN="right"><% mt('Attention') |h %></TD>
212   <TD BGCOLOR="#ffffff"><% $cust_main->payname |h %></TD>
213 </TR>
214 % } elsif ( $cust_main->payby eq 'COMP' ) { 
215
216     <% mt('Complimentary') |h %> 
217   </TD>
218 </TR>
219 <TR>
220   <TD ALIGN="right"><% mt('Authorized by') |h %></TD>
221   <TD BGCOLOR="#ffffff"><% $cust_main->payinfo %></TD>
222 </TR>
223 %
224 %#false laziness w/above etc.
225 %my( $mon, $year );
226 %my $date = $cust_main->paydate || '12-2037';
227 %if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
228 %  ( $mon, $year ) = ( $2, $1 );
229 %} elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
230 %  ( $mon, $year ) = ( $1, $3 );
231 %} else {
232 %  warn "unrecognized expiration date format: $date";
233 %  ( $mon, $year ) = ( '', '' );
234 %}
235 %
236
237 <TR>
238   <TD ALIGN="right"><% mt('Expiration') |h %></TD>
239   <TD BGCOLOR="#ffffff"><% "$mon/$year" %></TD>
240 </TR>
241 % } 
242
243 % my $yes = emt('yes');
244 % my $no = emt('no');
245
246 % my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
247
248 % unless (    $conf->exists('cust_class-tax_exempt')
249 %          || $conf->exists('tax-cust_exempt-groups-require_individual_nums')
250 %        )
251 % {
252     <TR>
253       <TD ALIGN="right"><% mt('Tax exempt') |h %><% @exempt_groups ? ' ('.emt('all taxes').')' : '' %></TD>
254       <TD BGCOLOR="#ffffff"><% $cust_main->tax ? $yes : $no %></TD>
255     </TR>
256 % }
257
258 % foreach my $exempt_group ( @exempt_groups ) {
259 %   my $cust_main_exemption = $cust_main->tax_exemption($exempt_group);
260     <TR>
261       <TD ALIGN="right"><% mt('Tax exempt') |h %> (<% $exempt_group %> taxes)</TD>
262       <TD BGCOLOR="#ffffff"><% $cust_main_exemption ? $yes : $no %>
263         <% $cust_main_exemption ? $cust_main_exemption->exempt_number : '' |h %>
264       </TD>
265     </TR>
266 % }
267
268 % if ( $conf->exists('enable_taxproducts') ) {
269 <TR>
270   <TD ALIGN="right"><% mt('Tax location') |h %></TD>
271 % my $tax_location = $conf->exists('tax-ship_address')
272 %                    ? $cust_main->ship_location
273 %                    : $cust_main->bill_location;
274   <TD BGCOLOR="#ffffff"><% $tax_location->geocode('cch') %></TD>
275 </TR>
276 % }
277 <TR>
278   <TD ALIGN="right"><% mt('Postal mail invoices') |h %></TD>
279   <TD BGCOLOR="#ffffff">
280     <% ( grep { $_ eq 'POST' } @invoicing_list ) ? $yes : $no %>
281   </TD>
282 </TR>
283 <TR>
284   <TD ALIGN="right"><% mt('Fax invoices') |h %></TD>
285   <TD BGCOLOR="#ffffff">
286     <% ( grep { $_ eq 'FAX' } @invoicing_list ) ? $yes : $no %>
287   </TD>
288 </TR>
289 <TR>
290   <TD ALIGN="right"><% mt('Email invoices') |h %></TD>
291   <TD BGCOLOR="#ffffff">
292     <% $cust_main->invoice_noemail ? $no : $yes %>
293   </TD>
294 </TR>
295 % unless ( $conf->exists('cust-email-high-visibility')) {
296 <TR>
297   <TD ALIGN="right"><% mt('Email address(es)') |h %></TD>
298   <TD BGCOLOR="#ffffff">
299     <% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) || $no %>
300 %   if ( $cust_main->message_noemail ) {
301     <BR>
302     <SPAN STYLE="font-size: small"><% emt('(do not send notices)') %></SPAN>
303 %   }
304   </TD>
305 </TR>
306 % }
307 <TR>
308   <TD ALIGN="right"><% mt('Invoice terms') |h %></TD>
309   <TD BGCOLOR="#ffffff">
310     <% $cust_main->invoice_terms
311          || emt('Default').' ('. ( $conf->config('invoice_default_terms', $cust_main->agentnum)
312                                      || emt('Payable upon receipt')
313                                  ).
314                            ')'
315     %>
316   </TD>
317 </TR>
318 <TR>
319   <TD ALIGN="right"><% mt('Credit limit') |h %></TD>
320   <TD BGCOLOR="#ffffff">
321 %   my $default_credit_limit = $conf->config('default_credit_limit');
322     <% length($cust_main->credit_limit)
323          ? $money_char. sprintf("%.2f", $cust_main->credit_limit)
324          : $default_credit_limit
325            ? "Default ($money_char". sprintf("%.2f", $default_credit_limit). ")"
326            : emt('Unlimited')
327     %>
328 %   if ( $cust_main->num_cust_main_credit_limit ) {
329       <A HREF="<% $p %>search/cust_main_credit_limit.html?custnum=<% $cust_main->custnum %>">(incidents)</A>
330 %   }
331   </TD>
332 </TR>
333
334 % if ( $conf->exists('voip-cust_cdr_spools') ) { 
335   <TR>
336     <TD ALIGN="right"><% mt('Spool CDRs') |h %></TD>
337     <TD BGCOLOR="#ffffff"><% $cust_main->spool_cdr ? $yes : $no %></TD>
338   </TR>
339 % } 
340
341 % if ( $conf->exists('voip-cust_cdr_squelch') ) { 
342   <TR>
343     <TD ALIGN="right"><% mt($conf->exists('voip-cdr_email') ? 'Print CDRs' : 'Show CDRs') |h %></TD>
344     <TD BGCOLOR="#ffffff"><% $cust_main->squelch_cdr ? $no : $yes %></TD>
345   </TR>
346 % } 
347
348 % if ( $conf->exists('voip-cust_accountcode_cdr') ) { 
349    <TR>
350      <TD ALIGN="right"><% mt('Breakdown CDRs by accountcode') |h %></TD>
351      <TD BGCOLOR="#ffffff"><% $cust_main->accountcode_cdr ? $yes : $no %></TD>
352    </TR>
353 % }
354
355 % if ( my $attach = $conf->config('voip-cdr_email_attach') ) { 
356   <TR>
357     <TD ALIGN="right"><% mt('Email CDRs as '.uc($attach)) |h %></TD>
358     <TD BGCOLOR="#ffffff"><% $cust_main->email_csv_cdr ? $yes : $no %></TD>
359   </TR>
360 % } 
361
362 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
363   <TR>
364     <TD ALIGN="right"><% mt('CDR termination settlement') |h %></TD>
365     <TD BGCOLOR="#ffffff"><% $cust_main->cdr_termination_percentage %><% $cust_main->cdr_termination_percentage =~ /\d/ ? '%' : '' %></TD>
366   </TR>
367 % }
368
369 % if ( $cust_main->locale ) {
370 % my %locale_info = FS::Locales->locale_info($cust_main->locale);
371   <TR>
372     <TD ALIGN="right"><% mt('Invoicing locale') |h %></TD>
373     <TD BGCOLOR="#ffffff"><% $locale_info{name} . " (" . $locale_info{country} .")" %></TD>
374   </TR>
375 % }
376
377
378 </TABLE>
379 <%once>
380
381 my $paystate_label = FS::Msgcat::_gettext('paystate');
382 $paystate_label = 'Bank state' if $paystate_label =~/^paystate$/;
383
384 </%once>
385 <%init>
386
387 my( $cust_main ) = @_;
388 my @invoicing_list = $cust_main->invoicing_list;
389 my $conf = new FS::Conf;
390 my $money_char = $conf->config('money_char') || '$';
391
392 #false laziness w/edit/cust_main/billing.html
393 my $term_sql = "SELECT COUNT(*) FROM cust_pkg LEFT JOIN part_pkg USING ( pkgpart ) WHERE custnum = ? AND plan = 'cdr_termination' LIMIT 1";
394 my $term_sth = dbh->prepare($term_sql)  or die dbh->errstr;
395 $term_sth->execute($cust_main->custnum) or die $term_sth->errstr;
396 my $show_term = $term_sth->fetchrow_arrayref->[0];
397
398 </%init>