stop new IP address assignment code from tripping over ancient svc_acct.slipip values...
[freeside.git] / FS / FS / access_user.pm
index 4d72c2e..de3c884 100644 (file)
@@ -10,6 +10,8 @@ use FS::access_user_pref;
 use FS::access_usergroup;
 use FS::agent;
 use FS::cust_main;
+use FS::sales;
+use FS::sched_item;
 
 $DEBUG = 0;
 $me = '[FS::access_user]';
@@ -254,6 +256,7 @@ sub check {
     || $self->ut_text('last')
     || $self->ut_text('first')
     || $self->ut_foreign_keyn('user_custnum', 'cust_main', 'custnum')
+    || $self->ut_foreign_keyn('report_salesnum', 'sales', 'salesnum')
     || $self->ut_enum('disabled', [ '', 'Y' ] )
   ;
   return $error if $error;
@@ -286,6 +289,18 @@ sub user_cust_main {
   qsearchs( 'cust_main', { 'custnum' => $self->user_custnum } );
 }
 
+=item report_sales
+
+Returns the FS::sales object (see L<FS::sales>), if any, for this
+user.
+
+=cut
+
+sub report_sales {
+  my $self = shift;
+  qsearchs( 'sales', { 'salesnum' => $self->report_salesnum } );
+}
+
 =item access_usergroup
 
 Returns links to the the groups this user is a part of, as FS::access_usergroup
@@ -427,6 +442,7 @@ sub agents {
     'table'     => 'agent',
     'hashref'   => { disabled=>'' },
     'extra_sql' => ' AND '. $self->agentnums_sql(@_),
+    'order_by'  => 'ORDER BY agent',
   });
 }
 
@@ -454,7 +470,7 @@ sub access_right {
     unless ( grep !exists($self->{_ACLcache}{$_}), @$rightname ) {
       warn "$me ACL cache hit for ". join(', ', @$rightname). "\n"
         if $DEBUG;
-      return grep $self->{_ACLcache}{$_}, @$rightname
+      return scalar( grep $self->{_ACLcache}{$_}, @$rightname );
     }
 
     warn "$me ACL cache miss for ". join(', ', @$rightname). "\n"
@@ -511,14 +527,16 @@ sub default_customer_view {
 
 }
 
-=item spreadsheet_format
+=item spreadsheet_format [ OVERRIDE ]
 
 Returns a hashref of this user's Excel spreadsheet download settings:
 'extension' (xls or xlsx), 'class' (Spreadsheet::WriteExcel or
-Excel::Writer::XLSX), and 'mime_type'.
+Excel::Writer::XLSX), and 'mime_type'.  If OVERRIDE is 'XLS' or 'XLSX',
+use that instead of the user's setting.
 
 =cut
 
+# is there a better place to put this?
 my %formats = (
   XLS => {
     extension => '.xls',
@@ -535,10 +553,12 @@ my %formats = (
 
 sub spreadsheet_format {
   my $self = shift;
+  my $override = shift;
 
-  my $f = $self->option('spreadsheet_format') 
-       || $conf->config('spreadsheet_format')
-       || 'XLS';
+  my $f =  $override
+        || $self->option('spreadsheet_format') 
+        || $conf->config('spreadsheet_format')
+        || 'XLS';
 
   $formats{$f};
 }
@@ -562,6 +582,11 @@ sub is_system_user {
 ) );
 }
 
+sub sched_item {
+  my $self = shift;
+  qsearch( 'sched_item', { 'usernum' => $self->usernum } );
+}
+
 =back
 
 =head1 BUGS