Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / misc / xmlhttp-cust_main-search.cgi
index 6f02312..436501e 100644 (file)
 % } elsif ( $sub eq 'invnum_search' ) {
 %
 %   my $string = $cgi->param('arg');
-%   my $inv = qsearchs('cust_bill', { 'invnum' => $string });
-%   my $return = $inv ? findbycustnum($inv->custnum,0) : [];
+%   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 = [];
+%   foreach (@cust_main) {
+%     push @$return, {
+%       custnum => $_->custnum,
+%       name => $_->name_short,
+%       address1 => $_->address1,
+%       city => $_->city,
+%     };
+%   }
+<% objToJson($return) %>
+% }
 <%init>
 
 my $conf = new FS::Conf;