better delete customer code & warnings, delete package ability (& warning)
authorivan <ivan>
Mon, 22 Oct 2001 08:29:42 +0000 (08:29 +0000)
committerivan <ivan>
Mon, 22 Oct 2001 08:29:42 +0000 (08:29 +0000)
FS/FS/cust_main.pm
FS/FS/cust_pkg.pm

index 3895514..12be7ab 100644 (file)
@@ -362,11 +362,13 @@ This will completely remove all traces of the customer record.  This is not
 what you want when a customer cancels service; for that, cancel all of the
 customer's packages (see L<FS::cust_pkg/cancel>).
 
-If the customer has any packages, you need to pass a new (valid) customer
-number for those packages to be transferred to.
+If the customer has any uncancelled packages, you need to pass a new (valid)
+customer number for those packages to be transferred to.  Cancelled packages
+will be deleted.  Did I mention that this is NOT what you want when a customer
+cancels service and that you really should be looking see L<FS::cust_pkg/cancel>?
 
 You can't delete a customer with invoices (see L<FS::cust_bill>),
-or credits (see L<FS::cust_credit>).
+or credits (see L<FS::cust_credit>) or payments (see L<FS::cust_pay>).
 
 =cut
 
@@ -392,8 +394,12 @@ sub delete {
     $dbh->rollback if $oldAutoCommit;
     return "Can't delete a customer with credits";
   }
+  if ( qsearch( 'cust_pay', { 'custnum' => $self->custnum } ) ) {
+    $dbh->rollback if $oldAutoCommit;
+    return "Can't delete a customer with payments";
+  }
 
-  my @cust_pkg = qsearch( 'cust_pkg', { 'custnum' => $self->custnum } );
+  my @cust_pkg = $self->ncancelled_pkgs;
   if ( @cust_pkg ) {
     my $new_custnum = shift;
     unless ( qsearchs( 'cust_main', { 'custnum' => $new_custnum } ) ) {
@@ -411,6 +417,15 @@ sub delete {
       }
     }
   }
+  my @cancelled_pkgs = $self->all_pkgs;
+  foreach my $cust_pkg ( @cancelled_cust_pkg ) {
+    my $error = $cust_pkg->delete;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   foreach my $cust_main_invoice (
     qsearch( 'cust_main_invoice', { 'custnum' => $self->custnum } )
   ) {
@@ -1840,7 +1855,7 @@ sub append_fuzzyfiles {
 
 =head1 VERSION
 
-$Id: cust_main.pm,v 1.42 2001-10-20 12:17:59 ivan Exp $
+$Id: cust_main.pm,v 1.43 2001-10-22 08:29:42 ivan Exp $
 
 =head1 BUGS
 
index 069ac8c..7aee8d0 100644 (file)
@@ -123,15 +123,16 @@ sub insert {
 
 =item delete
 
-Currently unimplemented.  You don't want to delete billing items, because there
-would then be no record the customer ever purchased the item.  Instead, see
-the cancel method.
+This method now works but you probably shouldn't use it.
+
+You don't want to delete billing items, because there would then be no record
+the customer ever purchased the item.  Instead, see the cancel method.
 
 =cut
 
-sub delete {
-  return "Can't delete cust_pkg records!";
-}
+#sub delete {
+#  return "Can't delete cust_pkg records!";
+#}
 
 =item replace OLD_RECORD
 
@@ -588,7 +589,7 @@ sub order {
 
 =head1 VERSION
 
-$Id: cust_pkg.pm,v 1.11 2001-10-15 14:58:03 ivan Exp $
+$Id: cust_pkg.pm,v 1.12 2001-10-22 08:29:42 ivan Exp $
 
 =head1 BUGS