X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fmisc%2Fxmlhttp-cust_main-search.cgi;h=86983e462c2bc8c6b72e1b26797d820d2d4540cb;hb=2a7f90bbc8958c0674bb470ecd8e4bed00e6a8c4;hp=c71953ba9307bff35203356b30f6e117050c523f;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/httemplate/misc/xmlhttp-cust_main-search.cgi b/httemplate/misc/xmlhttp-cust_main-search.cgi index c71953ba9..86983e462 100644 --- a/httemplate/misc/xmlhttp-cust_main-search.cgi +++ b/httemplate/misc/xmlhttp-cust_main-search.cgi @@ -1,52 +1,64 @@ -% if ( $sub eq 'custnum_search' ) { -% +% if ( $sub eq 'custnum_search' ) { % my $custnum = $cgi->param('arg'); -% my $cust_main = ''; -% if ( $custnum =~ /^(\d+)$/ and $1 <= 2147483647 ) { -% $cust_main = qsearchs({ -% 'table' => 'cust_main', -% 'hashref' => { 'custnum' => $1 }, -% 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, -% }); -% } -% if ( ! $cust_main ) { -% $cust_main = qsearchs({ -% 'table' => 'cust_main', -% 'hashref' => { 'agent_custid' => $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)); % } -% -"<% $cust_main ? $cust_main->name : '' %>" -% +<% objToJson($return) %> % } elsif ( $sub eq 'smart_search' ) { % % my $string = $cgi->param('arg'); % my @cust_main = smart_search( 'search' => $string, % 'no_fuzzy_on_exact' => 1, #pref? % ); -% my $return = [ map [ $_->custnum, $_->name, $_->balance ], @cust_main ]; +% my $return = [ map [ $_->custnum, $_->name, $_->balance, $_->ucfirst_status, $_->statuscolor, scalar($_->open_cust_bill) ], @cust_main ]; % <% objToJson($return) %> % } elsif ( $sub eq 'invnum_search' ) { % % my $string = $cgi->param('arg'); -% my $inv = qsearchs('cust_bill', { 'invnum' => $string }); +% if ( $string =~ /^(\d+)$/ ) { +% my $inv = qsearchs('cust_bill', { 'invnum' => $1 }); +% my $return = $inv ? findbycustnum($inv->custnum,0) : []; +<% objToJson($return) %> +% } else { #return nothing +[] +% } +% } +% 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 = []; -% if ( $inv ) { -% my $cust_main = qsearchs({ -% 'table' => 'cust_main', -% 'hashref' => { 'custnum' => $inv->custnum }, -% 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, -% }); -% $return = [ $cust_main->custnum, $cust_main->name, $cust_main->balance ]; +% 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, scalar($c->open_cust_bill) ] + if $c; + []; +}