From 51d044c74ff531b744a6b570fe4a178654a0e7da Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 19 Oct 2008 00:38:09 +0000 Subject: [PATCH] add a master custnum field to agents, RT#2933 (roundabout) --- FS/FS/Schema.pm | 6 ++-- FS/FS/agent.pm | 29 +++++++++++++++--- httemplate/browse/agent.cgi | 12 ++++++++ httemplate/edit/agent.cgi | 12 ++++++++ httemplate/elements/search-cust_main.html | 51 ++++++++++++++++++++----------- 5 files changed, 85 insertions(+), 25 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 0b121db3e..941eafc7f 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -332,17 +332,17 @@ sub tables_hashref { 'agentnum', 'serial', '', '', '', '', 'agent', 'varchar', '', $char_d, '', '', 'typenum', 'int', '', '', '', '', - 'disabled', 'char', 'NULL', 1, '', '', 'ticketing_queueid', 'int', 'NULL', '', '', '', 'invoice_template', 'varchar', 'NULL', $char_d, '', '', + 'agent_custnum', 'int', 'NULL', '', '', '', + 'disabled', 'char', 'NULL', 1, '', '', 'username', 'varchar', 'NULL', $char_d, '', '', #deprecated '_password', 'varchar', 'NULL', $char_d, '', '', #deprecated 'freq', 'int', 'NULL', '', '', '', #deprecated (never used) 'prog', @perl_type, '', '', #deprecated (never used) - ], 'primary_key' => 'agentnum', - 'unique' => [], + 'unique' => [ [ 'agent_custnum' ] ], #one agent per customer? 'index' => [ ['typenum'], ['disabled'] ], }, diff --git a/FS/FS/agent.pm b/FS/FS/agent.pm index 57cc94563..4166a7cac 100644 --- a/FS/FS/agent.pm +++ b/FS/FS/agent.pm @@ -48,17 +48,23 @@ from FS::Record. The following fields are currently supported: =item agent - Text name of this agent -=item typenum - Agent type. See L +=item typenum - Agent type (see L) -=item prog - For future use. +=item ticketing_queueid - Ticketing Queue -=item freq - For future use. +=item invoice_template - Invoice template name + +=item agent_custnum - Optional agent customer (see L) =item disabled - Disabled flag, empty or 'Y' -=item username - Username for the Agent interface +=item prog - Deprecated (never used) + +=item freq - Deprecated (never used) + +=item username - (Deprecated) Username for the Agent interface -=item _password - Password for the Agent interface +=item _password - (Deprecated) Password for the Agent interface =back @@ -118,6 +124,7 @@ sub check { || $self->ut_numbern('freq') || $self->ut_textn('prog') || $self->ut_textn('invoice_template') + || $self->ut_foreign_keyn('agent_custnum', 'cust_main', 'custnum' ) ; return $error if $error; @@ -156,6 +163,18 @@ sub agent_type { qsearchs( 'agent_type', { 'typenum' => $self->typenum } ); } +=item agent_cust_main + +Returns the FS::cust_main object (see L), if any, for this +agent. + +=cut + +sub agent_cust_main { + my $self = shift; + qsearchs( 'cust_main', { 'custnum' => $self->agent_custnum } ); +} + =item pkgpart_hashref Returns a hash reference. The keys of the hash are pkgparts. The value is diff --git a/httemplate/browse/agent.cgi b/httemplate/browse/agent.cgi index 234bfa74a..89739f00b 100755 --- a/httemplate/browse/agent.cgi +++ b/httemplate/browse/agent.cgi @@ -26,6 +26,7 @@ full offerings (via their type).

param('showdisabled') || !dbdef->table('agent')->column('disabled') ) ? 2 : 3 %>>Agent Type + Master Customer Invoice
Template
Customers Customer
packages
@@ -84,6 +85,17 @@ full offerings (via their type).

<% $agent->agent_type->atype %> + +% if ( $agent->agent_custnum ) { + <% include('/elements/small_custview.html', + $agent->agent_custnum, + scalar($conf->config('countrydefault')), + 1, #show balance + ) + %> +% } + + <% $agent->invoice_template || '(Default)' %> diff --git a/httemplate/edit/agent.cgi b/httemplate/edit/agent.cgi index 11bfc5932..0c2520510 100755 --- a/httemplate/edit/agent.cgi +++ b/httemplate/edit/agent.cgi @@ -30,6 +30,18 @@ Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %> + Master customer + + <% include('/elements/search-cust_main.html', + 'field_name' => 'agent_custnum', + 'curr_value' => $agent->agent_custnum, + 'find_button' => 1, + ) + %> + + + + Disable disabled eq 'Y' ? ' CHECKED' : '' %>> diff --git a/httemplate/elements/search-cust_main.html b/httemplate/elements/search-cust_main.html index f2b17eacb..dbcc2ed0b 100644 --- a/httemplate/elements/search-cust_main.html +++ b/httemplate/elements/search-cust_main.html @@ -1,23 +1,24 @@ -% -% my( %opt ) = @_; -% $opt{'field_name'} ||= 'custnum'; -% -% my $cust_main = ''; -% if ( $opt{'value'} ) { -% $cust_main = qsearchs( -% 'table' => 'cust_main', -% 'hashref' => { 'custnum' => $opt{'value'} }, -% 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql, -% ); -% } -% - - - + - + + +% if ( $opt{'find_button'} ) { + +% } @@ -161,4 +162,20 @@ } +<%init> +my( %opt ) = @_; +$opt{'field_name'} ||= 'custnum'; + +my $value = $opt{'curr_value'} || $opt{'value'}; + +my $cust_main = ''; +if ( $value ) { + $cust_main = qsearchs({ + 'table' => 'cust_main', + 'hashref' => { 'custnum' => $value }, + 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql, + }); +} + + -- 2.11.0