create a Sales, Credits, and Receipts report broken down by day, RT11470
[freeside.git] / httemplate / elements / select-agent.html
index c2a5e4b..897c982 100644 (file)
@@ -1,24 +1,31 @@
-<%
-  my( $agentnum, %opt ) = @_;
-
-  my @agents;
-  if ( $opt{'agents'} ) {
-    @agents = @{ $opt{'agents'} };
-  } else {
-    @agents = qsearch( 'agent', { disabled=>'' } );
-  }
-
+<% include( '/elements/select-table.html',
+                 'table'         => 'agent',
+                 'name_col'      => 'agent',
+                 'value'         => $agentnum || '',
+                 'agent_virt'    => 1,
+                 'empty_label'   => 'all',
+                 'hashref'       => { 'disabled' => '' },
+                 'order_by'      => ' ORDER BY agent',
+                 'disable_empty' => $disable_empty,
+                 %opt,
+             )
 %>
+<%init>
 
-<SELECT NAME="agentnum">
-
-  <OPTION VALUE="">all</OPTION>
+my %opt = @_;
+my $agentnum = $opt{'curr_value'} || $opt{'value'};
 
-  <% foreach my $agent ( sort { $a->agent cmp $b->agent } @agents ) { %>
+$opt{'records'} = delete $opt{'agents'}
+  if $opt{'agents'};
 
-    <OPTION VALUE="<%= $agent->agentnum %>"<%= $agentnum == $agent->agentnum ? ' SELECTED' : '' %>><%= $agent->agent %>
-
-  <% } %>
-
-</SELECT>
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $disable_empty = 0;
+if ( $opt{'agent_null_right'} ) {
+  if ( $curuser->access_right($opt{'agent_null_right'}) ) {
+    $disable_empty = 0;
+  } else {
+    $disable_empty = 1;
+  }
+}
 
+</%init>