[freeside-commits] branch FREESIDE_3_BRANCH updated. e3e006a4e2d532e5643e8e7cbb1de4b7f1d21135

Jonathan Prykop jonathan at 420.am
Mon Mar 2 13:03:49 PST 2015


The branch, FREESIDE_3_BRANCH has been updated
       via  e3e006a4e2d532e5643e8e7cbb1de4b7f1d21135 (commit)
       via  dae6eb9669fd2386fe19a31782c298efaefaf35a (commit)
       via  598f5364ffaab833463442f910fc9c533975e317 (commit)
       via  efa870992fa06350b1e1d75a53b7e0c42f59f59b (commit)
       via  20a1e12e4dd57dfa69979918d4da524a30d36462 (commit)
      from  726bac7944dd7f768fe50b1d615b2b67cd466424 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e3e006a4e2d532e5643e8e7cbb1de4b7f1d21135
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Fri Feb 20 20:07:18 2015 -0600

    RT#14671: Usage for current day when billing outstanding usage (for cancelling customers) [now uses suspend for everything]

diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 38cd354..88afe35 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -791,6 +791,10 @@ to a different pkgpart or location, and probably shouldn't be in any other
 case.  If it's not set, the 'unused_credit_cancel' part_pkg option will 
 be used.
 
+=item delay_cancel - for internal use, to allow proper handling of
+supplemental packages when the main package is flagged to suspend 
+before cancelling
+
 =back
 
 If there is an error, returns the error, otherwise returns false.
@@ -837,7 +841,7 @@ sub cancel {
   my $date = $options{'date'} if $options{'date'}; # expire/cancel later
   $date = '' if ($date && $date <= $cancel_time);      # complain instead?
 
-  my $delay_cancel = undef;
+  my $delay_cancel = $options{'delay_cancel'};
   if ( !$date && $self->part_pkg->option('delay_cancel',1)
        && (($self->status eq 'active') || ($self->status eq 'suspended'))
   ) {
@@ -921,7 +925,7 @@ sub cancel {
   if ( $date ) {
     $hash{'expire'} = $date;
     if ($delay_cancel) {
-      $hash{'susp'} = $cancel_time unless $self->susp;
+      # just to be sure these are clear
       $hash{'adjourn'} = undef;
       $hash{'resume'} = undef;
     }
@@ -948,21 +952,24 @@ sub cancel {
   }
 
   foreach my $supp_pkg ( $self->supplemental_pkgs ) {
-    if ($delay_cancel) {
-      $error = $supp_pkg->suspend(
-        'from_main'   => 1, 
-        'from_cancel' => 1,
-        'time'        => $cancel_time
-      );
-    } else {
-      $error = $supp_pkg->cancel(%options, 'from_main' => 1);
-    }
+    $error = $supp_pkg->cancel(%options, 
+      'from_main' => 1, 
+      'date' => $date, #in case it got changed by delay_cancel
+      'delay_cancel' => $delay_cancel,
+    );
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
       return "canceling supplemental pkg#".$supp_pkg->pkgnum.": $error";
     }
   }
 
+  if ($delay_cancel && !$options{'from_main'}) {
+    $error = $new->suspend(
+      'from_cancel' => 1,
+      'time'        => $cancel_time
+    );
+  }
+
   unless ($date) {
     foreach my $usage ( $self->cust_pkg_usage ) {
       $error = $usage->delete;
@@ -3415,6 +3422,9 @@ really the whole point of the delay_cancel option.
 
 sub is_status_delay_cancel {
   my ($self) = @_;
+  if ( $self->main_pkgnum and $self->pkglinknum ) {
+    return $self->main_pkg->is_status_delay_cancel;
+  }
   return 0 unless $self->part_pkg->option('delay_cancel',1);
   return 0 unless $self->status eq 'suspended';
   return 0 unless $self->expire;
diff --git a/httemplate/view/cust_main/packages/status.html b/httemplate/view/cust_main/packages/status.html
index a021f1c..66df1ce 100644
--- a/httemplate/view/cust_main/packages/status.html
+++ b/httemplate/view/cust_main/packages/status.html
@@ -54,9 +54,15 @@
         <% pkg_status_row( $cust_pkg, emt('On Hold'), '', 'color'=>'7E0079', %opt ) %>
 
 %     } else { #status: suspended
-
-        <% pkg_status_row( $cust_pkg, emt('Suspended'), 'susp', 'color'=>'FF9900', %opt ) %>
-%       my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
+%       my ($cpr,$susplabel);
+%       if ($cust_pkg->is_status_delay_cancel) {
+%         $cpr = $cust_pkg->last_cust_pkg_reason('expire');
+%         $susplabel = 'Suspended (Cancelled)';
+%       } else {
+%         $cpr = $cust_pkg->last_cust_pkg_reason('susp');
+%         $susplabel = 'Suspended';
+%       }
+        <% pkg_status_row( $cust_pkg, emt($susplabel), 'susp', 'color'=>'FF9900', %opt ) %>
         <% pkg_reason_row( $cust_pkg, $cpr, 'color' => 'FF9900', %opt ) %>
 
 %     }

commit dae6eb9669fd2386fe19a31782c298efaefaf35a
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Feb 17 18:11:21 2015 -0600

    #14671: Usage for current day when billing outstanding usage (for cancelling customers) [various fixes to previous]

diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 69f7bc0..38cd354 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -915,7 +915,6 @@ sub cancel {
         return $error;
       }
     }
-
   } #unless $date
 
   my %hash = $self->hash;
@@ -950,9 +949,13 @@ sub cancel {
 
   foreach my $supp_pkg ( $self->supplemental_pkgs ) {
     if ($delay_cancel) {
-        $error = $supp_pkg->suspend(%options, 'from_main' => 1, 'reason' => undef);
+      $error = $supp_pkg->suspend(
+        'from_main'   => 1, 
+        'from_cancel' => 1,
+        'time'        => $cancel_time
+      );
     } else {
-        $error = $supp_pkg->cancel(%options, 'from_main' => 1);
+      $error = $supp_pkg->cancel(%options, 'from_main' => 1);
     }
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
@@ -960,11 +963,13 @@ sub cancel {
     }
   }
 
-  foreach my $usage ( $self->cust_pkg_usage ) {
-    $error = $usage->delete;
-    if ( $error ) {
-      $dbh->rollback if $oldAutoCommit;
-      return "deleting usage pools: $error";
+  unless ($date) {
+    foreach my $usage ( $self->cust_pkg_usage ) {
+      $error = $usage->delete;
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "deleting usage pools: $error";
+      }
     }
   }
 
@@ -1278,6 +1283,9 @@ separately.
 =item from_main - allows a supplemental package to be suspended, rather
 than redirecting the method call to its main package.  For internal use.
 
+=item from_cancel - used when suspending from the cancel method, forces
+this to skip everything besides basic suspension.  For internal use.
+
 =back
 
 If there is an error, returns the error, otherwise returns false.
@@ -1327,7 +1335,7 @@ sub suspend {
   }
 
   # some false laziness with sub cancel
-  if ( !$options{nobill} && !$date &&
+  if ( !$options{nobill} && !$date && !$options{'from_cancel'} &&
        $self->part_pkg->option('bill_suspend_as_cancel',1) ) {
     # kind of a kludge--'bill_suspend_as_cancel' to avoid having to 
     # make the entire cust_main->bill path recognize 'suspend' and 
@@ -1392,17 +1400,19 @@ sub suspend {
 
   unless ( $date ) { # then we are suspending now
 
-    # credit remaining time if appropriate
-    # (if required by the package def, or the suspend reason)
-    my $unused_credit = $self->part_pkg->option('unused_credit_suspend',1)
-                        || ( defined($reason) && $reason->unused_credit );
+    unless ($options{'from_cancel'}) {
+      # credit remaining time if appropriate
+      # (if required by the package def, or the suspend reason)
+      my $unused_credit = $self->part_pkg->option('unused_credit_suspend',1)
+                          || ( defined($reason) && $reason->unused_credit );
 
-    if ( $unused_credit ) {
-      warn "crediting unused time on pkg#".$self->pkgnum."\n" if $DEBUG;
-      my $error = $self->credit_remaining('suspend', $suspend_time);
-      if ($error) {
-        $dbh->rollback if $oldAutoCommit;
-        return $error;
+      if ( $unused_credit ) {
+        warn "crediting unused time on pkg#".$self->pkgnum."\n" if $DEBUG;
+        my $error = $self->credit_remaining('suspend', $suspend_time);
+        if ($error) {
+          $dbh->rollback if $oldAutoCommit;
+          return $error;
+        }
       }
     }
 
@@ -1433,7 +1443,7 @@ sub suspend {
     }
 
     my $conf = new FS::Conf;
-    if ( $conf->config('suspend_email_admin') ) {
+    if ( $conf->config('suspend_email_admin') && !$options{'from_cancel'} ) {
  
       my $error = send_email(
         'from'    => $conf->config('invoice_from', $self->cust_main->agentnum),

commit 598f5364ffaab833463442f910fc9c533975e317
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Feb 16 15:30:37 2015 -0600

    RT#14671: Usage for current day when billing outstanding usage (for cancelling customers) [better supplemental package handling]

diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 079a865..69f7bc0 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -949,7 +949,11 @@ sub cancel {
   }
 
   foreach my $supp_pkg ( $self->supplemental_pkgs ) {
-    $error = $supp_pkg->cancel(%options, 'from_main' => 1);
+    if ($delay_cancel) {
+        $error = $supp_pkg->suspend(%options, 'from_main' => 1, 'reason' => undef);
+    } else {
+        $error = $supp_pkg->cancel(%options, 'from_main' => 1);
+    }
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
       return "canceling supplemental pkg#".$supp_pkg->pkgnum.": $error";

commit efa870992fa06350b1e1d75a53b7e0c42f59f59b
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Feb 10 14:18:31 2015 -0600

    RT#14671: Usage for current day when billing outstanding usage (for cancelling customers)

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 07f910d..d7b0bb9 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4658,6 +4658,16 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'part_pkg-delay_cancel-days',
+    'section'     => '',
+    'description' => 'Expire packages in this many days when using delay_cancel (default is 1)',
+    'type'        => 'text',
+    'validate'    => sub { (($_[0] =~ /^\d*$/) && (($_[0] eq '') || $_[0]))
+                           ? 'Must specify an integer number of days'
+                           : '' }
+  },
+
+  {
     'key'         => 'mcp_svcpart',
     'section'     => '',
     'description' => 'Master Control Program svcpart.  Leave this blank.',
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index e049320..7d80746 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -4250,6 +4250,27 @@ sub cust_status {
   }
 }
 
+=item is_status_delay_cancel
+
+Returns true if customer status is 'suspended'
+and all suspended cust_pkg return true for
+cust_pkg->is_status_delay_cancel.
+
+This is not a real status, this only meant for hacking display 
+values, because otherwise treating the customer as suspended is 
+really the whole point of the delay_cancel option.
+
+=cut
+
+sub is_status_delay_cancel {
+  my ($self) = @_;
+  return 0 unless $self->status eq 'suspended';
+  foreach my $cust_pkg ($self->ncancelled_pkgs) {
+    return 0 unless $cust_pkg->is_status_delay_cancel;
+  }
+  return 1;
+}
+
 =item ucfirst_cust_status
 
 =item ucfirst_status
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 3c9eab8..079a865 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -837,6 +837,20 @@ sub cancel {
   my $date = $options{'date'} if $options{'date'}; # expire/cancel later
   $date = '' if ($date && $date <= $cancel_time);      # complain instead?
 
+  my $delay_cancel = undef;
+  if ( !$date && $self->part_pkg->option('delay_cancel',1)
+       && (($self->status eq 'active') || ($self->status eq 'suspended'))
+  ) {
+    my $expdays = $conf->config('part_pkg-delay_cancel-days') || 1;
+    my $expsecs = 60*60*24*$expdays;
+    my $suspfor = $self->susp ? $cancel_time - $self->susp : 0;
+    $expsecs = $expsecs - $suspfor if $suspfor;
+    unless ($expsecs <= 0) { #if it's already been suspended long enough, don't re-suspend
+      $delay_cancel = 1;
+      $date = $cancel_time + $expsecs;
+    }
+  }
+
   #race condition: usage could be ongoing until unprovisioned
   #resolved by performing a change package instead (which unprovisions) and
   #later cancelling
@@ -907,6 +921,11 @@ sub cancel {
   my %hash = $self->hash;
   if ( $date ) {
     $hash{'expire'} = $date;
+    if ($delay_cancel) {
+      $hash{'susp'} = $cancel_time unless $self->susp;
+      $hash{'adjourn'} = undef;
+      $hash{'resume'} = undef;
+    }
   } else {
     $hash{'cancel'} = $cancel_time;
   }
@@ -3367,6 +3386,31 @@ sub statuscolor {
   $statuscolor{$self->status};
 }
 
+=item is_status_delay_cancel
+
+Returns true if part_pkg has option delay_cancel, 
+cust_pkg status is 'suspended' and expire is set
+to cancel package within the next day (or however
+many days are set in global config part_pkg-delay_cancel-days.
+
+This is not a real status, this only meant for hacking display 
+values, because otherwise treating the package as suspended is 
+really the whole point of the delay_cancel option.
+
+=cut
+
+sub is_status_delay_cancel {
+  my ($self) = @_;
+  return 0 unless $self->part_pkg->option('delay_cancel',1);
+  return 0 unless $self->status eq 'suspended';
+  return 0 unless $self->expire;
+  my $conf = new FS::Conf;
+  my $expdays = $conf->config('part_pkg-delay_cancel-days') || 1;
+  my $expsecs = 60*60*24*$expdays;
+  return 0 unless $self->expire < time + $expsecs;
+  return 1;
+}
+
 =item pkg_label
 
 Returns a label for this package.  (Currently "pkgnum: pkg - comment" or
diff --git a/FS/FS/part_pkg/global_Mixin.pm b/FS/FS/part_pkg/global_Mixin.pm
index 2637729..2318c3e 100644
--- a/FS/FS/part_pkg/global_Mixin.pm
+++ b/FS/FS/part_pkg/global_Mixin.pm
@@ -40,6 +40,10 @@ tie my %a2billing_simultaccess, 'Tie::IxHash', (
                 'changing packages',
       'type' => 'checkbox',
     },
+    'delay_cancel' => {
+      'name' => 'Automatically suspend for one day before cancelling',
+      'type' => 'checkbox',
+    },
 
     # miscellany--maybe put this in a separate module?
 
@@ -109,6 +113,7 @@ tie my %a2billing_simultaccess, 'Tie::IxHash', (
     unused_credit_cancel
     unused_credit_suspend
     unused_credit_change
+    delay_cancel
 
     a2billing_tariff
     a2billing_type
diff --git a/httemplate/view/cust_main/misc.html b/httemplate/view/cust_main/misc.html
index 0d011f6..fe0e329 100644
--- a/httemplate/view/cust_main/misc.html
+++ b/httemplate/view/cust_main/misc.html
@@ -7,7 +7,7 @@
 
 <TR>
   <TD ALIGN="right"><% mt('Status') |h %></TD>
-  <TD BGCOLOR="#ffffff"><FONT COLOR="#<% $cust_main->statuscolor %>"><B><% ucfirst($cust_main->status) %></B></FONT></TD>
+  <TD BGCOLOR="#ffffff"><FONT COLOR="#<% $cust_main->statuscolor %>"><B><% $status_label %></B></FONT></TD>
 </TR>
 
 % my @part_tag = $cust_main->part_tag;
@@ -204,4 +204,9 @@ my $curuser = $FS::CurrentUser::CurrentUser;
 
 my @agentnums = $curuser->agentnums;
 
+my $status_label = $cust_main->status_label;
+if ($cust_main->is_status_delay_cancel) {
+  $status_label .= ' (Cancelled)';
+}
+
 </%init>

commit 20a1e12e4dd57dfa69979918d4da524a30d36462
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Feb 10 14:08:14 2015 -0600

    Bug fix: list returned by cust_main->cancel was being displayed in scalar context

diff --git a/httemplate/misc/cust_main-cancel.cgi b/httemplate/misc/cust_main-cancel.cgi
index a78a8b3..f6fd1e9 100755
--- a/httemplate/misc/cust_main-cancel.cgi
+++ b/httemplate/misc/cust_main-cancel.cgi
@@ -54,10 +54,11 @@ if ( $error ) {
 }
 else {
   warn "cancelling $cust_main";
-  $error = $cust_main->cancel(
+  my @error = $cust_main->cancel( #returns list of errors
     'ban'    => $ban,
     'reason' => $reasonnum,
   );
+  $error = join(', ', at error);
 }
 
 if ( $error ) {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm                                  |   10 +++
 FS/FS/cust_main.pm                             |   21 +++++
 FS/FS/cust_pkg.pm                              |  106 +++++++++++++++++++-----
 FS/FS/part_pkg/global_Mixin.pm                 |    5 ++
 httemplate/misc/cust_main-cancel.cgi           |    3 +-
 httemplate/view/cust_main/misc.html            |    7 +-
 httemplate/view/cust_main/packages/status.html |   12 ++-
 7 files changed, 140 insertions(+), 24 deletions(-)




More information about the freeside-commits mailing list