diff options
author | ivan <ivan> | 2006-08-11 08:02:26 +0000 |
---|---|---|
committer | ivan <ivan> | 2006-08-11 08:02:26 +0000 |
commit | e47e9758f480c664bfc3917d798cd69c7d354999 (patch) | |
tree | e776a5753a1214a797731f4da39518979f1400eb /httemplate | |
parent | dbc120189697e8306f62349c310f5410f8382491 (diff) |
virtualize referrals on customer addition
Diffstat (limited to 'httemplate')
-rwxr-xr-x | httemplate/browse/part_referral.html | 29 | ||||
-rwxr-xr-x | httemplate/edit/cust_main.cgi | 80 | ||||
-rw-r--r-- | httemplate/elements/select-agent.html | 8 | ||||
-rw-r--r-- | httemplate/elements/select-part_referral.html | 17 | ||||
-rw-r--r-- | httemplate/elements/tr-select-agent.html | 10 | ||||
-rw-r--r-- | httemplate/elements/tr-select-part_referral.html | 30 |
6 files changed, 102 insertions, 72 deletions
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. </TR> <% -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; + %> <TR> - <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"><A HREF="<%= $p %>edit/part_referral.html?<%= $part_referral->refnum %>"> - <%= $part_referral->refnum %></A></TD> - <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"><A HREF="<%= $p %>edit/part_referral.html?<%= $part_referral->refnum %>"> - <%= $part_referral->referral %></A></TD> + <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"> + <% if ( $part_referral->agentnum || $curuser->access_right('Edit global advertising sources') ) { + $a++; + %> + <A HREF="<%= $p %>edit/part_referral.html?<%= $part_referral->refnum %>"> + <% } %> + <%= $part_referral->refnum %><%= $a ? '</A>' : '' %></TD> + <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"> + <% if ( $a ) { %> + <A HREF="<%= $p %>edit/part_referral.html?<%= $part_referral->refnum %>"> + <% } %> + <%= $part_referral->referral %><%= $a ? '</A>' : '' %></TD> <% if ( $show_agentnums ) { %> <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"><%= $part_referral->agentnum ? $part_referral->agent->agent : '(global)' %></TD> 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!<font color="#ff0000">*</font> !; + %> <!-- top --> @@ -77,38 +79,29 @@ my $action = $custnum ? 'Edit' : 'Add'; ) %> <% if ( $error ) { %> -<FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT> +<FONT SIZE="+1" COLOR="#ff0000">Error: <%= $error %></FONT><BR><BR> <% } %> <FORM NAME="topform" STYLE="margin-bottom: 0"> <INPUT TYPE="hidden" NAME="custnum" VALUE="<%= $custnum %>"> -Customer # <%= $custnum ? "<B>$custnum</B>" : " (NEW)" %> - -<!-- agent --> - -<% +<% if ( $custnum ) { %> + Customer #<B><%= $custnum %></B> - + <B><FONT COLOR="<%= $cust_main->statuscolor %>"> + <%= ucfirst($cust_main->status) %> + </FONT></B> + <BR><BR> +<% } %> -my $r = qq!<font color="#ff0000">*</font> !; +<%= &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 +<!-- agent --> +<%= include('/elements/tr-select-agent.html', $cust_main->agentnum, + 'label' => "<B>${r}Agent</B>", + 'empty_label' => 'Select agent', + ) %> -<% if ( scalar(@agents) == 1 ) { %> - <INPUT TYPE="hidden" NAME="agentnum" VALUE="<%= $agentnum %>"> -<% } else { %> - <BR><BR><%=$r%>Agent <SELECT NAME="agentnum" SIZE="1"> - <% foreach my $agent (sort { $a->agent cmp $b->agent; } @agents) { %> - <OPTION VALUE="<%= $agent->agentnum %>"<%= " SELECTED"x($agent->agentnum==$agentnum) %>><%= $agent->agent %> - <% } %> - </SELECT> -<% } %> - <!-- referral (advertising source) --> <% @@ -118,28 +111,9 @@ if ( $custnum && ! $conf->exists('editreferrals') ) { <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>"> -<% - } 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; -%> - - <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>"> - <% } else { %> - <BR><BR><%=$r%>Advertising source - <SELECT NAME="refnum" SIZE="1"> - <%= $refnum ? '' : '<OPTION VALUE="">' %> - <% foreach my $referral (sort { $a->refnum <=> $b->refnum } @referrals) { %> - <OPTION VALUE="<%= $referral->refnum %>" <%= $referral->refnum == $refnum ? 'SELECTED' : '' %>><%= $referral->refnum %>: <%= $referral->referral %> - <% } %> - </SELECT> -<% } %> + <%= include('/elements/tr-select-part_referral.html') %> <% } %> @@ -153,14 +127,20 @@ if ( $cust_main->referral_custnum ) { %> - <BR><BR>Referring Customer: - <A HREF="<%= popurl(1) %>/cust_main.cgi?<%= $cust_main->referral_custnum %>"><%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %></A> + <TR> + <TD ALIGN="right">Referring customer</TD> + <TD> + <A HREF="<%= popurl(1) %>/cust_main.cgi?<%= $cust_main->referral_custnum %>"><%= $cust_main->referral_custnum %>: <%= $referring_cust_main->name %></A> + </TD> + </TR> <INPUT TYPE="hidden" NAME="referral_custnum" VALUE="<%= $cust_main->referral_custnum %>"> <% } elsif ( ! $conf->exists('disable_customer_referrals') ) { %> - <BR><BR>Referring customer number: - <INPUT TYPE="text" NAME="referral_custnum" VALUE=""> + <TR> + <TD ALIGN="right">Referring customer</TD> + <TD><INPUT TYPE="text" NAME="referral_custnum" VALUE=""></TD> + </TR> <% } else { %> @@ -168,6 +148,8 @@ if ( $cust_main->referral_custnum <% } %> +</TABLE> + <!-- contact info --> <BR><BR> @@ -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 { %> <TR> - <TD ALIGN="right"><%= $opt{'label'} || 'Agent: ' %></TD> + <TD ALIGN="right"><%= $opt{'label'} || 'Agent' %></TD> <TD> <%= include( '/elements/select-agent.html', $agentnum, 'agents' => \@agents, + %opt, ) %> </TD> 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!<font color="#ff0000">*</font> !; + +%> + +<% 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 ) { +%> + + <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $opt{'part_referrals'}->[0]->refnum %>"> + +<% } else { %> + + <TR> + <TH ALIGN="right"><%=$r%>Advertising source</TH> + <TD> + <%= include( '/elements/select-part_referral.html', $refnum, + 'part_referrals' => $opt{'part_referrals'}, + ) + %> + </TD> + </TR> + +<% } %> |