zip email CDRs, RT#40112
[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 %   my $sth = dbh->prepare("
32 %     SELECT DISTINCT freq FROM cust_pkg LEFT JOIN part_pkg USING (pkgpart)
33 %       WHERE freq IS NOT NULL AND freq != '0'
34 %         AND ( cancel IS NULL OR cancel = 0 )
35 %         AND custnum = ?
36 %   ") or die $DBI::errstr;
37
38 %   $sth->execute($cust_main->custnum) or die $sth->errstr;
39
40 %   #not really a numeric sort because freqs can actually be all sorts of things
41 %   # but good enough for the 99% cases of ordering monthly quarterly annually
42 %   my @freqs = sort { $a <=> $b } map { $_->[0] } @{ $sth->fetchall_arrayref };
43
44 %   foreach my $freq (@freqs) {
45 %     my @cust_pkg = qsearch({
46 %       'table'     => 'cust_pkg',
47 %       'addl_from' => 'LEFT JOIN part_pkg USING (pkgpart)',
48 %       'hashref'   => { 'custnum' => $cust_main->custnum, },
49 %       'extra_sql' => 'AND ( cancel IS NULL OR cancel = 0 )
50 %                       AND freq = '. dbh->quote($freq),
51 %       'order_by'  => 'ORDER BY COALESCE(start_date,0), pkgnum', # to ensure old pkgs come before change_to_pkg
52 %     }) or next;
53
54 %     my $freq_pretty = $cust_pkg[0]->part_pkg->freq_pretty;
55 %
56 %     my $amount = 0;
57 %     my $skip_pkg = {};
58 %     foreach my $cust_pkg (@cust_pkg) {
59 %       my $part_pkg = $cust_pkg->part_pkg;
60 %       next if $cust_pkg->susp
61 %            && ! $cust_pkg->option('suspend_bill')
62 %            && ( ! $part_pkg->option('suspend_bill')
63 %                 || $cust_pkg->option('no_suspend_bill')
64 %               );
65 %
66 %       #pkg change handling
67 %       next if $skip_pkg->{$cust_pkg->pkgnum};
68 %       if ($cust_pkg->change_to_pkgnum) {
69 %         #if change is on or before next bill date, use new pkg
70 %         next if $cust_pkg->expire <= $cust_pkg->bill;
71 %         #if change is after next bill date, use old (this) pkg
72 %         $skip_pkg->{$cust_pkg->change_to_pkgnum} = 1;
73 %       }
74 %
75 %       my $pkg_amount = 0;
76 %
77 %       #add recurring amounts for this package and its billing add-ons
78 %       foreach my $l_part_pkg ( $part_pkg->self_and_bill_linked ) {
79 %         $pkg_amount += $l_part_pkg->base_recur($cust_pkg);
80 %       }
81 %
82 %       #subtract amounts for any active discounts
83 %       #(there should only be one at the moment, otherwise this makes no sense)
84 %       foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
85 %         my $discount = $cust_pkg_discount->discount;
86 %         #and only one of these for each
87 %         $pkg_amount -= $discount->amount;
88 %         $pkg_amount -= $amount * $discount->percent/100;
89 %       }
90 %
91 %       $pkg_amount *= ( $cust_pkg->quantity || 1 );
92 %
93 %       $amount += $pkg_amount;
94 %
95 %     }
96    
97       <TR>
98         <TD ALIGN="right"><% emt( ucfirst($freq_pretty). ' recurring' ) %></TD>
99         <TD BGCOLOR="#ffffff"><% $money_char. sprintf('%.2f', $amount) %></TD>
100         </TD>
101       </TR>
102 %   }
103
104 % }
105
106 % if ( $conf->exists('cust_main-select-prorate_day') ) {
107 <TR>
108   <TD ALIGN="right"><% mt('Prorate day of month') |h %></TD>
109   <TD BGCOLOR="#ffffff"><% $cust_main->prorate_day %>
110   </TD>
111 </TR>
112 % }
113
114 % if ( $conf->exists('cust_main-select-billday') 
115 %    && ($cust_main->payby eq 'CARD' || $cust_main->payby eq 'CHEK') ) {
116 <TR>
117   <TD ALIGN="right"><% mt('Billing day of month') |h %></TD>
118   <TD BGCOLOR="#ffffff"><% $cust_main->billday %>
119   </TD>
120 </TR>
121 % }
122
123 <TR>
124   <TD ALIGN="right"><% mt('Billing type') |h %></TD>
125   <TD BGCOLOR="#ffffff">
126 % if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) { 
127
128 %   my $autodemand = $cust_main->payby eq 'CARD' ? 'automatic' : 'on-demand';
129     <% mt("Credit card ([_1])",$autodemand) |h %>
130   </TD>
131 </TR>
132 <TR>
133   <TD ALIGN="right"><% mt('Card number') |h %></TD>
134   <TD BGCOLOR="#ffffff"><% $cust_main->paymask %></TD>
135 </TR>
136 %
137 %#false laziness w/elements/select-month_year.html & edit/cust_main/billing.html
138 %my( $mon, $year );
139 %my $date = $cust_main->paydate || '12-2037';
140 %if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
141 %  ( $mon, $year ) = ( $2, $1 );
142 %} elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
143 %  ( $mon, $year ) = ( $1, $3 );
144 %} else {
145 %  warn "unrecognized expiration date format: $date";
146 %  ( $mon, $year ) = ( '', '' );
147 %}
148 %
149
150 <TR>
151   <TD ALIGN="right"><% mt('Expiration') |h %></TD>
152   <TD BGCOLOR="#ffffff"><% "$mon/$year" %></TD>
153 </TR>
154 % if ( $cust_main->paystart_month ) { 
155
156   <TR>
157     <TD ALIGN="right"><% mt('Start date') |h %></TD>
158     <TD BGCOLOR="#ffffff"><% $cust_main->paystart_month. '/'. $cust_main->paystart_year %>
159   </TR>
160 % } elsif ( $cust_main->payissue ) { 
161
162   <TR>
163     <TD ALIGN="right"><% mt('Issue #') |h %></TD>
164     <TD BGCOLOR="#ffffff"><% $cust_main->payissue %>
165   </TR>
166 % } 
167
168
169 <TR>
170   <TD ALIGN="right"><% mt('Name on card') |h %></TD>
171   <TD BGCOLOR="#ffffff"><% $cust_main->payname %></TD>
172 </TR>
173 % } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') {
174 %     my( $account, $aba ) = split('@', $cust_main->paymask );
175 %  my $branch = '';
176 %  ($branch,$aba) = split('\.',$aba) if $conf->config('echeck-country') eq 'CA';
177
178
179 % my $autodemand = $cust_main->payby eq 'CHEK' ? 'automatic' : 'on-demand';
180     <% mt("Electronic check ([_1])",$autodemand) |h %>
181   </TD>
182 </TR>
183
184 %  #false laziness w/edit/cust_main/billing.html and misc/payment.cgi
185 %  my $routing_label = $conf->config('echeck-country') eq 'US'
186 %                        ? 'ABA/Routing number'
187 %                        : 'Routing number';
188
189 <TR>
190   <TD ALIGN="right"><% mt($routing_label) |h %></TD>
191   <TD BGCOLOR="#ffffff"><% $aba %></TD>
192 </TR>
193
194 % if ( $conf->config('echeck-country') eq 'CA' ) {
195 <TR>
196   <TD ALIGN="right"><% mt('Branch number') |h %></TD>
197   <TD BGCOLOR="#ffffff"><% $branch %></TD>
198 <TR>
199 % }
200
201   <TD ALIGN="right"><% mt('Account number') |h %></TD>
202   <TD BGCOLOR="#ffffff"><% $account %></TD>
203 </TR>
204 <TR>
205   <TD ALIGN="right"><% mt('Account type') |h %></TD>
206   <TD BGCOLOR="#ffffff"><% $cust_main->paytype %></TD>
207 </TR>
208 <TR>
209   <TD ALIGN="right"><% mt('Bank name') |h %></TD>
210   <TD BGCOLOR="#ffffff"><% $cust_main->payname %></TD>
211 </TR>
212 % if ( $conf->exists('show_bankstate') ) {
213 <TR>
214   <TD ALIGN="right"><% $paystate_label %></TD>
215   <TD BGCOLOR="#ffffff"><% $cust_main->paystate || '&nbsp;&nbsp;&nbsp;' %></TD>
216 </TR>
217 % }
218 % } elsif ( $cust_main->payby eq 'LECB' ) {
219 %     $cust_main->payinfo =~ /^(\d{3})(\d{3})(\d{4})$/;
220 %     my $payinfo = "$1-$2-$3";
221
222     <% mt('Phone bill billing') |h %> 
223   </TD>
224 </TR>
225 <TR>
226   <TD ALIGN="right"><% mt('Phone number') |h %></TD>
227   <TD BGCOLOR="#ffffff"><% $payinfo %></TD>
228 </TR>
229 % } elsif ( $cust_main->payby eq 'BILL' ) { 
230
231     <% mt('Billing') |h %> 
232   </TD>
233 </TR>
234 % if ( $cust_main->payinfo ) { 
235
236 <TR>
237   <TD ALIGN="right"><% mt('P.O.') |h %></TD>
238   <TD BGCOLOR="#ffffff"><% $cust_main->payinfo %></TD>
239 </TR>
240 % } 
241
242
243 <TR>
244   <TD ALIGN="right"><% mt('Attention') |h %></TD>
245   <TD BGCOLOR="#ffffff"><% $cust_main->payname |h %></TD>
246 </TR>
247 % } elsif ( $cust_main->payby eq 'COMP' ) { 
248
249     <% mt('Complimentary') |h %> 
250   </TD>
251 </TR>
252 <TR>
253   <TD ALIGN="right"><% mt('Authorized by') |h %></TD>
254   <TD BGCOLOR="#ffffff"><% $cust_main->payinfo %></TD>
255 </TR>
256 %
257 %#false laziness w/above etc.
258 %my( $mon, $year );
259 %my $date = $cust_main->paydate || '12-2037';
260 %if ( $date  =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format
261 %  ( $mon, $year ) = ( $2, $1 );
262 %} elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
263 %  ( $mon, $year ) = ( $1, $3 );
264 %} else {
265 %  warn "unrecognized expiration date format: $date";
266 %  ( $mon, $year ) = ( '', '' );
267 %}
268 %
269
270 <TR>
271   <TD ALIGN="right"><% mt('Expiration') |h %></TD>
272   <TD BGCOLOR="#ffffff"><% "$mon/$year" %></TD>
273 </TR>
274 % } 
275
276 % my $yes = emt('yes');
277 % my $no = emt('no');
278
279 % my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
280
281 % unless (    $conf->exists('cust_class-tax_exempt')
282 %          || $conf->exists('tax-cust_exempt-groups-require_individual_nums')
283 %        )
284 % {
285     <TR>
286       <TD ALIGN="right"><% mt('Tax exempt') |h %><% @exempt_groups ? ' ('.emt('all taxes').')' : '' %></TD>
287       <TD BGCOLOR="#ffffff"><% $cust_main->tax ? $yes : $no %></TD>
288     </TR>
289 % }
290
291 % foreach my $exempt_group ( @exempt_groups ) {
292 %   my $cust_main_exemption = $cust_main->tax_exemption($exempt_group);
293     <TR>
294       <TD ALIGN="right"><% mt('Tax exempt') |h %> (<% $exempt_group %> taxes)</TD>
295       <TD BGCOLOR="#ffffff"><% $cust_main_exemption ? $yes : $no %>
296         <% $cust_main_exemption ? $cust_main_exemption->exempt_number : '' |h %>
297       </TD>
298     </TR>
299 % }
300
301 % if ( $conf->exists('enable_taxproducts') ) {
302 <TR>
303   <TD ALIGN="right"><% mt('Tax location') |h %></TD>
304 % my $tax_location = $conf->exists('tax-ship_address')
305 %                    ? $cust_main->ship_location
306 %                    : $cust_main->bill_location;
307   <TD BGCOLOR="#ffffff"><% $tax_location->geocode('cch') %></TD>
308 </TR>
309 % }
310 <TR>
311   <TD ALIGN="right"><% mt('Postal mail invoices') |h %></TD>
312   <TD BGCOLOR="#ffffff">
313     <% ( grep { $_ eq 'POST' } @invoicing_list ) ? $yes : $no %>
314   </TD>
315 </TR>
316 <TR>
317   <TD ALIGN="right"><% mt('Fax invoices') |h %></TD>
318   <TD BGCOLOR="#ffffff">
319     <% ( grep { $_ eq 'FAX' } @invoicing_list ) ? $yes : $no %>
320   </TD>
321 </TR>
322 <TR>
323   <TD ALIGN="right"><% mt('Email invoices') |h %></TD>
324   <TD BGCOLOR="#ffffff">
325     <% $cust_main->invoice_noemail ? $no : $yes %>
326   </TD>
327 </TR>
328 % unless ( $conf->exists('cust-email-high-visibility')) {
329 <TR>
330   <TD ALIGN="right"><% mt('Email address(es)') |h %></TD>
331   <TD BGCOLOR="#ffffff">
332     <% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) || $no %>
333 %   if ( $cust_main->message_noemail ) {
334     <BR>
335     <SPAN STYLE="font-size: small"><% emt('(do not send notices)') %></SPAN>
336 %   }
337   </TD>
338 </TR>
339 % }
340 <TR>
341   <TD ALIGN="right"><% mt('Invoice terms') |h %></TD>
342   <TD BGCOLOR="#ffffff">
343     <% $cust_main->invoice_terms
344          || emt('Default').' ('. ( $conf->config('invoice_default_terms', $cust_main->agentnum)
345                                      || emt('Payable upon receipt')
346                                  ).
347                            ')'
348     %>
349   </TD>
350 </TR>
351 <TR>
352   <TD ALIGN="right"><% mt('Credit limit') |h %></TD>
353   <TD BGCOLOR="#ffffff">
354 %   my $default_credit_limit = $conf->config('default_credit_limit');
355     <% length($cust_main->credit_limit)
356          ? $money_char. sprintf("%.2f", $cust_main->credit_limit)
357          : $default_credit_limit
358            ? "Default ($money_char". sprintf("%.2f", $default_credit_limit). ")"
359            : emt('Unlimited')
360     %>
361 %   if ( $cust_main->num_cust_main_credit_limit ) {
362       <A HREF="<% $p %>search/cust_main_credit_limit.html?custnum=<% $cust_main->custnum %>">(incidents)</A>
363 %   }
364   </TD>
365 </TR>
366
367 % if ( $conf->exists('voip-cust_cdr_spools') ) { 
368   <TR>
369     <TD ALIGN="right"><% mt('Spool CDRs') |h %></TD>
370     <TD BGCOLOR="#ffffff"><% $cust_main->spool_cdr ? $yes : $no %></TD>
371   </TR>
372 % } 
373
374 % if ( $conf->exists('voip-cust_cdr_squelch') ) { 
375   <TR>
376     <TD ALIGN="right"><% mt($conf->exists('voip-cdr_email') ? 'Print CDRs' : 'Show CDRs') |h %></TD>
377     <TD BGCOLOR="#ffffff"><% $cust_main->squelch_cdr ? $no : $yes %></TD>
378   </TR>
379 % } 
380
381 % if ( $conf->exists('voip-cust_accountcode_cdr') ) { 
382    <TR>
383      <TD ALIGN="right"><% mt('Breakdown CDRs by accountcode') |h %></TD>
384      <TD BGCOLOR="#ffffff"><% $cust_main->accountcode_cdr ? $yes : $no %></TD>
385    </TR>
386 % }
387
388 % if ( $conf->config('voip-cdr_email_attach') ) { 
389   <TR>
390     <TD ALIGN="right"><% mt('Email CDRs as CSV') |h %></TD>
391     <TD BGCOLOR="#ffffff"><% $cust_main->email_csv_cdr ? $yes : $no %></TD>
392   </TR>
393 % } 
394
395 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
396   <TR>
397     <TD ALIGN="right"><% mt('CDR termination settlement') |h %></TD>
398     <TD BGCOLOR="#ffffff"><% $cust_main->cdr_termination_percentage %><% $cust_main->cdr_termination_percentage =~ /\d/ ? '%' : '' %></TD>
399   </TR>
400 % }
401
402 % if ( $cust_main->locale ) {
403 % my %locale_info = FS::Locales->locale_info($cust_main->locale);
404   <TR>
405     <TD ALIGN="right"><% mt('Invoicing locale') |h %></TD>
406     <TD BGCOLOR="#ffffff"><% $locale_info{name} . " (" . $locale_info{country} .")" %></TD>
407   </TR>
408 % }
409
410
411 </TABLE>
412 <%once>
413
414 my $paystate_label = FS::Msgcat::_gettext('paystate');
415 $paystate_label = 'Bank state' if $paystate_label =~/^paystate$/;
416
417 </%once>
418 <%init>
419
420 my( $cust_main ) = @_;
421 my @invoicing_list = $cust_main->invoicing_list;
422 my $conf = new FS::Conf;
423 my $money_char = $conf->config('money_char') || '$';
424
425 #false laziness w/edit/cust_main/billing.html
426 my $term_sql = "SELECT COUNT(*) FROM cust_pkg LEFT JOIN part_pkg USING ( pkgpart ) WHERE custnum = ? AND plan = 'cdr_termination' LIMIT 1";
427 my $term_sth = dbh->prepare($term_sql)  or die dbh->errstr;
428 $term_sth->execute($cust_main->custnum) or die $term_sth->errstr;
429 my $show_term = $term_sth->fetchrow_arrayref->[0];
430
431 </%init>