X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fmisc%2Fxmlhttp-cust_main-search.cgi;h=68c5bf59737076e54060d441198a6bad5b1232fb;hb=fec48523d3cf056da08813f9b2b7d633b27aaf8d;hp=26e68b5d87d9808581a46517bb4f772304165f2f;hpb=40a7b3dc653e099f7bd0bd762b649b04c4432db2;p=freeside.git diff --git a/httemplate/misc/xmlhttp-cust_main-search.cgi b/httemplate/misc/xmlhttp-cust_main-search.cgi index 26e68b5d8..68c5bf597 100644 --- a/httemplate/misc/xmlhttp-cust_main-search.cgi +++ b/httemplate/misc/xmlhttp-cust_main-search.cgi @@ -1,36 +1,60 @@ -% if ( $sub eq 'custnum_search' ) { -% +% if ( $sub eq 'custnum_search' ) { % my $custnum = $cgi->param('arg'); -% my $cust_main = ''; -% if ( $custnum <= 2147483647 ) { -% $cust_main = qsearchs({ -% 'table' => 'cust_main', -% 'hashref' => { 'custnum' => $custnum }, -% 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, -% }); +% my $return = []; +% if ( $custnum =~ /^(\d+)$/ ) { +% $return = findbycustnum($1,0); +% $return = findbycustnum($1,1) if(!scalar(@$return)); % } -% if ( ! $cust_main ) { -% $cust_main = qsearchs({ -% 'table' => 'cust_main', -% 'hashref' => { 'agent_custid' => $custnum }, -% 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, -% }); -% } -% -"<% $cust_main ? $cust_main->name : '' %>" -% +<% objToJson($return) %> % } elsif ( $sub eq 'smart_search' ) { % % my $string = $cgi->param('arg'); -% my @cust_main = smart_search( 'search' => $string ); -% my $return = [ map [ $_->custnum, $_->name ], @cust_main ]; +% my @cust_main = smart_search( 'search' => $string, +% 'no_fuzzy_on_exact' => 1, #pref? +% ); +% my $return = [ map [ $_->custnum, $_->name, $_->balance, $_->ucfirst_status, $_->statuscolor ], @cust_main ]; % <% objToJson($return) %> +% } elsif ( $sub eq 'invnum_search' ) { +% +% my $string = $cgi->param('arg'); +% my $inv = qsearchs('cust_bill', { 'invnum' => $string }); +% my $return = $inv ? findbycustnum($inv->custnum,0) : []; +<% objToJson($return) %> % } +% 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, +% }; +% } +<% objToJson($return) %> +% } <%init> my $conf = new FS::Conf; my $sub = $cgi->param('sub'); +sub findbycustnum{ + my $custnum = shift; + my $agent = shift; + my $hashref = { 'custnum' => $custnum }; + $hashref = { 'agent_custid' => $custnum } if $agent; + my $c = qsearchs({ + 'table' => 'cust_main', + 'hashref' => $hashref, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, + }); + return [ $c->custnum, $c->name, $c->balance, $c->ucfirst_status, $c->statuscolor ] + if $c; + []; +}