-% #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),
-% }) or next;
-%
-% my $freq_pretty = $cust_pkg[0]->part_pkg->freq_pretty;
-%
-% my $amount = 0;
-% 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')
-% );
-%
-% #add recurring amounts for this package and its billing add-ons
-% foreach my $l_part_pkg ( $part_pkg->self_and_bill_linked ) {
-% $amount += $l_part_pkg->option('recur_fee');
-% }
-%
-% #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
-% $amount -= $discount->amount;
-% $amount -= $amount * $discount->percent/100;
-% }
-%
-% }
-
- <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>