From 987b49fbf7754b4954018e258d27a6ea72499f84 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 10 Oct 2008 01:15:50 +0000 Subject: add options to auto-generate agent_custid and display it as the customer number, RT#4099 --- FS/FS/Conf.pm | 17 +++++++++++++++ FS/FS/UI/Web.pm | 5 ++++- FS/FS/UI/Web/small_custview.pm | 2 +- FS/FS/cust_main.pm | 49 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) (limited to 'FS') diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 610d590d1..46e636b68 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2422,6 +2422,23 @@ worry that config_items is freeside-specific and icky. 'type' => 'checkbox', }, + { + 'key' => 'cust_main-default_agent_custid', + 'section' => 'UI', + 'description' => 'Display the agent_custid field instead of the custnum field.', + 'type' => 'checkbox', + }, + + { + 'key' => 'cust_main-auto_agent_custid', + 'section' => 'UI', + 'description' => 'Automatically assign an agent_custid - select format', + 'type' => 'select', + 'select_hash' => [ '' => 'No', + '1YMMXXXXXXXX' => '1YMMXXXXXXXX', + ], + }, + { 'key' => 'cust_main-default_areacode', 'section' => 'UI', diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm index 2e9261bc0..744d5f793 100644 --- a/FS/FS/UI/Web.pm +++ b/FS/FS/UI/Web.pm @@ -214,6 +214,8 @@ sub cust_header { warn "FS::UI:Web::cust_header called" if $DEBUG; + my $conf = new FS::Conf; + my %header2method = ( 'Customer' => 'name', 'Cust. Status' => 'ucfirst_cust_status', @@ -239,6 +241,8 @@ sub cust_header { 'Payment Type' => 'payby', 'Current Balance' => 'current_balance', ); + $header2method{'Cust#'} = 'display_custnum' + if $conf->exists('cust_main-default_agent_custid'); my %header2colormethod = ( 'Cust. Status' => 'cust_statuscolor', @@ -261,7 +265,6 @@ sub cust_header { } else { - my $conf = new FS::Conf; if ( $conf->exists('cust-fields') && $conf->config('cust-fields') =~ /^([\w\. \|\#\(\)]+):?/ ) diff --git a/FS/FS/UI/Web/small_custview.pm b/FS/FS/UI/Web/small_custview.pm index 079ae9368..f8e202092 100644 --- a/FS/FS/UI/Web/small_custview.pm +++ b/FS/FS/UI/Web/small_custview.pm @@ -33,7 +33,7 @@ sub small_custview { $html = qq!View ' if $url; - $html .= 'Customer #'. $cust_main->custnum. ''. + $html .= 'Customer #'. $cust_main->display_custnum. ''. ' - '. ucfirst($cust_main->status). ''. ntable('#e8e8e8'). ''. ntable("#cccccc",2). diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 225854c06..c048482df 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -343,6 +343,9 @@ sub insert { $self->signupdate(time) unless $self->signupdate; + $self->auto_agent_custid() + if $conf->config('cust_main-auto_agent_custid') && ! $self->agent_custid; + my $error = $self->SUPER::insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -419,6 +422,35 @@ sub insert { } +use File::CounterFile; +sub auto_agent_custid { + my $self = shift; + + my $format = $conf->config('cust_main-auto_agent_custid'); + my $agent_custid; + if ( $format eq '1YMMXXXXXXXX' ) { + + my $counter = new File::CounterFile 'cust_main.agent_custid'; + $counter->lock; + + my $ym = 100000000000 + time2str('%y%m00000000', time); + if ( $ym > $counter->value ) { + $counter->{'value'} = $agent_custid = $ym; + $counter->{'updated'} = 1; + } else { + $agent_custid = $counter->inc; + } + + $counter->unlock; + + } else { + die "Unknown cust_main-auto_agent_custid format: $format"; + } + + $self->agent_custid($agent_custid); + +} + sub start_copy_skel { my $self = shift; @@ -1233,6 +1265,7 @@ sub check { || $self->ut_textn('stateid_state') || $self->ut_textn('invoice_terms') ; + #barf. need message catalogs. i18n. etc. $error .= "Please select an advertising source." if $error =~ /^Illegal or empty \(numeric\) refnum: /; @@ -5051,6 +5084,22 @@ sub cust_refund { qsearch( 'cust_refund', { 'custnum' => $self->custnum } ) } +=item display_custnum + +Returns the displayed customer number for this customer: agent_custid if +cust_main-default_agent_custid is set and it has a value, custnum otherwise. + +=cut + +sub display_custnum { + my $self = shift; + if ( $conf->exists('cust_main-default_agent_custid') && $self->agent_custid ){ + return $self->agent_custid; + } else { + return $self->custnum; + } +} + =item name Returns a name string for this customer, either "Company (Last, First)" or -- cgit v1.2.1