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 --- httemplate/edit/cust_main.cgi | 2 +- httemplate/index.html | 2 +- httemplate/search/cust_main.cgi | 15 ++++++++--- httemplate/view/cust_main/misc.html | 50 ++++++++++++++++++------------------- 4 files changed, 38 insertions(+), 31 deletions(-) (limited to 'httemplate') diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 10086a4dd..8de73c513 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -12,7 +12,7 @@ % if ( $custnum ) { - Customer #<% $custnum %> - + Customer #<% $cust_main->display_custnum %> - <% ucfirst($cust_main->status) %> diff --git a/httemplate/index.html b/httemplate/index.html index 60ab26f86..c813991f9 100644 --- a/httemplate/index.html +++ b/httemplate/index.html @@ -36,7 +36,7 @@ % next unless $cust_main; - <% $custnum %>: <% $cust_main->name %> + <% $cust_main->display_custnum %>: <% $cust_main->name %> % if ( $bgcolor eq $bgcolor1 ) { diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index 1ddafae0b..36e4374ee 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -62,8 +62,13 @@ % if ( $cgi->param('browse') ) { % my $query = $cgi->param('browse'); % if ( $query eq 'custnum' ) { -% $sortby=\*custnum_sort; -% $orderby = "ORDER BY custnum"; +% if ( $conf->exists('cust_main-default_agent_custid') ) { +% $sortby=\*display_custnum_sort; +% $orderby = "ORDER BY CASE WHEN agent_custid IS NOT NULL AND agent_custid != '' THEN CAST(agent_custid AS BIGINT) ELSE custnum END"; +% } else { +% $sortby=\*custnum_sort; +% $orderby = "ORDER BY custnum"; +% } % } elsif ( $query eq 'last' ) { % $sortby=\*last_sort; % $orderby = "ORDER BY LOWER(last || ' ' || first)"; @@ -379,7 +384,7 @@ % my $statuscol = $cust_main->statuscolor; - ><% $custnum %> + ><% $cust_main->display_custnum %> ><% ucfirst($status) %> ><% "$last, $first" %> ><% $pcompany %> @@ -538,6 +543,10 @@ % || lc($a->first) cmp lc($b->first);; %} % +%sub display_custnum_sort { +% $a->display_custnum <=> $b->display_custnum; +%} +% %sub custnum_sort { % $a->getfield('custnum') <=> $b->getfield('custnum'); %} diff --git a/httemplate/view/cust_main/misc.html b/httemplate/view/cust_main/misc.html index 9528db243..060da87dd 100644 --- a/httemplate/view/cust_main/misc.html +++ b/httemplate/view/cust_main/misc.html @@ -1,41 +1,29 @@ -% -% my( $cust_main ) = @_; -% my $conf = new FS::Conf; -% my $date_format = ($conf->config('date_format') || "%m/%d/%Y"); -% - - <% ntable("#cccccc") %><% &ntable("#cccccc",2) %> Customer number - <% $cust_main->custnum %> + <% $cust_main->display_custnum %> Status <% ucfirst($cust_main->status) %> -% -% my @agents = qsearch( 'agent', {} ); -% my $agent; -% unless ( scalar(@agents) == 1 ) { -% $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } ); -% +%my $agent; +%if ( $num_agents == 1 ) { +% my @agents = qsearchs( 'agent', {} ); +% $agent = $agents[0]; +%} else { +% $agent = qsearchs('agent',{ 'agentnum' => $cust_main->agentnum } ); + + Agent + <% $agent->agentnum %>: <% $agent->agent %> + +% } - - Agent - <% $agent->agentnum %>: <% $agent->agent %> - -% -% } else { -% $agent = $agents[0]; -% } -% -% if ( $cust_main->agent_custid ) { -% - +% if ( $cust_main->agent_custid +% && ! $conf->exists('cust_main-default_agent_custid') ) { Agent customer ref# @@ -109,4 +97,14 @@ % } +<%init> + +my( $cust_main ) = @_; +my $conf = new FS::Conf; +my $date_format = ($conf->config('date_format') || "%m/%d/%Y"); + +my $sth = dbh->prepare('SELECT COUNT(*) FROM agent') or die dbh->errstr; +$sth->execute or die $sth->errstr; +my $num_agents = $sth->fetchrow_arrayref->[0]; + -- cgit v1.2.1