$title .= 'Customer Accounting Summary Report';
-my @custs = ();
-@custs = qsearch('cust_main', {} );
-
my @items = ('netsales', 'cashflow');
my @params = ( [], [] );
my $setuprecur = '';
my $status = $cgi->param('status');
die "invalid status" unless $status =~ /^\w+|$/;
+my %search_hash;
+foreach (qw(agentnum refnum status)) {
+ if ( defined $cgi->param($_) ) {
+ $search_hash{$_} = $cgi->param($_);
+ }
+}
+$search_hash{'classnum'} = [ $cgi->param('cust_classnum') ]
+ if grep { $_ eq 'cust_classnum' } $cgi->param;
+
+my $query = FS::cust_main::Search->search(\%search_hash);
+my @custs = qsearch($query);
+
foreach my $cust_main ( @custs ) {
# XXX should do this in the qsearch
next unless ($status eq '' || $status eq $cust_main->status);