RT#71890: SelfService API: Return monthly recurring fee [display_recurring, v3 reconc...
[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 % #54: just an arbitrary number i pulled out of my goober.  ideally we'd like
27 % # to consider e.g. a histogram of num_ncancelled_packages for the entire
28 % # customer base, and compare it to a graph of the overhead for generating this
29 % # information.  (and optimize it better, we could get it more from SQL)
30 % if ( $cust_main->num_ncancelled_pkgs < 54 ) {
31 %   foreach my $freq_info ($cust_main->display_recurring) {
32       <TR>
33         <TD ALIGN="right"><% emt( ucfirst($freq_info->{'freq_pretty'}). ' recurring' ) %></TD>
34         <TD BGCOLOR="#ffffff"><% $money_char. sprintf('%.2f', $freq_info->{'amount'}) %></TD>
35       </TR>
36 %   }
37 % }
38
39 % if ( $conf->exists('cust_main-select-prorate_day') ) {
40 <TR>
41   <TD ALIGN="right"><% mt('Prorate day of month') |h %></TD>
42   <TD BGCOLOR="#ffffff"><% $cust_main->prorate_day %>
43   </TD>
44 </TR>
45 % }
46
47 % if ( $conf->exists('cust_main-select-billday') 
48 %    && ($cust_main->payby eq 'CARD' || $cust_main->payby eq 'CHEK') ) {
49 <TR>
50   <TD ALIGN="right"><% mt('Billing day of month') |h %></TD>
51   <TD BGCOLOR="#ffffff"><% $cust_main->billday %>
52   </TD>
53 </TR>
54 % }
55
56 <TR>
57   <TD ALIGN="right"><% mt('Billing type') |h %></TD>
58   <TD BGCOLOR="#ffffff">
59 % if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) { 
60
61 %   my $autodemand = $cust_main->payby eq 'CARD' ? 'automatic' : 'on-demand';
62     <% mt("Credit card ([_1])",$autodemand) |h %>
63   </TD>
64 </TR>
65 <TR>
66   <TD ALIGN="right"><% mt('Card number') |h %></TD>
67   <TD BGCOLOR="#ffffff"><% $cust_main->paymask %></TD>
68 </TR>
69 %
70 %#false laziness w/elements/select-month_year.html & edit/cust_main/billing.html
71 %my( $mon, $year );
72 %my $date = $cust_main->paydate || '12-2037';
73 %if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
74 %  ( $mon, $year ) = ( $2, $1 );
75 %} elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
76 %  ( $mon, $year ) = ( $1, $3 );
77 %} else {
78 %  warn "unrecognized expiration date format: $date";
79 %  ( $mon, $year ) = ( '', '' );
80 %}
81 %
82
83 <TR>
84   <TD ALIGN="right"><% mt('Expiration') |h %></TD>
85   <TD BGCOLOR="#ffffff"><% "$mon/$year" %></TD>
86 </TR>
87 % if ( $cust_main->paystart_month ) { 
88
89   <TR>
90     <TD ALIGN="right"><% mt('Start date') |h %></TD>
91     <TD BGCOLOR="#ffffff"><% $cust_main->paystart_month. '/'. $cust_main->paystart_year %>
92   </TR>
93 % } elsif ( $cust_main->payissue ) { 
94
95   <TR>
96     <TD ALIGN="right"><% mt('Issue #') |h %></TD>
97     <TD BGCOLOR="#ffffff"><% $cust_main->payissue %>
98   </TR>
99 % } 
100
101
102 <TR>
103   <TD ALIGN="right"><% mt('Name on card') |h %></TD>
104   <TD BGCOLOR="#ffffff"><% $cust_main->payname %></TD>
105 </TR>
106 % } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') {
107 %     my( $account, $aba ) = split('@', $cust_main->paymask );
108 %  my $branch = '';
109 %  ($branch,$aba) = split('\.',$aba) if $conf->config('echeck-country') eq 'CA';
110
111
112 % my $autodemand = $cust_main->payby eq 'CHEK' ? 'automatic' : 'on-demand';
113     <% mt("Electronic check ([_1])",$autodemand) |h %>
114   </TD>
115 </TR>
116
117 %  #false laziness w/edit/cust_main/billing.html and misc/payment.cgi
118 %  my $routing_label = $conf->config('echeck-country') eq 'US'
119 %                        ? 'ABA/Routing number'
120 %                        : 'Routing number';
121
122 <TR>
123   <TD ALIGN="right"><% mt($routing_label) |h %></TD>
124   <TD BGCOLOR="#ffffff"><% $aba %></TD>
125 </TR>
126
127 % if ( $conf->config('echeck-country') eq 'CA' ) {
128 <TR>
129   <TD ALIGN="right"><% mt('Branch number') |h %></TD>
130   <TD BGCOLOR="#ffffff"><% $branch %></TD>
131 <TR>
132 % }
133
134   <TD ALIGN="right"><% mt('Account number') |h %></TD>
135   <TD BGCOLOR="#ffffff"><% $account %></TD>
136 </TR>
137 <TR>
138   <TD ALIGN="right"><% mt('Account type') |h %></TD>
139   <TD BGCOLOR="#ffffff"><% $cust_main->paytype %></TD>
140 </TR>
141 <TR>
142   <TD ALIGN="right"><% mt('Bank name') |h %></TD>
143   <TD BGCOLOR="#ffffff"><% $cust_main->payname %></TD>
144 </TR>
145 % if ( $conf->exists('show_bankstate') ) {
146 <TR>
147   <TD ALIGN="right"><% $paystate_label %></TD>
148   <TD BGCOLOR="#ffffff"><% $cust_main->paystate || '&nbsp;&nbsp;&nbsp;' %></TD>
149 </TR>
150 % }
151 % } elsif ( $cust_main->payby eq 'LECB' ) {
152 %     $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
153 %     my $payinfo = "$1-$2-$3";
154
155     <% mt('Phone bill billing') |h %> 
156   </TD>
157 </TR>
158 <TR>
159   <TD ALIGN="right"><% mt('Phone number') |h %></TD>
160   <TD BGCOLOR="#ffffff"><% $payinfo %></TD>
161 </TR>
162 % } elsif ( $cust_main->payby eq 'BILL' ) { 
163
164     <% mt('Billing') |h %> 
165   </TD>
166 </TR>
167 % if ( $cust_main->payinfo ) { 
168
169 <TR>
170   <TD ALIGN="right"><% mt('P.O.') |h %></TD>
171   <TD BGCOLOR="#ffffff"><% $cust_main->payinfo %></TD>
172 </TR>
173 % } 
174
175
176 <TR>
177   <TD ALIGN="right"><% mt('Attention') |h %></TD>
178   <TD BGCOLOR="#ffffff"><% $cust_main->payname |h %></TD>
179 </TR>
180 % } elsif ( $cust_main->payby eq 'COMP' ) { 
181
182     <% mt('Complimentary') |h %> 
183   </TD>
184 </TR>
185 <TR>
186   <TD ALIGN="right"><% mt('Authorized by') |h %></TD>
187   <TD BGCOLOR="#ffffff"><% $cust_main->payinfo %></TD>
188 </TR>
189 %
190 %#false laziness w/above etc.
191 %my( $mon, $year );
192 %my $date = $cust_main->paydate || '12-2037';
193 %if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
194 %  ( $mon, $year ) = ( $2, $1 );
195 %} elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
196 %  ( $mon, $year ) = ( $1, $3 );
197 %} else {
198 %  warn "unrecognized expiration date format: $date";
199 %  ( $mon, $year ) = ( '', '' );
200 %}
201 %
202
203 <TR>
204   <TD ALIGN="right"><% mt('Expiration') |h %></TD>
205   <TD BGCOLOR="#ffffff"><% "$mon/$year" %></TD>
206 </TR>
207 % } 
208
209 % my $yes = emt('yes');
210 % my $no = emt('no');
211
212 % my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
213
214 % unless (    $conf->exists('cust_class-tax_exempt')
215 %          || $conf->exists('tax-cust_exempt-groups-require_individual_nums')
216 %        )
217 % {
218     <TR>
219       <TD ALIGN="right"><% mt('Tax exempt') |h %><% @exempt_groups ? ' ('.emt('all taxes').')' : '' %></TD>
220       <TD BGCOLOR="#ffffff"><% $cust_main->tax ? $yes : $no %></TD>
221     </TR>
222 % }
223
224 % foreach my $exempt_group ( @exempt_groups ) {
225 %   my $cust_main_exemption = $cust_main->tax_exemption($exempt_group);
226     <TR>
227       <TD ALIGN="right"><% mt('Tax exempt') |h %> (<% $exempt_group %> taxes)</TD>
228       <TD BGCOLOR="#ffffff"><% $cust_main_exemption ? $yes : $no %>
229         <% $cust_main_exemption ? $cust_main_exemption->exempt_number : '' |h %>
230       </TD>
231     </TR>
232 % }
233
234 % if ( $conf->exists('enable_taxproducts') ) {
235 <TR>
236   <TD ALIGN="right"><% mt('Tax location') |h %></TD>
237 % my $tax_location = $conf->exists('tax-ship_address')
238 %                    ? $cust_main->ship_location
239 %                    : $cust_main->bill_location;
240   <TD BGCOLOR="#ffffff"><% $tax_location->geocode('cch') %></TD>
241 </TR>
242 % }
243 <TR>
244   <TD ALIGN="right"><% mt('Postal mail invoices') |h %></TD>
245   <TD BGCOLOR="#ffffff">
246     <% ( grep { $_ eq 'POST' } @invoicing_list ) ? $yes : $no %>
247   </TD>
248 </TR>
249 <TR>
250   <TD ALIGN="right"><% mt('Fax invoices') |h %></TD>
251   <TD BGCOLOR="#ffffff">
252     <% ( grep { $_ eq 'FAX' } @invoicing_list ) ? $yes : $no %>
253   </TD>
254 </TR>
255 <TR>
256   <TD ALIGN="right"><% mt('Email invoices') |h %></TD>
257   <TD BGCOLOR="#ffffff">
258     <% $cust_main->invoice_noemail ? $no : $yes %>
259   </TD>
260 </TR>
261 % unless ( $conf->exists('cust-email-high-visibility')) {
262 <TR>
263   <TD ALIGN="right"><% mt('Email address(es)') |h %></TD>
264   <TD BGCOLOR="#ffffff">
265     <% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) || $no %>
266 %   if ( $cust_main->message_noemail ) {
267     <BR>
268     <SPAN STYLE="font-size: small"><% emt('(do not send notices)') %></SPAN>
269 %   }
270   </TD>
271 </TR>
272 % }
273 <TR>
274   <TD ALIGN="right"><% mt('Invoice terms') |h %></TD>
275   <TD BGCOLOR="#ffffff">
276     <% $cust_main->invoice_terms
277          || emt('Default').' ('. ( $conf->config('invoice_default_terms', $cust_main->agentnum)
278                                      || emt('Payable upon receipt')
279                                  ).
280                            ')'
281     %>
282   </TD>
283 </TR>
284 <TR>
285   <TD ALIGN="right"><% mt('Credit limit') |h %></TD>
286   <TD BGCOLOR="#ffffff">
287 %   my $default_credit_limit = $conf->config('default_credit_limit');
288     <% length($cust_main->credit_limit)
289          ? $money_char. sprintf("%.2f", $cust_main->credit_limit)
290          : $default_credit_limit
291            ? "Default ($money_char". sprintf("%.2f", $default_credit_limit). ")"
292            : emt('Unlimited')
293     %>
294 %   if ( $cust_main->num_cust_main_credit_limit ) {
295       <A HREF="<% $p %>search/cust_main_credit_limit.html?custnum=<% $cust_main->custnum %>">(incidents)</A>
296 %   }
297   </TD>
298 </TR>
299
300 % if ( $conf->exists('voip-cust_cdr_spools') ) { 
301   <TR>
302     <TD ALIGN="right"><% mt('Spool CDRs') |h %></TD>
303     <TD BGCOLOR="#ffffff"><% $cust_main->spool_cdr ? $yes : $no %></TD>
304   </TR>
305 % } 
306
307 % if ( $conf->exists('voip-cust_cdr_squelch') ) { 
308   <TR>
309     <TD ALIGN="right"><% mt($conf->exists('voip-cdr_email') ? 'Print CDRs' : 'Show CDRs') |h %></TD>
310     <TD BGCOLOR="#ffffff"><% $cust_main->squelch_cdr ? $no : $yes %></TD>
311   </TR>
312 % } 
313
314 % if ( $conf->exists('voip-cust_accountcode_cdr') ) { 
315    <TR>
316      <TD ALIGN="right"><% mt('Breakdown CDRs by accountcode') |h %></TD>
317      <TD BGCOLOR="#ffffff"><% $cust_main->accountcode_cdr ? $yes : $no %></TD>
318    </TR>
319 % }
320
321 % if ( my $attach = $conf->config('voip-cdr_email_attach') ) { 
322   <TR>
323     <TD ALIGN="right"><% mt('Email CDRs as '.uc($attach)) |h %></TD>
324     <TD BGCOLOR="#ffffff"><% $cust_main->email_csv_cdr ? $yes : $no %></TD>
325   </TR>
326 % } 
327
328 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
329   <TR>
330     <TD ALIGN="right"><% mt('CDR termination settlement') |h %></TD>
331     <TD BGCOLOR="#ffffff"><% $cust_main->cdr_termination_percentage %><% $cust_main->cdr_termination_percentage =~ /\d/ ? '%' : '' %></TD>
332   </TR>
333 % }
334
335 % if ( $cust_main->locale ) {
336 % my %locale_info = FS::Locales->locale_info($cust_main->locale);
337   <TR>
338     <TD ALIGN="right"><% mt('Invoicing locale') |h %></TD>
339     <TD BGCOLOR="#ffffff"><% $locale_info{name} . " (" . $locale_info{country} .")" %></TD>
340   </TR>
341 % }
342
343
344 </TABLE>
345 <%once>
346
347 my $paystate_label = FS::Msgcat::_gettext('paystate');
348 $paystate_label = 'Bank state' if $paystate_label =~/^paystate$/;
349
350 </%once>
351 <%init>
352
353 my( $cust_main ) = @_;
354 my @invoicing_list = $cust_main->invoicing_list;
355 my $conf = new FS::Conf;
356 my $money_char = $conf->config('money_char') || '$';
357
358 #false laziness w/edit/cust_main/billing.html
359 my $term_sql = "SELECT COUNT(*) FROM cust_pkg LEFT JOIN part_pkg USING ( pkgpart ) WHERE custnum = ? AND plan = 'cdr_termination' LIMIT 1";
360 my $term_sth = dbh->prepare($term_sql)  or die dbh->errstr;
361 $term_sth->execute($cust_main->custnum) or die $term_sth->errstr;
362 my $show_term = $term_sth->fetchrow_arrayref->[0];
363
364 </%init>