-} else {
-
- #some false laziness w/cust_bill::re_X
- my @where;
- my $orderby = 'ORDER BY cust_bill._date';
-
- if ( $cgi->param('beginning')
- && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
- $search{'begin'} = str2time($1);
- push @where, 'cust_bill._date >= '. $search{'begin'};
- }
- if ( $cgi->param('ending')
- && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
- $search{'end'} = str2time($1) + 86399;
- push @where, 'cust_bill._date < '. $search{'end'};
- }
-
- if ( $cgi->param('begin') =~ /^(\d+)$/ ) {
- $search{'begin'} = $1;
- push @where, 'cust_bill._date >= '. $search{'begin'};
- }
- if ( $cgi->param('end') =~ /^(\d+)$/ ) {
- $search{'end'} = $1;
- push @where, 'cust_bill._date < '. $search{'end'};
- }
-
- if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) {
- $search{'invnum_min'} = $1;
- push @where, 'cust_bill.invnum >= '. $search{'invnum_min'};
- }
- if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) {
- $search{'invnum_max'} = $1;
- push @where, 'cust_bill.invnum <= '. $search{'invnum_max'};
- }
-
- if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
- $search{'agentnum'} = $1;
- push @where, 'cust_main.agentnum = '. $search{'agentnum'};
+ if ( FS::Record->scalar_sql($count_query) == 0 ) {
+
+ # check for a voided invoice
+ $count_query =~ s/cust_bill/cust_bill_void/g;
+ if ( FS::Record->scalar_sql($count_query) > 0 ) {
+ # Redirect to the void search.
+ my $url = $cgi->self_url;
+ $url =~ s(search/cust_bill)(search/cust_bill_void);
+ $m->clear_buffer;
+ $m->print($cgi->redirect($url));
+ $m->abort;
+ }