fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / cust_svc.pm
index 30e49c5..fc6e605 100644 (file)
@@ -308,7 +308,9 @@ sub check {
     my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
     return "Unknown pkgnum" unless $cust_pkg;
     ($part_svc) = grep { $_->svcpart == $self->svcpart } $cust_pkg->part_svc;
-
+    return "No svcpart ". $self->svcpart.
+           " services in pkgpart ". $cust_pkg->pkgpart
+      unless $part_svc;
     return "Already ". $part_svc->get('num_cust_svc'). " ". $part_svc->svc.
            " services for pkgnum ". $self->pkgnum
       if $part_svc->get('num_avail') == 0 and !$ignore_quantity;
@@ -371,6 +373,20 @@ sub date_inserted {
   $self->h_date('insert');
 }
 
+=item pkg_cancel_date
+
+Returns the date this service's package was canceled.  This normally only 
+exists for a service that's been preserved through cancellation with the 
+part_pkg.preserve flag.
+
+=cut
+
+sub pkg_cancel_date {
+  my $self = shift;
+  my $cust_pkg = $self->cust_pkg or return;
+  return $cust_pkg->getfield('cancel') || '';
+}
+
 =item label
 
 Returns a list consisting of: