if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
my($open, $days, $field) = ($1, $2, $3);
$field = "_date" if $field eq 'date';
$orderby = "ORDER BY cust_bill.$field";
push @where, "0 != $owed" if $open;
push @where, "cust_bill._date < ". (time-86400*$days) if $days;
if ( $query =~ /^(OPEN(\d*)_)?(invnum|date|custnum)$/ ) {
my($open, $days, $field) = ($1, $2, $3);
$field = "_date" if $field eq 'date';
$orderby = "ORDER BY cust_bill.$field";
push @where, "0 != $owed" if $open;
push @where, "cust_bill._date < ". (time-86400*$days) if $days;