+% elsif ( $sub eq 'exact_search' ) {
+% # XXX possibly should query each element separately
+% my $hashref = decode_json($cgi->param('arg'));
+% my @cust_main = qsearch('cust_main', $hashref);
+% my $return = [];
+% foreach (@cust_main) {
+% push @$return, {
+% custnum => $_->custnum,
+% name => $_->name_short,
+% address1 => $_->address1,
+% city => $_->city,
+% };
+% }
+<% encode_json($return) %>\
+% }
+<%init>
+
+my $sub = $cgi->param('sub');
+
+sub findbycustnum {
+
+ my $c = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => { 'custnum' => shift },
+ 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+ }) or return [];
+
+ [ $c->custnum,
+ $c->name,
+ $c->balance,
+ $c->status_label,
+ $c->statuscolor,
+ scalar($c->open_cust_bill),
+ $c->display_custnum,
+ ];
+}
+
+sub findbycustnum_or_agent_custid {
+ my $num = shift;
+
+ my @or = ( 'agent_custid = ?' );
+ my @param = ( $num );
+
+ if ( $num =~ /^\d+$/ && $num <= 2147483647 ) { #need a bigint custnum? wow
+ my $conf = new FS::Conf;
+ if ( $conf->exists('cust_main-default_agent_custid') ) {
+ push @or, "( agent_custid IS NULL AND custnum = $num )";
+ } else {
+ push @or, "custnum = $num";
+ }
+ }