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 <% encode_json($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,
20 % scalar($_->open_cust_bill),
21 % $_->display_custnum,
26 <% encode_json($return) %>\
27 % } elsif ( $sub eq 'invnum_search' ) {
29 % my $string = $cgi->param('arg');
30 % if ( $string =~ /^(\d+)$/ ) {
31 % my $inv = qsearchs('cust_bill', { 'invnum' => $1 });
32 % my $return = $inv ? findbycustnum($inv->custnum) : [];
33 <% encode_json($return) %>\
34 % } else { #return nothing
38 % elsif ( $sub eq 'exact_search' ) {
39 % # XXX possibly should query each element separately
40 % my $hashref = decode_json($cgi->param('arg'));
41 % my @cust_main = qsearch('cust_main', $hashref);
43 % foreach (@cust_main) {
45 % custnum => $_->custnum,
46 % name => $_->name_short,
47 % address1 => $_->address1,
51 <% encode_json($return) %>\
55 my $sub = $cgi->param('sub');
60 'table' => 'cust_main',
61 'hashref' => { 'custnum' => shift },
62 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
70 scalar($c->open_cust_bill),
75 sub findbycustnum_or_agent_custid {
78 my @or = ( 'agent_custid = ?' );
81 if ( $num =~ /^\d+$/ && $num <= 2147483647 ) { #need a bigint custnum? wow
82 my $conf = new FS::Conf;
83 if ( $conf->exists('cust_main-default_agent_custid') ) {
84 push @or, "( agent_custid IS NULL AND custnum = $num )";
86 push @or, "custnum = $num";
90 my $extra_sql = ' WHERE '. $FS::CurrentUser::CurrentUser->agentnums_sql.
91 ' AND ( '. join(' OR ', @or). ' )';
98 scalar($_->open_cust_bill),
103 'table' => 'cust_main',
105 'extra_sql' => $extra_sql,
106 'extra_param' => \@param,