From 18459c4369f63b7fda11a3ff7a0af067bed0c9bf Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 13 Apr 2012 12:08:40 -0700 Subject: [PATCH] adjustment to display_custnum special format, #16815 --- FS/FS/Conf.pm | 3 ++- FS/FS/cust_main.pm | 11 +++++++++-- FS/FS/cust_main/Search.pm | 36 ++++++++++++++++++++---------------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 80c034890..edfe3c27a 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -3889,7 +3889,7 @@ and customer address. Include units.', 'section' => 'UI', 'description' => 'Prefix the customer number with this string for display purposes.', 'type' => 'text', - #and then probably agent-virt this to merge these instances + 'per_agent' => 1, }, { @@ -3898,6 +3898,7 @@ and customer address. Include units.', 'description' => 'Use this customer number prefix format', 'type' => 'select', 'select_hash' => [ '' => '', + 'CoStAg' => 'CoStAg (country, state, agent name or display_prefix)', 'CoStCl' => 'CoStCl (country, state, class name)' ], }, diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 1e0e6d3b1..845d09848 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -3963,9 +3963,16 @@ cust_main-default_agent_custid is set and it has a value, custnum otherwise. sub display_custnum { my $self = shift; - my $prefix = $conf->config('cust_main-custnum-display_prefix') || ''; + my $prefix = $conf->config('cust_main-custnum-display_prefix', $self->agentnum) || ''; if ( my $special = $conf->config('cust_main-custnum-display_special') ) { - if ( $special eq 'CoStCl' ) { + if ( $special eq 'CoStAg' ) { + $prefix = uc( join('', + $self->country, + ($self->state =~ /^(..)/), + $prefix || ($self->agent->agent =~ /^(..)/) + ) ); + } + elsif ( $special eq 'CoStCl' ) { $prefix = uc( join('', $self->country, ($self->state =~ /^(..)/), diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 62464e4aa..1e9eee79d 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -127,6 +127,12 @@ sub smart_search { || ( $conf->config('cust_main-agent_custid-format') eq 'ww?d+' && $search =~ /^\s*(\w\w?\d+)\s*$/ ) + || ( $conf->config('cust_main-custnum-display_special') + # it's not currently possible for special prefixes to contain + # digits, so just strip off any alphabetic prefix and match + # the rest to custnum + && $search =~ /^\s*[[:alpha:]]*(\d+)\s*$/ + ) || ( $conf->exists('address1-search' ) && $search =~ /^\s*(\d+\-?\w*)\s*$/ #i.e. 1234A or 9432-D ) @@ -143,25 +149,23 @@ sub smart_search { } ); } - #if this becomes agent-virt need to get a list of all prefixes the current - #user can see (via their agents) - my $prefix = $conf->config('cust_main-custnum-display_prefix'); - if ( $prefix && $prefix eq substr($num, 0, length($prefix)) ) { - push @cust_main, qsearch( { - 'table' => 'cust_main', - 'hashref' => { 'custnum' => 0 + substr($num, length($prefix)), - %options, + # for all agents this user can see, if any of them have custnum prefixes + # that match the search string, include customers that match the rest + # of the custnum and belong to that agent + foreach my $agentnum ( $FS::CurrentUser::CurrentUser->agentnums ) { + my $p = $conf->config('cust_main-custnum-display_prefix', $agentnum); + next if !$p; + if ( $p eq substr($num, 0, length($p)) ) { + push @cust_main, qsearch( { + 'table' => 'cust_main', + 'hashref' => { 'custnum' => 0 + substr($num, length($p)), + 'agentnum' => $agentnum, + %options, }, - 'extra_sql' => " AND $agentnums_sql", #agent virtualization - } ); + } ); + } } - push @cust_main, qsearch( { - 'table' => 'cust_main', - 'hashref' => { 'agent_custid' => $num, %options }, - 'extra_sql' => " AND $agentnums_sql", #agent virtualization - } ); - if ( $conf->exists('address1-search') ) { my $len = length($num); $num = lc($num); -- 2.11.0