[freeside-commits] branch FREESIDE_3_BRANCH updated. 7334227ea36b450e71c028e7ba564f91e7d4d1de

Mark Wells mark at 420.am
Mon Oct 17 16:38:46 PDT 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  7334227ea36b450e71c028e7ba564f91e7d4d1de (commit)
       via  1383836efb374d3dd10fec5830d2071d639916ff (commit)
       via  d9a6a1d8912bd059941bddc7875eb920a47cd8c5 (commit)
      from  eade44a93547afab49b043ac9b66ca432cffab21 (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 7334227ea36b450e71c028e7ba564f91e7d4d1de
Merge: 1383836 eade44a
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Oct 17 16:15:54 2016 -0700

    Merge branch 'FREESIDE_3_BRANCH' of git.freeside.biz:/home/git/freeside into 3.x


commit 1383836efb374d3dd10fec5830d2071d639916ff
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Oct 17 16:03:13 2016 -0700

    limit unused-time credit if the invoice already has credits applied, #72873, from #42729

diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 467b54d..b5506f6 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1792,6 +1792,8 @@ sub credit_remaining {
         # the cancellation date (can happen with advance billing). in that
         # case, use the entire recurring charge:
         my $amount = $cust_bill_pkg->recur - $cust_bill_pkg->usage;
+        my $max_credit = $amount
+            - $cust_bill_pkg->credited('', '', setuprecur => 'recur') || 0;
 
         # but if the cancellation happens during the interval, prorate it:
         # (XXX obey prorate_round_day here?)
@@ -1800,14 +1802,23 @@ sub credit_remaining {
                       ($edate - $time) / ($edate - $cust_bill_pkg->sdate);
         }
 
+        # if there are existing credits, don't let the sum of credits exceed
+        # the recurring charge
+        $amount = $max_credit if $amount > $max_credit;
+
         $amount = sprintf('%.2f', $amount);
 
-        push @billpkgnums, $cust_bill_pkg->billpkgnum;
-        push @amounts,     $amount;
-        push @setuprecurs, 'recur';
+        # if no time has been used and/or there are existing line item
+        # credits, we may end up not needing to credit anything.
+        if ( $amount > 0 ) {
 
-        warn "Crediting for $amount on package ".$remain_pkg->pkgnum."\n"
-          if $DEBUG;
+          push @billpkgnums, $cust_bill_pkg->billpkgnum;
+          push @amounts,     $amount;
+          push @setuprecurs, 'recur';
+
+          warn "Crediting for $amount on package ".$remain_pkg->pkgnum."\n"
+            if $DEBUG;
+        }
 
       }
 

commit d9a6a1d8912bd059941bddc7875eb920a47cd8c5
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Oct 17 15:16:40 2016 -0700

    if asked to credit a zero-amount line item, skip it rather than throwing an error, #72873, from #26925

diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index 18f4a32..ca41075 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -743,10 +743,12 @@ sub calculate_tax_adjustment {
     if ($recur) {
       $recur -= $cust_bill_pkg->credited('', '', setuprecur => 'recur') || 0;
     }
+    # Skip line items that have been completely credited.
+    next if ($setup + $recur) == 0;
     my $setup_ratio = $setup / ($setup + $recur);
 
-    # Calculate the fraction of tax to credit: it's the fraction of this charge
-    # (either setup or recur) that's being credited.
+    # Calculate the fraction of tax to credit: it's the fraction of this
+    # charge (either setup or recur) that's being credited.
     my $charged = ($setuprecur eq 'setup') ? $setup : $recur;
     next if $charged == 0; # shouldn't happen, but still...
 
@@ -911,7 +913,7 @@ sub credit_lineitems {
     my $invnum = $cust_bill_pkg->invnum;
 
     $need_to_unapply -= $cust_bill_pkg->owed($setuprecur);
-    next if $need_to_unapply < 0.005;
+    return if $need_to_unapply < 0.005;
 
     my $error;
     # then unapply payments one at a time (partially if need be) until the

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

Summary of changes:
 FS/FS/cust_credit.pm |    8 +++++---
 FS/FS/cust_pkg.pm    |   21 ++++++++++++++++-----
 2 files changed, 21 insertions(+), 8 deletions(-)




More information about the freeside-commits mailing list