better hidden pkg_svc flag, RT#9871
[freeside.git] / FS / FS / cust_pkg.pm
index 2b512a7..66d8bae 100644 (file)
@@ -1291,7 +1291,6 @@ use Data::Dumper;
 use Storable 'thaw';
 use MIME::Base64;
 sub process_bulk_cust_pkg {
-  local $DEBUG = 1;
   my $job = shift;
   my $param = thaw(decode_base64(shift));
   warn Dumper($param) if $DEBUG;
@@ -1301,7 +1300,8 @@ sub process_bulk_cust_pkg {
   my $new_part_pkg = qsearchs('part_pkg',
                               { pkgpart => $param->{'new_pkgpart'} });
   die "Must select a new package type\n" unless $new_part_pkg;
-  my $keep_dates = $param->{'keep_dates'} || 0;
+  #my $keep_dates = $param->{'keep_dates'} || 0;
+  my $keep_dates = 1; # there is no good reason to turn this off
 
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
@@ -1638,24 +1638,31 @@ sub overlimit {
   grep { $_->overlimit } $self->cust_svc(@_);
 }
 
-=item h_cust_svc END_TIMESTAMP [ START_TIMESTAMP ] 
+=item h_cust_svc END_TIMESTAMP [ START_TIMESTAMP ] [ MODE ]
 
 Returns historical services for this package created before END TIMESTAMP and
 (optionally) not cancelled before START_TIMESTAMP, as FS::h_cust_svc objects
-(see L<FS::h_cust_svc>).
+(see L<FS::h_cust_svc>).  If MODE is 'I' (for 'invoice'), services with the 
+I<pkg_svc.hidden> flag will be omitted.
 
 =cut
 
 sub h_cust_svc {
   my $self = shift;
-
-  $self->_sort_cust_svc(
+  my ($end, $start, $mode) = @_;
+  my @cust_svc = $self->_sort_cust_svc(
     [ qsearch( 'h_cust_svc',
-               { 'pkgnum' => $self->pkgnum, },
-               FS::h_cust_svc->sql_h_search(@_),
-             )
-    ]
+      { 'pkgnum' => $self->pkgnum, },  
+      FS::h_cust_svc->sql_h_search(@_),  
+    ) ]
   );
+  if ( $mode eq 'I' ) {
+    my %hidden_svcpart = map { $_->svcpart => $_->hidden } $self->part_svc;
+    return grep { !$hidden_svcpart{$_->svcpart} } @cust_svc;
+  }
+  else {
+    return @cust_svc;
+  }
 }
 
 sub _sort_cust_svc {
@@ -1758,6 +1765,7 @@ sub part_svc {
       max( 0, $pkg_svc->quantity - $num_cust_svc );
     $part_svc->{'Hash'}{'cust_pkg_svc'} =
       $num_cust_svc ? [ $self->cust_svc($part_svc->svcpart) ] : [];
+    $part_svc->{'Hash'}{'hidden'} = $pkg_svc->hidden;
     $part_svc;
   } $self->part_pkg->pkg_svc;
 
@@ -1973,11 +1981,12 @@ sub labels {
   map { [ $_->label ] } $self->cust_svc;
 }
 
-=item h_labels END_TIMESTAMP [ START_TIMESTAMP ] 
+=item h_labels END_TIMESTAMP [ START_TIMESTAMP ] [ MODE ]
 
 Like the labels method, but returns historical information on services that
 were active as of END_TIMESTAMP and (optionally) not cancelled before
-START_TIMESTAMP.
+START_TIMESTAMP.  If MODE is 'I' (for 'invoice'), services with the 
+I<pkg_svc.hidden> flag will be omitted.
 
 Returns a list of lists, calling the label method for all (historical) services
 (see L<FS::h_cust_svc>) of this billing item.