allow exports to add links to customer view (#1407)
[freeside.git] / FS / FS / cust_svc.pm
index af54f22..51fc186 100644 (file)
@@ -132,22 +132,30 @@ sub cancel {
 
   my $svc = $self->svc_x;
   if ($svc) {
+
     my $error = $svc->cancel;
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
       return "Error canceling service: $error";
     }
-    $error = $svc->delete;
+    $error = $svc->delete; #this deletes this cust_svc record as well
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
       return "Error deleting service: $error";
     }
-  }
 
-  my $error = $self->delete;
-  if ( $error ) {
-    $dbh->rollback if $oldAutoCommit;
-    return "Error deleting cust_svc: $error";
+  } else {
+
+    #huh?
+    warn "WARNING: no svc_ record found for svcnum ". $self->svcnum.
+         "; deleting cust_svc only\n"; 
+
+    my $error = $self->delete;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "Error deleting cust_svc: $error";
+    }
+
   }
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -321,6 +329,34 @@ sub cust_pkg {
   qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
 }
 
+=item pkg_svc
+
+Returns the pkg_svc record for for this service, if applicable.
+
+=cut
+
+sub pkg_svc {
+  my $self = shift;
+  my $cust_pkg = $self->cust_pkg;
+  return undef unless $cust_pkg;
+
+  qsearchs( 'pkg_svc', { 'svcpart' => $self->svcpart,
+                         'pkgpart' => $cust_pkg->pkgpart,
+                       }
+          );
+}
+
+=item date_inserted
+
+Returns the date this service was inserted.
+
+=cut
+
+sub date_inserted {
+  my $self = shift;
+  $self->h_date('insert');
+}
+
 =item label
 
 Returns a list consisting of:
@@ -356,6 +392,20 @@ sub _svc_label {
 
 }
 
+=item export_links
+
+Returns a list of html elements associated with this services exports.
+
+=cut
+
+sub export_links {
+  my $self = shift;
+  my $svc_x = $self->svc_x
+    or return "can't find ". $self->part_svc->svcdb. '.svcnum '. $self->svcnum;
+
+  $svc_x->export_links;
+}
+
 =item svc_x
 
 Returns the FS::svc_XXX object for this service (i.e. an FS::svc_acct object or
@@ -643,23 +693,6 @@ sub get_cdrs_for_update {
   @cdrs;
 }
 
-=item pkg_svc
-
-Returns the pkg_svc record for for this service, if applicable.
-
-=cut
-
-sub pkg_svc {
-  my $self = shift;
-  my $cust_pkg = $self->cust_pkg;
-  return undef unless $cust_pkg;
-
-  qsearchs( 'pkg_svc', { 'svcpart' => $self->svcpart,
-                         'pkgpart' => $cust_pkg->pkgpart,
-                       }
-          );
-}
-
 =back
 
 =head1 BUGS