display sent mail on customer notes page, and improve sent mail log UI, #29250
[freeside.git] / FS / FS / contact.pm
index 5c3981b..4a1fb39 100644 (file)
@@ -11,6 +11,7 @@ use FS::cust_location;
 use FS::contact_phone;
 use FS::contact_email;
 use FS::queue;
+use FS::cust_pkg;
 
 =head1 NAME
 
@@ -211,6 +212,15 @@ sub delete {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  foreach my $cust_pkg ( $self->cust_pkg ) {
+    $cust_pkg->contactnum('');
+    my $error = $cust_pkg->replace;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   foreach my $object ( $self->contact_phone, $self->contact_email ) {
     my $error = $object->delete;
     if ( $error ) {
@@ -491,6 +501,12 @@ sub cust_main {
   qsearchs('cust_main', { 'custnum' => $self->custnum  } );
 }
 
+sub cust_pkg {
+  my $self = shift;
+  qsearch('cust_pkg', { 'contactnum' => $self->contactnum  } );
+}
+
+
 sub by_selfservice_email {
   my($class, $email) = @_;