1 % if ( $sub eq 'custnum_search' ) {
2 % my $custnum = $cgi->param('arg');
4 % if ( $custnum =~ /^(\d+)$/ ) { #should also handle
5 % # cust_main-agent_custid-format') eq 'ww?d+'
6 % $return = findbycustnum_or_agent_custid($1);
8 <% objToJson($return) %>
9 % } elsif ( $sub eq 'smart_search' ) {
11 % my $string = $cgi->param('arg');
12 % my @cust_main = smart_search( 'search' => $string,
13 % 'no_fuzzy_on_exact' => ! $FS::CurrentUser::CurrentUser->option('enable_fuzzy_on_exact'),
15 % my $return = [ map [ $_->custnum,
24 <% objToJson($return) %>
25 % } elsif ( $sub eq 'invnum_search' ) {
27 % my $string = $cgi->param('arg');
28 % if ( $string =~ /^(\d+)$/ ) {
29 % my $inv = qsearchs('cust_bill', { 'invnum' => $1 });
30 % my $return = $inv ? findbycustnum($inv->custnum) : [];
31 <% objToJson($return) %>
32 % } else { #return nothing
36 % elsif ( $sub eq 'exact_search' ) {
37 % # XXX possibly should query each element separately
38 % my $hashref = decode_json($cgi->param('arg'));
39 % my @cust_main = qsearch('cust_main', $hashref);
41 % foreach (@cust_main) {
43 % custnum => $_->custnum,
44 % name => $_->name_short,
45 % address1 => $_->address1,
49 <% objToJson($return) %>
53 my $sub = $cgi->param('sub');
58 'table' => 'cust_main',
59 'hashref' => { 'custnum' => shift },
60 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
71 sub findbycustnum_or_agent_custid {
74 my @or = ( 'agent_custid = ?' );
77 if ( $num =~ /^\d+$/ && $num <= 2147483647 ) { #need a bigint custnum? wow
78 my $conf = new FS::Conf;
79 if ( $conf->exists('cust_main-default_agent_custid') ) {
80 push @or, "( agent_custid IS NULL AND custnum = $num )";
82 push @or, "custnum = $num";
86 my $extra_sql = ' WHERE '. $FS::CurrentUser::CurrentUser->agentnums_sql.
87 ' AND ( '. join(' OR ', @or). ' )';
97 'table' => 'cust_main',
99 'extra_sql' => $extra_sql,
100 'extra_param' => \@param,