[freeside-commits] branch master updated. 4d0db1129018d2f598091edbbffeb09b23c64d99

Jonathan Prykop jonathan at 420.am
Tue Feb 10 12:19:43 PST 2015


The branch, master has been updated
       via  4d0db1129018d2f598091edbbffeb09b23c64d99 (commit)
       via  8c84e8692d48eff3b03822dcd18c1766fd0b9bca (commit)
       via  d9ab02b37871572303a9d3c47cd8b3d79e37cce9 (commit)
       via  0db02d518080007ae5c682836390cdb5e14ac916 (commit)
      from  ad1d603d9e9a813e697c267d29fefd00fee56ae7 (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 4d0db1129018d2f598091edbbffeb09b23c64d99
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 a4e26f7..091070e 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4627,6 +4627,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 d38f3d0..c3b141e 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -3900,6 +3900,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 56e4c90..1cc83b6 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -823,6 +823,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
@@ -893,6 +907,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;
   }
@@ -3343,6 +3362,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 15def32..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><% $cust_main->status_label %></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 8c84e8692d48eff3b03822dcd18c1766fd0b9bca
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Feb 10 14:12:13 2015 -0600

    Bug fix: checking ref() instead of defined()

diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 3bd2107..56e4c90 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1643,7 +1643,7 @@ sub unsuspend {
          )
       or $hash{'order_date'} == $hash{'susp'}
       or $self->part_pkg->option('unused_credit_suspend')
-      or ( defined($reason) and $reason->unused_credit )
+      or ( ref($reason) and $reason->unused_credit )
   ) {
     $adjust_bill = 0;
   }

commit d9ab02b37871572303a9d3c47cd8b3d79e37cce9
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 ) {

commit 0db02d518080007ae5c682836390cdb5e14ac916
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Tue Feb 10 14:06:29 2015 -0600

    Bug fix: removed unintended variable localization

diff --git a/FS/FS/reason.pm b/FS/FS/reason.pm
index 864804d..9c34dd9 100644
--- a/FS/FS/reason.pm
+++ b/FS/FS/reason.pm
@@ -174,7 +174,7 @@ sub new_or_existing {
     }
   } else {
     my %hash = ('class' => $opt{'class'}, 'type' => $opt{'type'});
-    my $reason_type = qsearchs('reason_type', \%hash)
+    $reason_type = qsearchs('reason_type', \%hash)
                       || FS::reason_type->new(\%hash);
 
     $error = $reason_type->insert unless $reason_type->typenum;

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

Summary of changes:
 FS/FS/Conf.pm                        |   10 ++++++++
 FS/FS/cust_main.pm                   |   21 ++++++++++++++++
 FS/FS/cust_pkg.pm                    |   46 +++++++++++++++++++++++++++++++++-
 FS/FS/part_pkg/global_Mixin.pm       |    5 ++++
 FS/FS/reason.pm                      |    2 +-
 httemplate/misc/cust_main-cancel.cgi |    3 ++-
 httemplate/view/cust_main/misc.html  |    7 +++++-
 7 files changed, 90 insertions(+), 4 deletions(-)




More information about the freeside-commits mailing list