fix ambiguous agentnum errors in cust_event.html & report_tax.cgi (provide a table...
authorivan <ivan>
Sat, 29 Sep 2007 02:17:48 +0000 (02:17 +0000)
committerivan <ivan>
Sat, 29 Sep 2007 02:17:48 +0000 (02:17 +0000)
FS/FS/access_user.pm
httemplate/search/cust_event.html
httemplate/search/report_tax.cgi

index 8e4ad46..e3a677b 100644 (file)
@@ -323,6 +323,8 @@ Options are passed as a hashref or a list.  Available options are:
 
 =item null_right - The fragment will also allow the selection of null agentnums if the current user has the provided access right
 
+=item table - Optional table name in which agentnum is being checked.  Sometimes required to resolve 'column reference "agentnum" is ambiguous' errors.
+
 =back
 
 =cut
@@ -331,9 +333,11 @@ sub agentnums_sql {
   my( $self ) = shift;
   my %opt = ref($_[0]) ? %{$_[0]} : @_;
 
-  my @agentnums = map { "agentnum = $_" } $self->agentnums;
+  my $agentnum = $opt{'table'} ? $opt{'table'}.'.agentnum' : 'agentnum';
+
+  my @agentnums = map { "$agentnum = $_" } $self->agentnums;
 
-  push @agentnums, 'agentnum IS NULL'
+  push @agentnums, "$agentnum IS NULL"
     if $opt{'null'}
     || ( $opt{'null_right'} && $self->access_right($opt{'null_right'}) );
 
index f9cce46..dc6fd05 100644 (file)
@@ -151,7 +151,7 @@ my $title = $cgi->param('failed')
 my @search = ();
 
 if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
-  push @search, "agentnum = $1";
+  push @search, "cust_main.agentnum = $1";
   #my $agent = qsearchs('agent', { 'agentnum' => $1 } );
   #die "unknown agentnum $1" unless $agent;
 }
@@ -183,9 +183,7 @@ if ( $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
 }
 
 #here is the agent virtualization
-my $agent_sql = $curuser->agentnums_sql;
-$agent_sql =~ s/agentnum/cust_main.agentnum/g;
-push @search, $agent_sql;
+push @search, $curuser->agentnums_sql( 'table' => 'cust_main' );
 
 my $where = 'WHERE '. join(' AND ', @search );
 
index e974805..bb9c8f4 100755 (executable)
@@ -226,7 +226,7 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
   my $agent = qsearchs('agent', { 'agentnum' => $1 } );
   die "agent not found" unless $agent;
   $agentname = $agent->agent;
-  $where .= ' AND agentnum = '. $agent->agentnum;
+  $where .= ' AND cust_main.agentnum = '. $agent->agentnum;
 }
 
 my $gotcust = "