From 401ba3ab0637de1bc460370949b75dca092375d8 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Sat, 14 Apr 2012 11:43:08 -0700 Subject: fix various quick payment entry problems, #17356 --- httemplate/misc/xmlhttp-cust_main-search.cgi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'httemplate/misc/xmlhttp-cust_main-search.cgi') diff --git a/httemplate/misc/xmlhttp-cust_main-search.cgi b/httemplate/misc/xmlhttp-cust_main-search.cgi index 68c5bf597..436501e8b 100644 --- a/httemplate/misc/xmlhttp-cust_main-search.cgi +++ b/httemplate/misc/xmlhttp-cust_main-search.cgi @@ -18,9 +18,13 @@ % } 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 -- cgit v1.2.1 From 527b92c4f125282e267863cb102664da57f94ebd Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 26 Apr 2012 11:41:05 -0700 Subject: allocate quick payment only when customer has multiple open invoices, #15861 --- httemplate/misc/xmlhttp-cust_main-search.cgi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'httemplate/misc/xmlhttp-cust_main-search.cgi') diff --git a/httemplate/misc/xmlhttp-cust_main-search.cgi b/httemplate/misc/xmlhttp-cust_main-search.cgi index 436501e8b..86983e462 100644 --- a/httemplate/misc/xmlhttp-cust_main-search.cgi +++ b/httemplate/misc/xmlhttp-cust_main-search.cgi @@ -12,7 +12,7 @@ % my @cust_main = smart_search( 'search' => $string, % 'no_fuzzy_on_exact' => 1, #pref? % ); -% my $return = [ map [ $_->custnum, $_->name, $_->balance, $_->ucfirst_status, $_->statuscolor ], @cust_main ]; +% my $return = [ map [ $_->custnum, $_->name, $_->balance, $_->ucfirst_status, $_->statuscolor, scalar($_->open_cust_bill) ], @cust_main ]; % <% objToJson($return) %> % } elsif ( $sub eq 'invnum_search' ) { @@ -57,7 +57,7 @@ sub findbycustnum{ 'hashref' => $hashref, 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, }); - return [ $c->custnum, $c->name, $c->balance, $c->ucfirst_status, $c->statuscolor ] + return [ $c->custnum, $c->name, $c->balance, $c->ucfirst_status, $c->statuscolor, scalar($c->open_cust_bill) ] if $c; []; } -- cgit v1.2.1 From 15dbf6151b7e6e3b32e55fd6609725f650349460 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 13 Jun 2012 14:34:46 -0700 Subject: quick payment entry: if both a custnum and an agent_custid match, allow the user to pick, RT#18100 --- httemplate/misc/xmlhttp-cust_main-search.cgi | 84 +++++++++++++++++++++------- 1 file changed, 64 insertions(+), 20 deletions(-) (limited to 'httemplate/misc/xmlhttp-cust_main-search.cgi') diff --git a/httemplate/misc/xmlhttp-cust_main-search.cgi b/httemplate/misc/xmlhttp-cust_main-search.cgi index 86983e462..16f7cd2bc 100644 --- a/httemplate/misc/xmlhttp-cust_main-search.cgi +++ b/httemplate/misc/xmlhttp-cust_main-search.cgi @@ -1,9 +1,9 @@ % if ( $sub eq 'custnum_search' ) { % my $custnum = $cgi->param('arg'); % my $return = []; -% if ( $custnum =~ /^(\d+)$/ ) { -% $return = findbycustnum($1,0); -% $return = findbycustnum($1,1) if(!scalar(@$return)); +% if ( $custnum =~ /^(\d+)$/ ) { #should also handle +% # cust_main-agent_custid-format') eq 'ww?d+' +% $return = findbycustnum_or_agent_custid($1); % } <% objToJson($return) %> % } elsif ( $sub eq 'smart_search' ) { @@ -12,7 +12,15 @@ % my @cust_main = smart_search( 'search' => $string, % 'no_fuzzy_on_exact' => 1, #pref? % ); -% my $return = [ map [ $_->custnum, $_->name, $_->balance, $_->ucfirst_status, $_->statuscolor, scalar($_->open_cust_bill) ], @cust_main ]; +% my $return = [ map [ $_->custnum, +% $_->name, +% $_->balance, +% $_->ucfirst_status, +% $_->statuscolor, +% scalar($_->open_cust_bill) +% ], +% @cust_main +% ]; % <% objToJson($return) %> % } elsif ( $sub eq 'invnum_search' ) { @@ -20,7 +28,7 @@ % my $string = $cgi->param('arg'); % if ( $string =~ /^(\d+)$/ ) { % my $inv = qsearchs('cust_bill', { 'invnum' => $1 }); -% my $return = $inv ? findbycustnum($inv->custnum,0) : []; +% my $return = $inv ? findbycustnum($inv->custnum) : []; <% objToJson($return) %> % } else { #return nothing [] @@ -43,22 +51,58 @@ % } <%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; - []; +sub findbycustnum { + + my $c = qsearchs({ + 'table' => 'cust_main', + 'hashref' => { 'custnum' => shift }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, + }) or return []; + + [ $c->custnum, + $c->name, + $c->balance, + $c->ucfirst_status, + $c->statuscolor, + scalar($c->open_cust_bill) + ]; +} + +sub findbycustnum_or_agent_custid { + my $num = shift; + + my @or = ( 'agent_custid = ?' ); + my @param = ( $num ); + + if ( $num =~ /^\d+$/ && $num <= 2147483647 ) { #need a bigint custnum? wow + my $conf = new FS::Conf; + if ( $conf->exists('cust_main-default_agent_custid') ) { + push @or, "( agent_custid IS NULL AND custnum = $num )"; + } else { + push @or, "custnum = $num"; + } + } + + my $extra_sql = ' WHERE '. $FS::CurrentUser::CurrentUser->agentnums_sql. + ' AND ( '. join(' OR ', @or). ' )'; + + [ map [ $_->custnum, + $_->name, + $_->balance, + $_->ucfirst_status, + $_->statuscolor, + scalar($_->open_cust_bill), + ], + + qsearch({ + 'table' => 'cust_main', + 'hashref' => {}, + 'extra_sql' => $extra_sql, + 'extra_param' => \@param, + }) + ]; } + -- cgit v1.2.1