<FONT CLASS="fsinnerbox-title"><% mt('Billing information') |h %></FONT>
% my $yes = emt('yes');
% my $no = emt('no');
+% my $allowed = emt('allowed');
+% my $refused = emt('refused');
<TABLE CLASS="fsinnerbox">
<TD><B><% $balance %></B></TD>
</TR>
-% #54: just an arbitrary number i pulled out of my goober. ideally we'd like
-% # to consider e.g. a histogram of num_ncancelled_packages for the entire
-% # customer base, and compare it to a graph of the overhead for generating this
-% # information. (and optimize it better, we could get it more from SQL)
-% if ( $cust_main->num_ncancelled_pkgs < 54 ) {
-% my $sth = dbh->prepare("
-% SELECT DISTINCT freq FROM cust_pkg LEFT JOIN part_pkg USING (pkgpart)
-% WHERE freq IS NOT NULL AND freq != '0'
-% AND ( cancel IS NULL OR cancel = 0 )
-% AND custnum = ?
-% ") or die $DBI::errstr;
-%
-% $sth->execute($cust_main->custnum) or die $sth->errstr;
+<TR ID="recurring_row">
+ <TH ID="recurring_label" ALIGN="right"><% emt( 'Recurring' ) %></TH>
+ <TD ID="recurring_value"><IMG SRC="<% $fsurl %>images/wait-orange.gif"></TD>
+</TR>
-% #not really a numeric sort because freqs can actually be all sorts of things
-% # but good enough for the 99% cases of ordering monthly quarterly annually
-% my @freqs = sort { $a <=> $b } map { $_->[0] } @{ $sth->fetchall_arrayref };
-%
-% foreach my $freq (@freqs) {
-% my @cust_pkg = qsearch({
-% 'table' => 'cust_pkg',
-% 'addl_from' => 'LEFT JOIN part_pkg USING (pkgpart)',
-% 'hashref' => { 'custnum' => $cust_main->custnum, },
-% 'extra_sql' => 'AND ( cancel IS NULL OR cancel = 0 )
-% AND freq = '. dbh->quote($freq),
-% 'order_by' => 'ORDER BY COALESCE(start_date,0), pkgnum', # to ensure old pkgs come before change_to_pkg
-% }) or next;
-%
-% my $freq_pretty = $cust_pkg[0]->part_pkg->freq_pretty;
-%
-% my $amount = 0;
-% my $skip_pkg = {};
-% foreach my $cust_pkg (@cust_pkg) {
-% my $part_pkg = $cust_pkg->part_pkg;
-% next if $cust_pkg->susp
-% && ! $cust_pkg->option('suspend_bill')
-% && ( ! $part_pkg->option('suspend_bill')
-% || $cust_pkg->option('no_suspend_bill')
-% );
-%
-% #pkg change handling
-% next if $skip_pkg->{$cust_pkg->pkgnum};
-% if ($cust_pkg->change_to_pkgnum) {
-% #if change is on or before next bill date, use new pkg
-% next if $cust_pkg->expire <= $cust_pkg->bill;
-% #if change is after next bill date, use old (this) pkg
-% $skip_pkg->{$cust_pkg->change_to_pkgnum} = 1;
-% }
-%
-% my $pkg_amount = 0;
-%
-% #add recurring amounts for this package and its billing add-ons
-% foreach my $l_part_pkg ( $part_pkg->self_and_bill_linked ) {
-% $pkg_amount += $l_part_pkg->base_recur($cust_pkg);
-% }
-%
-% #subtract amounts for any active discounts
-% #(there should only be one at the moment, otherwise this makes no sense)
-% foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
-% my $discount = $cust_pkg_discount->discount;
-% #and only one of these for each
-% $pkg_amount -= $discount->amount;
-% $pkg_amount -= $amount * $discount->percent/100;
-% }
-%
-% $pkg_amount *= ( $cust_pkg->quantity || 1 );
-%
-% $amount += $pkg_amount;
-%
-% }
-
- <TR>
- <TH ALIGN="right"><% emt( ucfirst($freq_pretty). ' recurring' ) %></TH>
- <TD><% $money_char. sprintf('%.2f', $amount) %></TD>
- </TD>
- </TR>
-% }
+<& '/elements/xmlhttp.html',
+ 'url' => $fsurl.'misc/xmlhttp-cust_main-display_recurring.html',
+ 'subs' => [ 'get_display_recurring'] &>
+
+<SCRIPT>
+function set_display_recurring (xmlresult) {
+ var recurring = JSON.parse(xmlresult);
+ var rlabel = document.getElementById('recurring_label');
+ var rvalue = document.getElementById('recurring_value');
+ var rrow = document.getElementById('recurring_row');
+ if (recurring['error']) {
+ rvalue.innerHTML = '<SPAN STYLE="color: red">Error</SPAN>';
+ console.log('display_recurring error: ' + recurring['error']);
+ } else if (recurring['display_recurring'].length) {
+ for (var ri = 0; ri < recurring['display_recurring'].length; ri++) {
+ var robj = recurring['display_recurring'][ri];
+ var freq_pretty = robj['freq_pretty'].charAt(0).toUpperCase()+robj['freq_pretty'].slice(1)+' recurring';
+ var amount = '<% $money_char %>'+parseFloat(robj['amount']).toFixed(2);
+ if (ri + 1 < recurring['display_recurring'].length) {
+ var rr = document.createElement('TR');
+ var rl = document.createElement('TH');
+ rl.style.textAlign = 'right';
+ rl.innerHTML = freq_pretty;
+ rr.appendChild(rl);
+ var rv = document.createElement('TD');
+ rv.innerHTML = amount;
+ rr.appendChild(rv);
+ rrow.parentNode.insertBefore(rr,rrow);
+ } else {
+ rlabel.innerHTML = freq_pretty;
+ rvalue.innerHTML = amount;
+ }
+ }
+ } else {
+ rrow.parentNode.removeChild(rrow);
+ }
+}
+</SCRIPT>
+% # 10 is an arbitrary number, use ajax for customers with many packages
+% if ( $cust_main->num_billing_pkgs > 10 ) {
+<& '/elements/xmlhttp.html',
+ 'url' => $fsurl.'misc/xmlhttp-cust_main-display_recurring.html',
+ 'subs' => [ 'get_display_recurring'] &>
+<SCRIPT>
+get_display_recurring('custnum',<% $cust_main->custnum %>,set_display_recurring);
+</SCRIPT>
+% } else {
+<SCRIPT>
+set_display_recurring(<% encode_json({'display_recurring' => [ $cust_main->display_recurring ]}) |js_string %>);
+</SCRIPT>
% }
% if ( $conf->exists('cust_main-select-prorate_day') ) {
<TR>
<TH ALIGN="right"><% mt('Prorate day of month') |h %></TH>
<TD><% $cust_main->prorate_day %>
+ <% $cust_main->force_prorate_day && ('<i>'.emt('(applies to all packages)').'</i>') %>
</TD>
</TR>
% }
</TR>
% }
-% if ( $conf->config('tax_data_vendor') eq 'cch' ) {
+% if ( $conf->config('tax_data_vendor') ) {
<TR>
<TH ALIGN="right"><% mt('Tax location') |h %></TH>
% my $tax_location = $conf->exists('tax-ship_address')
% ? $cust_main->ship_location
% : $cust_main->bill_location;
- <TD><% $tax_location->geocode('cch') %></TD>
+ <TD><% $tax_location && $tax_location->geocode %></TD>
</TR>
% }
<TR>
<TH ALIGN="right"><% mt('Postal mail invoices') |h %></TH>
- <TD>
- <% ( grep { $_ eq 'POST' } @invoicing_list )
- ? $yes. ( $cust_main->invoice_attn
+% if ( $cust_main->postal_invoice ) {
+ <TD><% $yes . ( $cust_main->invoice_attn
? ', attn: '. $cust_main->invoice_attn
: ''
- )
- : $no
- %>
+ ) %>
+ </TD>
+% } elsif ( $cust_main->invoice_noemail
+% or scalar(@invoicing_list) == 0 ) {
+% # alert the user that this customer has no way to receive an invoice
+ <TD CLASS="error"><% $no %></TD>
+% } else {
+ <TD><% $no %></TD>
+% }
</TD>
</TR>
<TR>
<TH ALIGN="right"><% mt('Email invoices') |h %></TH>
- <TD>
- <% $cust_main->invoice_noemail ? $no : $yes %>
- </TD>
+% if ( $cust_main->invoice_noemail and ! $cust_main->postal_invoice ) {
+% # as above, warn if the customer refuses both email and postal invoices
+ <TD CLASS="error"><% $refused %></TD>
+% } else {
+ <TD><% $cust_main->invoice_noemail ? $refused : $allowed %></TD>
+% }
</TR>
-% unless ( $conf->exists('cust-email-high-visibility')) {
+% if ( $conf->config_bool('allow_payment_receipt_noemail', $cust_main->agentnum) ) {
<TR>
- <TH ALIGN="right"><% mt('Email address(es)') |h %></TH>
+ <TH ALIGN="right"><% mt('Email payment receipts') |h %></TH>
+ <TD><% $cust_main->paymentreceipt_noemail ? $refused : $allowed %></TD>
+</TR>
+% }
+<TR>
+ <TH ALIGN="right"><% mt('Other email notices') |h %></TH>
<TD>
- <% join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list ) || $no %>
-% if ( $cust_main->message_noemail ) {
- <BR>
- <SPAN STYLE="font-size: small"><% emt('(do not send notices)') %></SPAN>
-% }
+ <% $cust_main->message_noemail ? $refused : $allowed %>
</TD>
</TR>
-% }
<TR>
<TH ALIGN="right"><% mt('Invoice terms') |h %></TH>
<TD>
</TD>
</TR>
-% if ( $conf->exists('voip-cust_cdr_spools') ) {
- <TR>
- <TH ALIGN="right"><% mt('Spool CDRs') |h %></TH>
- <TD><% $cust_main->spool_cdr ? $yes : $no %></TD>
- </TR>
-% }
-
% if ( $conf->exists('voip-cust_cdr_squelch') ) {
<TR>
<TH ALIGN="right"><% mt($conf->exists('voip-cdr_email') ? 'Print CDRs' : 'Show CDRs') |h %></TH>
</TR>
% }
-% if ( $conf->exists('voip-cust_email_csv_cdr') ) {
+% if ( my $attach = $conf->config('voip-cdr_email_attach') ) {
<TR>
- <TH ALIGN="right"><% mt('Email CDRs as CSV') |h %></TH>
+ <TH ALIGN="right"><% mt('Email CDRs as '.uc($attach)) |h %></TH>
<TD><% $cust_main->email_csv_cdr ? $yes : $no %></TD>
</TR>
% }
<%init>
my( $cust_main ) = @_;
-my @invoicing_list = $cust_main->invoicing_list;
+my @invoicing_list = $cust_main->invoicing_list_emailonly;
my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';