fix term discount display, #16965
authorMark Wells <mark@freeside.biz>
Sat, 17 Mar 2012 23:29:29 +0000 (16:29 -0700)
committerMark Wells <mark@freeside.biz>
Sat, 17 Mar 2012 23:29:29 +0000 (16:29 -0700)
FS/FS/cust_bill.pm
FS/FS/discount_plan.pm

index bb44c05..3aa75ec 100644 (file)
@@ -5261,6 +5261,9 @@ sub _items_discounts_avail {
                  join(', ', map { "#$_" } $plan->pkgnums)
       if $list_pkgnums;
 
+    # discounts for non-integer months don't work anyway
+    $months = sprintf("%d", $months);
+
     +{
       description => $self->mt('Save [_1]% by paying for [_2] months',
                                 $percent, $months),
index 3ae44c8..6a45676 100644 (file)
@@ -80,19 +80,24 @@ sub new {
           $self->{discounted} += $setup;
         }
 
-        if ( $discount->percent ) {
+        if ( $discount->percent > 0 ) {
           $discountable += $months * $permonth;
           $discountable -= ($discountable * $discount->percent / 100);
           $discountable -= ($permonth - $recur); # correct for prorate
           $self->{discounted} += $discountable;
         }
-        else {
+        elsif ( $discount->amount > 0 ) {
           $discountable += $recur;
           $discountable -= $discount->amount * $recur/$permonth;
           $discountable += ($months - 1) * max($permonth - $discount->amount,0);
+          $self->{discounted} += $discountable;
+        }
+        else {
+          warn "discountnum ".$discount->discountnum.
+            " has no amount or percentage, ignored\n";
+          $self->{discounted} = $self->{base};
         }
 
-        $self->{discounted} += $discountable;
         push @{ $self->{pkgnums} }, $cust_pkg->pkgnum;
       }
       else { #no discount