-% if ( $conf->exists('cust_main-select-billday')
-% && ($cust_main->payby eq 'CARD' || $cust_main->payby eq 'CHEK') ) {
-<TR>
- <TD ALIGN="right"><% mt('Billing day of month') |h %></TD>
- <TD BGCOLOR="#ffffff"><% $cust_main->billday %>
- </TD>
-</TR>
-% }
-
-<TR>
- <TD ALIGN="right"><% mt('Billing type') |h %></TD>
- <TD BGCOLOR="#ffffff">
-% if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) {
-
-% my $autodemand = $cust_main->payby eq 'CARD' ? 'automatic' : 'on-demand';
- <% mt("Credit card ([_1])",$autodemand) |h %>
- </TD>
-</TR>
-<TR>
- <TD ALIGN="right"><% mt('Card number') |h %></TD>
- <TD BGCOLOR="#ffffff"><% $cust_main->paymask %></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;
+
+% #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;