[freeside-commits] branch FREESIDE_4_BRANCH updated. c768181f5e2f4fd5ffcc02e504ce6fa6d73b3922

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


The branch, FREESIDE_4_BRANCH has been updated
       via  c768181f5e2f4fd5ffcc02e504ce6fa6d73b3922 (commit)
       via  3bfc810bd02e6b822964cbabda2480a21b61ff38 (commit)
       via  e1bd031f800327e3efcc35ae2715794b85352a94 (commit)
      from  096bb3e9f98031580ad03d08d0695fcf96ee8cf0 (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 c768181f5e2f4fd5ffcc02e504ce6fa6d73b3922
Merge: 3bfc810 096bb3e
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Oct 17 16:15:44 2016 -0700

    Merge branch 'FREESIDE_4_BRANCH' of git.freeside.biz:/home/git/freeside into 4.x


commit 3bfc810bd02e6b822964cbabda2480a21b61ff38
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 634895a..4de2faa 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1817,6 +1817,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?)
@@ -1825,14 +1827,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 e1bd031f800327e3efcc35ae2715794b85352a94
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 eaff6e8..dfc4c80 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -727,10 +727,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...
 
@@ -899,7 +901,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