use FS::Record qw( qsearch qsearchs dbh );
use FS::m2m_Common;
use FS::access_usergroup;
+use FS::agent;
@ISA = qw( FS::m2m_Common FS::Record );
$sth->fetchrow_arrayref->[0];
}
+=item agents
+
+Returns the list of agents this user can view (via group membership), as
+FS::agent objects.
+
+=cut
+
+sub agents {
+ my $self = shift;
+ qsearch({
+ 'table' => 'agent',
+ 'hashref' => { disabled=>'' },
+ 'extra_sql' => ' AND '. $self->agentnums_sql,
+ });
+}
=item access_right
=over 4
-=item acl_agentnum_sql
+=item acl_agentnum_sql [ INCLUDE_GLOBAL_BOOL ]
Returns an SQL fragment for searching for part_referral records allowed by the
current users's agent ACLs (and "Edit global advertising sources" right).
+Pass a true value to include global advertising sources (for example, when
+simply using rather than editing advertising sources).
+
=cut
sub acl_agentnum_sql {
- #my $class = shift;
+ my $self = shift;
my $curuser = $FS::CurrentUser::CurrentUser;
my $sql = $curuser->agentnums_sql;
$sql = " ( $sql OR agentnum IS NULL ) "
- if $curuser->access_right('Edit global advertising sources');
+ if $curuser->access_right('Edit global advertising sources')
+ or defined($_[0]) && $_[0];
$sql;
}
-=item all_part_referral
+=item all_part_referral [ INCLUDE_GLOBAL_BOOL ]
Returns all part_referral records allowed by the current users's agent ACLs
(and "Edit global advertising sources" right).
+Pass a true value to include global advertising sources (for example, when
+simply using rather than editing advertising sources).
+
=cut
sub all_part_referral {
qsearch({
'table' => 'part_referral',
- 'extra_sql' => ' WHERE '. $self->acl_agentnum_sql. ' ORDER BY refnum ',
+ 'extra_sql' => ' WHERE '. $self->acl_agentnum_sql(@_). ' ORDER BY refnum ',
});
}
-=item num_part_referral
+=item num_part_referral [ INCLUDE_GLOBAL_BOOL ]
Returns the number of part_referral records allowed by the current users's
agent ACLs (and "Edit global advertising sources" right).
my $self = shift;
my $sth = dbh->prepare(
- 'SELECT COUNT(*) FROM part_referral WHERE '. $self->acl_agentnum_sql
+ 'SELECT COUNT(*) FROM part_referral WHERE '. $self->acl_agentnum_sql(@_)
) or die dbh->errstr;
$sth->execute() or die $sth->errstr;
$sth->fetchrow_arrayref->[0];
'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'
</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;
$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>
$cgi->delete_all();
my $action = $custnum ? 'Edit' : 'Add';
+my $r = qq!<font color="#ff0000">*</font> !;
+
%>
<!-- top -->
) %>
<% 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) -->
<%
<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') %>
<% } %>
) {
%>
- <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 { %>
<% } %>
+</TABLE>
+
<!-- contact info -->
<BR><BR>
#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;
<%
my( $agentnum, %opt ) = @_;
- my %select_opt = ();
- $select_opt{'records'} = $opt{'agents'}
+ $opt{'records'} = delete $opt{'agents'}
if $opt{'agents'};
%><%= include( '/elements/select-table.html',
'empty_label' => 'all',
'hashref' => { 'disabled' => '' },
'extra_sql' => ' AND '.
- $FS::CurrentUser::CurrentUser->agentnums_sql,
- %select_opt,
+ $FS::CurrentUser::CurrentUser->agentnums_sql.
+ ' ORDER BY agent',
+ %opt,
)
%>
--- /dev/null
+<%
+ 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,
+ )
+%>
#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;
}
%>
<% } 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>
--- /dev/null
+<%
+ 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>
+
+<% } %>