[freeside-commits] branch master updated. 167c155032545af623972ffb449455810d0a2b78

Mark Wells mark at 420.am
Tue Jan 27 22:47:02 PST 2015


The branch, master has been updated
       via  167c155032545af623972ffb449455810d0a2b78 (commit)
      from  65b94bd80599a27c658b792f02c85d200488688d (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 167c155032545af623972ffb449455810d0a2b78
Author: Mark Wells <mark at freeside.biz>
Date:   Tue Jan 27 22:46:55 2015 -0800

    show months used/remaining in discounts on invoices, #31273, #32959

diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index 1fed7f1..996cb55 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -3448,8 +3448,29 @@ sub _items_cust_bill_pkg {
                 ext_description => \@ext,
               };
               foreach my $cust_bill_pkg_discount (@discounts) {
-                my $def = $cust_bill_pkg_discount->cust_pkg_discount->discount;
-                push @ext, &{$escape_function}( $def->description );
+                my $discount = $cust_bill_pkg_discount->cust_pkg_discount->discount;
+                my $discount_desc = $discount->description_short;
+
+                if ($discount->months) {
+
+                  # calculate months remaining after this invoice
+                  my $used = FS::Record->scalar_sql(
+                    'SELECT SUM(months) FROM cust_bill_pkg_discount
+                      JOIN cust_bill_pkg USING (billpkgnum)
+                      JOIN cust_bill USING (invnum)
+                      WHERE pkgdiscountnum = ? AND _date <= ?',
+                    $cust_bill_pkg_discount->pkgdiscountnum,
+                    $self->_date
+                  );
+                  $used ||= 0;
+                  my $remaining = sprintf('%.2f', $discount->months - $used);
+                  # append "for X months (Y months remaining)"
+                  $discount_desc .= $self->mt(' for [quant,_1,month] ([quant,_2,month] remaining)',
+                    $cust_bill_pkg_discount->months,
+                    $remaining
+                  );
+                } # else it's not time-limited
+                push @ext, &{$escape_function}($discount_desc);
               }
             }
 


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

Summary of changes:
 FS/FS/Template_Mixin.pm |   25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)




More information about the freeside-commits mailing list