-<TR>
- <TD ALIGN="right">Billing type</TD>
- <TD BGCOLOR="#ffffff">
-% if ( $cust_main->payby eq 'CARD' || $cust_main->payby eq 'DCRD' ) {
-
-
- Credit card <% $cust_main->payby eq 'CARD' ? '(automatic)' : '(on-demand)' %>
- </TD>
-</TR>
-<TR>
- <TD ALIGN="right">Card number</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),
+% }) or next;
+%
+% my $freq_pretty = $cust_pkg[0]->part_pkg->freq_pretty;