virtualize referrals on customer addition
[freeside.git] / httemplate / browse / part_referral.html
index fff433a..c50a406 100755 (executable)
@@ -33,11 +33,6 @@ Where a customer heard about your service. Tracked for informational purposes.
   );
 
   my $curuser = $FS::CurrentUser::CurrentUser;
-  my $extra_sql = $curuser->agentnums_sql;
-  $extra_sql .= ' OR agentnum IS NULL '
-    if $curuser->access_right('Edit global advertising sources');
-
-  $extra_sql = " WHERE $extra_sql";
 
   my $statement = "SELECT COUNT(*) FROM h_cust_main
                     WHERE history_action = 'insert'
@@ -72,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;
@@ -87,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>
@@ -117,14 +115,14 @@ foreach my $part_referral (
     or die dbh->errstr;
 %>
       <TR>
-        <TD BGCOLOR="#dddddd" COLSPAN=3><B>Total</B></TD>
+        <TD BGCOLOR="#dddddd" ALIGN="center" COLSPAN=3><B>Total</B></TD>
         <% for my $period ( keys %after ) {
           $sth->execute( $today-$after{$period},
                          $today+$before{$period},
           ) or die $sth->errstr;
           my $number = $sth->fetchrow_arrayref->[0];
         %>
-          <TD BGCOLOR="#dddddd" ALIGN="right"><%= $number %></TD>
+          <TD BGCOLOR="#dddddd" ALIGN="right"><B><%= $number %><B></TD>
         <% } %>
       </TR>
     </TABLE>