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