add options to skip CDRs under a defined length and with specific lastapp
[freeside.git] / FS / FS / part_pkg.pm
index f7c56f3..8cf7d0c 100644 (file)
@@ -1,7 +1,7 @@
 package FS::part_pkg;
 
 use strict;
-use vars qw( @ISA %plans $DEBUG );
+use vars qw( @ISA %plans $DEBUG $setup_hack );
 use Carp qw(carp cluck confess);
 use Scalar::Util qw( blessed );
 use Time::Local qw( timelocal_nocheck );
@@ -22,6 +22,7 @@ use FS::part_pkg_link;
 
 @ISA = qw( FS::m2m_Common FS::option_Common );
 $DEBUG = 0;
+$setup_hack = 0;
 
 =head1 NAME
 
@@ -454,7 +455,10 @@ sub check {
                               'part_pkg_taxproduct',
                               'taxproductnum'
                              )
-    || $self->ut_agentnum_acl('agentnum', \@null_agentnum_right)
+    || ( $setup_hack
+           ? $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' )
+           : $self->ut_agentnum_acl('agentnum', \@null_agentnum_right)
+       )
     || $self->SUPER::check
   ;
   return $error if $error;
@@ -1112,6 +1116,9 @@ sub calc_remain { 0; }
 sub calc_cancel { 0; }
 sub calc_units  { 0; }
 
+#fallback for everything except bulk.pm
+sub hide_svc_detail { 0; }
+
 =item format OPTION DATA
 
 Returns data formatted according to the function 'format' described
@@ -1229,9 +1236,31 @@ L<FS::type_pkgs>).
 =cut
 
 sub curuser_pkgs_sql {
-  #my($class) = shift;
+  my $class = shift;
+
+  $class->_pkgs_sql( $FS::CurrentUser::CurrentUser->agentnums );
+
+}
+
+=item agent_pkgs_sql AGENT | AGENTNUM, ...
+
+Returns an SQL fragment for searching for packages the provided agent or agents
+can use, either via part_pkg.agentnum directly, or via agent type (see
+L<FS::type_pkgs>).
+
+=cut
+
+sub agent_pkgs_sql {
+  my $class = shift;  #i'm a class method, not a sub (the question is... why??)
+  my @agentnums = map { ref($_) ? $_->agentnum : $_ } @_;
+
+  $class->_pkgs_sql(@agentnums); #is this why
+
+}
 
-  my $agentnums = join(',', $FS::CurrentUser::CurrentUser->agentnums);
+sub _pkgs_sql {
+  my( $class, @agentnums ) = @_;
+  my $agentnums = join(',', @agentnums);
 
   "
     (