summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/Conf.pm3
-rw-r--r--FS/FS/cust_main.pm11
-rw-r--r--FS/FS/cust_main/Search.pm36
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);