[freeside-commits] branch master updated. 068b074adcb3cd0c4d0b39d407c7bb2272a9cade

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


The branch, master has been updated
       via  068b074adcb3cd0c4d0b39d407c7bb2272a9cade (commit)
       via  76aa1ddd3ef1c63972fa4e940cbdc9a84fde35a1 (commit)
       via  b25a5e64054fed0ba59842442a5921ba5a3d1071 (commit)
      from  389b6f1116c3309c2ee57a6c295ed1a793503095 (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 068b074adcb3cd0c4d0b39d407c7bb2272a9cade
Merge: 76aa1dd 389b6f1
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Oct 17 16:15:00 2016 -0700

    Merge branch 'master' of git.freeside.biz:/home/git/freeside


commit 76aa1ddd3ef1c63972fa4e940cbdc9a84fde35a1
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 2c75506..714d292 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -1810,6 +1810,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?)
@@ -1818,14 +1820,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 b25a5e64054fed0ba59842442a5921ba5a3d1071
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 aebf259..6249713 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -728,10 +728,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...
 
@@ -900,7 +902,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