From: Jonathan Prykop <jonathan@freeside.biz>
Date: Wed, 16 Sep 2015 06:59:07 +0000 (-0500)
Subject: RT#36813: Monthly Recurring Total [change_to_pkgnum handling]
X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=62bfe13409a16e04599f52edb3ce00ee3031a0f9

RT#36813: Monthly Recurring Total [change_to_pkgnum handling]
---

diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html
index c031ce929..f7ea68a65 100644
--- a/httemplate/view/cust_main/billing.html
+++ b/httemplate/view/cust_main/billing.html
@@ -44,11 +44,13 @@
 %       'hashref'   => { 'custnum' => $cust_main->custnum, },
 %       'extra_sql' => 'AND ( cancel IS NULL OR cancel = 0 )
 %                       AND freq = '. dbh->quote($freq),
+%       'order_by'  => 'ORDER BY pkgnum', # to ensure old pkgs come before change_to_pkg
 %     }) or next;
 % 
 %     my $freq_pretty = $cust_pkg[0]->part_pkg->freq_pretty;
 %
 %     my $amount = 0;
+%     my $skip_pkg = {};
 %     foreach my $cust_pkg (@cust_pkg) {
 %       my $part_pkg = $cust_pkg->part_pkg;
 %       next if $cust_pkg->susp
@@ -57,6 +59,15 @@
 %                 || $cust_pkg->option('no_suspend_bill')
 %               );
 %
+%       #pkg change handling
+%       next if $skip_pkg->{$cust_pkg->pkgnum};
+%       if ($cust_pkg->change_to_pkgnum) {
+%         #if change is on or before next bill date, use new pkg
+%         next if $cust_pkg->expire <= $cust_pkg->bill;
+%         #if change is after next bill date, use old (this) pkg
+%         $skip_pkg->{$cust_pkg->change_to_pkgnum} = 1;
+%       }
+%
 %       my $pkg_amount = 0;
 %
 %       #add recurring amounts for this package and its billing add-ons