From e47e9758f480c664bfc3917d798cd69c7d354999 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 11 Aug 2006 08:02:26 +0000 Subject: virtualize referrals on customer addition --- httemplate/browse/part_referral.html | 29 +++++---- httemplate/edit/cust_main.cgi | 80 +++++++++--------------- httemplate/elements/select-agent.html | 8 +-- httemplate/elements/select-part_referral.html | 17 +++++ httemplate/elements/tr-select-agent.html | 10 ++- httemplate/elements/tr-select-part_referral.html | 30 +++++++++ 6 files changed, 102 insertions(+), 72 deletions(-) create mode 100644 httemplate/elements/select-part_referral.html create mode 100644 httemplate/elements/tr-select-part_referral.html (limited to 'httemplate') diff --git a/httemplate/browse/part_referral.html b/httemplate/browse/part_referral.html index 468593160..c50a406ed 100755 --- a/httemplate/browse/part_referral.html +++ b/httemplate/browse/part_referral.html @@ -32,7 +32,7 @@ Where a customer heard about your service. Tracked for informational purposes. 'Total' => 86400, # 60sec * 60min * 24hrs ); - $extra_sql = " WHERE ". FS::part_referral->acl_agentnum_sql; + my $curuser = $FS::CurrentUser::CurrentUser; my $statement = "SELECT COUNT(*) FROM h_cust_main WHERE history_action = 'insert' @@ -67,14 +67,7 @@ Where a customer heard about your service. Tracked for informational purposes. <% -foreach my $part_referral ( - - qsearch({ - 'table' => 'part_referral', - 'extra_sql' => "$extra_sql ORDER BY refnum", - }) - -) { +foreach my $part_referral ( FS::part_referral->all_part_referral(1) ) { if ( $bgcolor eq $bgcolor1 ) { $bgcolor = $bgcolor2; @@ -82,13 +75,23 @@ foreach my $part_referral ( $bgcolor = $bgcolor1; } + $a = 0; + %> - - <%= $part_referral->refnum %> - - <%= $part_referral->referral %> + + <% if ( $part_referral->agentnum || $curuser->access_right('Edit global advertising sources') ) { + $a++; + %> + + <% } %> + <%= $part_referral->refnum %><%= $a ? '' : '' %> + + <% if ( $a ) { %> + + <% } %> + <%= $part_referral->referral %><%= $a ? '' : '' %> <% if ( $show_agentnums ) { %> <%= $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %> diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index bb2a8618e..45cb69fc2 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -66,6 +66,8 @@ if ( $cgi->param('error') ) { $cgi->delete_all(); my $action = $custnum ? 'Edit' : 'Add'; +my $r = qq!* !; + %> @@ -77,38 +79,29 @@ my $action = $custnum ? 'Edit' : 'Add'; ) %> <% if ( $error ) { %> -Error: <%= $error %> +Error: <%= $error %>

<% } %>
-Customer # <%= $custnum ? "$custnum" : " (NEW)" %> - - - -<% +<% if ( $custnum ) { %> + Customer #<%= $custnum %> - + + <%= ucfirst($cust_main->status) %> + +

+<% } %> -my $r = qq!* !; +<%= &ntable("#cccccc") %> -my %agent_search = dbdef->table('agent')->column('disabled') - ? ( 'disabled' => '' ) : (); -my @agents = qsearch( 'agent', \%agent_search ); -#die "No agents created!" unless @agents; -eidiot "You have not created any agents (or all agents are disabled). You must create at least one agent before adding a customer. Go to ". popurl(2). "browse/agent.cgi and create one or more agents." unless @agents; -my $agentnum = $cust_main->agentnum || $agents[0]->agentnum; #default to first + +<%= include('/elements/tr-select-agent.html', $cust_main->agentnum, + 'label' => "${r}Agent", + 'empty_label' => 'Select agent', + ) %> -<% if ( scalar(@agents) == 1 ) { %> - -<% } else { %> -

<%=$r%>Agent -<% } %> - <% @@ -118,28 +111,9 @@ if ( $custnum && ! $conf->exists('editreferrals') ) { -<% - } else { - - my(@referrals) = qsearch('part_referral',{}); - if ( scalar(@referrals) == 0 ) { - eidiot "You have not created any advertising sources. You must create at least one advertising source before adding a customer. Go to ". popurl(2). "browse/part_referral.cgi and create one or more advertising sources."; - } elsif ( scalar(@referrals) == 1 ) { - $refnum ||= $referrals[0]->refnum; -%> - - - <% } else { %> -

<%=$r%>Advertising source - -<% } %> + <%= include('/elements/tr-select-part_referral.html') %> <% } %> @@ -153,14 +127,20 @@ if ( $cust_main->referral_custnum ) { %> -

Referring Customer: - <%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %> + + Referring customer + + <%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %> + + <% } elsif ( ! $conf->exists('disable_customer_referrals') ) { %> -

Referring customer number: - + + Referring customer + + <% } else { %> @@ -168,6 +148,8 @@ if ( $cust_main->referral_custnum <% } %> + +

@@ -377,10 +359,10 @@ unless ( $custnum ) { #false laziness, copied from FS::cust_pkg::order my $pkgpart; + my @agents = $FS::CurrentUser::CurrentUser->agents; if ( scalar(@agents) == 1 ) { # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART - my($agent)=qsearchs('agent',{'agentnum'=> $agentnum }); - $pkgpart = $agent->pkgpart_hashref; + $pkgpart = $agents[0]->pkgpart_hashref; } else { #can't know (agent not chosen), so, allow all my %typenum; diff --git a/httemplate/elements/select-agent.html b/httemplate/elements/select-agent.html index 78ec25f82..009cc6e06 100644 --- a/httemplate/elements/select-agent.html +++ b/httemplate/elements/select-agent.html @@ -1,8 +1,7 @@ <% my( $agentnum, %opt ) = @_; - my %select_opt = (); - $select_opt{'records'} = $opt{'agents'} + $opt{'records'} = delete $opt{'agents'} if $opt{'agents'}; %><%= include( '/elements/select-table.html', @@ -12,7 +11,8 @@ 'empty_label' => 'all', 'hashref' => { 'disabled' => '' }, 'extra_sql' => ' AND '. - $FS::CurrentUser::CurrentUser->agentnums_sql, - %select_opt, + $FS::CurrentUser::CurrentUser->agentnums_sql. + ' ORDER BY agent', + %opt, ) %> diff --git a/httemplate/elements/select-part_referral.html b/httemplate/elements/select-part_referral.html new file mode 100644 index 000000000..deb87bd3b --- /dev/null +++ b/httemplate/elements/select-part_referral.html @@ -0,0 +1,17 @@ +<% + my( $refnum, %opt ) = @_; + + $opt{'records'} = delete $opt{'part_referrals'} + if $opt{'part_referrals'}; + +%><%= include( '/elements/select-table.html', + 'table' => 'part_referral', + 'name_col' => 'referral', + 'value' => $refnum, + 'empty_label' => 'Select advertising source', + 'hashref' => { 'disabled' => '' }, + 'extra_sql' => ' AND '. + FS::part_referral->all_part_referral(1), + %opt, + ) +%> diff --git a/httemplate/elements/tr-select-agent.html b/httemplate/elements/tr-select-agent.html index 83c8d1758..6158f6f47 100644 --- a/httemplate/elements/tr-select-agent.html +++ b/httemplate/elements/tr-select-agent.html @@ -7,12 +7,9 @@ #here is the agent virtualization my $agentnums_href = $FS::CurrentUser::CurrentUser->agentnums_href; @agents = grep $agentnums_href->{$_->agentnum}, @{ $opt{'agents'} }; + delete $opt{'agents'}; } else { - @agents = qsearch( { - 'table' => 'agent', - 'hashref' => { disabled=>'' }, - 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, - }); + @agents = $FS::CurrentUser::CurrentUser->agents; } %> @@ -24,10 +21,11 @@ <% } else { %> - <%= $opt{'label'} || 'Agent: ' %> + <%= $opt{'label'} || 'Agent' %> <%= include( '/elements/select-agent.html', $agentnum, 'agents' => \@agents, + %opt, ) %> diff --git a/httemplate/elements/tr-select-part_referral.html b/httemplate/elements/tr-select-part_referral.html new file mode 100644 index 000000000..0108388bc --- /dev/null +++ b/httemplate/elements/tr-select-part_referral.html @@ -0,0 +1,30 @@ +<% + my( $refnum, %opt ) = @_; + + $opt{'part_referrals'} ||= + [ FS::part_referral->all_part_referral( 1 ) ]; #1: include global + + my $r = qq!* !; + +%> + +<% if ( scalar( @{$opt{'part_referrals'}} ) == 0 ) { + eidiot "You have not created any advertising sources. You must create at least one advertising source before adding a customer. Go to ". popurl(2). "browse/part_referral.html and create one or more advertising sources."; + } elsif ( scalar( @{$opt{'part_referrals'}} ) == 1 ) { +%> + + + +<% } else { %> + + + <%=$r%>Advertising source + + <%= include( '/elements/select-part_referral.html', $refnum, + 'part_referrals' => $opt{'part_referrals'}, + ) + %> + + + +<% } %> -- cgit v1.2.1