allocate quick payment only when customer has multiple open invoices, #15861
[freeside.git] / httemplate / misc / xmlhttp-cust_main-search.cgi
1 % if ( $sub eq 'custnum_search' ) { 
2 %   my $custnum = $cgi->param('arg');
3 %   my $return = [];
4 %   if ( $custnum =~ /^(\d+)$/ ) {
5 %       $return = findbycustnum($1,0);
6 %       $return = findbycustnum($1,1) if(!scalar(@$return));
7 %   }
8 <% objToJson($return) %>
9 % } elsif ( $sub eq 'smart_search' ) {
10 %
11 %   my $string = $cgi->param('arg');
12 %   my @cust_main = smart_search( 'search' => $string,
13 %                                 'no_fuzzy_on_exact' => 1, #pref?
14 %                               );
15 %   my $return = [ map [ $_->custnum, $_->name, $_->balance, $_->ucfirst_status, $_->statuscolor, scalar($_->open_cust_bill) ], @cust_main ];
16 %     
17 <% objToJson($return) %>
18 % } elsif ( $sub eq 'invnum_search' ) {
19 %
20 %   my $string = $cgi->param('arg');
21 %   if ( $string =~ /^(\d+)$/ ) {
22 %     my $inv = qsearchs('cust_bill', { 'invnum' => $1 });
23 %     my $return = $inv ? findbycustnum($inv->custnum,0) : [];
24 <% objToJson($return) %>
25 %   } else { #return nothing
26 []
27 %   }
28 % } 
29 % elsif ( $sub eq 'exact_search' ) {
30 %   # XXX possibly should query each element separately
31 %   my $hashref = decode_json($cgi->param('arg'));
32 %   my @cust_main = qsearch('cust_main', $hashref);
33 %   my $return = [];
34 %   foreach (@cust_main) {
35 %     push @$return, {
36 %       custnum => $_->custnum,
37 %       name => $_->name_short,
38 %       address1 => $_->address1,
39 %       city => $_->city,
40 %     };
41 %   }
42 <% objToJson($return) %>
43 % }
44 <%init>
45
46 my $conf = new FS::Conf;
47
48 my $sub = $cgi->param('sub');
49
50 sub findbycustnum{
51     my $custnum = shift;
52     my $agent = shift;
53     my $hashref = { 'custnum' => $custnum };
54     $hashref = { 'agent_custid' => $custnum } if $agent;
55     my $c = qsearchs({
56         'table'   => 'cust_main',
57         'hashref' => $hashref,
58         'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
59                 });
60    return [ $c->custnum, $c->name, $c->balance, $c->ucfirst_status, $c->statuscolor, scalar($c->open_cust_bill) ] 
61         if $c;
62    [];
63 }
64 </%init>