[freeside-commits] branch master updated. b3cc20aeca25e4351c6ec3b795a951e6124f6376

Jonathan Prykop jonathan at 420.am
Mon Mar 14 21:41:12 PDT 2016


The branch, master has been updated
       via  b3cc20aeca25e4351c6ec3b795a951e6124f6376 (commit)
      from  2ffdb485e5534df3d89bcc12d4d02d485e9b28f5 (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 b3cc20aeca25e4351c6ec3b795a951e6124f6376
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Mon Mar 14 23:39:18 2016 -0500

    RT#28648: Unsuspend when past due balance is paid

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 72b449c..47eccf8 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -1967,10 +1967,13 @@ and customer address. Include units.',
   },
 
   {
-    'key'         => 'unsuspendauto',
+    'key'         => 'unsuspend_balance',
     'section'     => 'billing',
-    'description' => 'Enables the automatic unsuspension of suspended packages when a customer\'s balance due changes from positive to zero or negative as the result of a payment or credit',
-    'type'        => 'checkbox',
+    'description' => 'Enables the automatic unsuspension of suspended packages when a customer\'s balance due is at or below the specified amount after a payment or credit',
+    'type'        => 'select',
+    'select_enum' => [ 
+      '', 'Zero', 'Latest invoice charges'
+    ],
   },
 
   {
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index 4be4b17..094437e 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -3,7 +3,7 @@ use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::reason_Mixin
              FS::Record );
 
 use strict;
-use vars qw( $conf $unsuspendauto $me $DEBUG
+use vars qw( $conf $me $DEBUG
              $otaker_upgrade_kludge $ignore_empty_reasonnum
            );
 use List::Util qw( min );
@@ -34,7 +34,6 @@ $ignore_empty_reasonnum = 0;
 $FS::UID::callback{'FS::cust_credit'} = sub { 
 
   $conf = new FS::Conf;
-  $unsuspendauto = $conf->exists('unsuspendauto');
 
 };
 
@@ -210,16 +209,8 @@ sub insert {
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
-  #false laziness w/ cust_pay::insert
-  if ( $unsuspendauto && $old_balance && $cust_main->balance <= 0 ) {
-    my @errors = $cust_main->unsuspend;
-    #return 
-    # side-fx with nested transactions?  upstack rolls back?
-    warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
-         join(' / ', @errors)
-      if @errors;
-  }
-  #eslaf
+  # possibly trigger package unsuspend, doesn't abort transaction on failure
+  $self->unsuspend_balance if $old_balance;
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index de13847..9b4ae3a 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -654,6 +654,45 @@ sub time2str_local {
   $string;
 }
 
+=item unsuspend_balance
+
+If conf I<unsuspend_balance> is set and customer's current balance is
+beneath the set threshold, unsuspends customer packages.
+
+=cut
+
+sub unsuspend_balance {
+  my $self = shift;
+  my $cust_main = $self->cust_main;
+  my $conf = $self->conf;
+  my $setting = $conf->config('unsuspend_balance');
+  my $maxbalance;
+  if ($setting eq 'Zero') {
+    $maxbalance = 0;
+  } elsif ($setting eq 'Latest invoice charges') {
+    my @cust_bill = $cust_main->cust_bill();
+    my $cust_bill = $cust_bill[-1]; #always want the most recent one
+    return unless $cust_bill;
+    $maxbalance = $cust_bill->charged || 0;
+  } elsif (length($setting)) {
+    warn "Unrecognized unsuspend_balance setting $setting";
+    return;
+  } else {
+    return;
+  }
+  my $balance = $cust_main->balance || 0;
+  if ($balance <= $maxbalance) {
+    # or should this be 
+    # my @errors = grep { ($_->get('setup')) && $_->unsuspend } $cust_main->unflagged_suspended_pkgs;
+    my @errors = $cust_main->unsuspend;
+    # side-fx with nested transactions?  upstack rolls back?
+    warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
+         join(' / ', @errors)
+      if @errors;
+  }
+  return;
+}
+
 =back
 
 =head1 BUGS
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 620f6c6..86e7968 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -4,7 +4,7 @@ use strict;
 use base qw( FS::otaker_Mixin FS::payinfo_transaction_Mixin FS::cust_main_Mixin
              FS::reason_Mixin FS::Record);
 use vars qw( $DEBUG $me $conf @encrypted_fields
-             $unsuspendauto $ignore_noapply
+             $ignore_noapply
            );
 use Date::Format;
 use Business::CreditCard;
@@ -36,7 +36,6 @@ $ignore_noapply = 0;
 #ask FS::UID to run this stuff for us later
 FS::UID->install_callback( sub { 
   $conf = new FS::Conf;
-  $unsuspendauto = $conf->exists('unsuspendauto');
 } );
 
 @encrypted_fields = ('payinfo');
@@ -355,16 +354,8 @@ sub insert {
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
-  #false laziness w/ cust_credit::insert
-  if ( $unsuspendauto && $old_balance && $cust_main->balance <= 0 ) {
-    my @errors = $cust_main->unsuspend;
-    #return 
-    # side-fx with nested transactions?  upstack rolls back?
-    warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".
-         join(' / ', @errors)
-      if @errors;
-  }
-  #eslaf
+  # possibly trigger package unsuspend, doesn't abort transaction on failure
+  $self->unsuspend_balance if $old_balance;
 
   #bill setup fees for voip_cdr bill_every_call packages
   #some false laziness w/search in freeside-cdrd
@@ -1214,6 +1205,15 @@ sub _upgrade_data {  #class method
       process_upgrade_paybatch();
     }
   }
+
+  # unsuspendauto upgrade
+  # could just as easily go in cust_credit, or even cust_bill or cust_main
+  # but here works
+  if ($conf->exists('unsuspendauto') && !$conf->config('unsuspend_balance')) {
+    $conf->set('unsuspend_balance','Zero');
+    $conf->delete('unsuspendauto');
+  }
+
 }
 
 sub process_upgrade_paybatch {

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

Summary of changes:
 FS/FS/Conf.pm            |    9 ++++++---
 FS/FS/cust_credit.pm     |   15 +++------------
 FS/FS/cust_main_Mixin.pm |   39 +++++++++++++++++++++++++++++++++++++++
 FS/FS/cust_pay.pm        |   24 ++++++++++++------------
 4 files changed, 60 insertions(+), 27 deletions(-)




More information about the freeside-commits mailing list