fix over-discounting resulting in an error, RT#13450
[freeside.git] / FS / FS / part_pkg / discount_Mixin.pm
index 17e2f53..87ec3a7 100644 (file)
@@ -120,6 +120,9 @@ sub calc_discount {
         $param->{'discount_left_recur'}{$discount->discountnum} = 0;
         $months = 1;
     }
+    elsif ( $discount->setup && $discount->months == 1 && $discount->amount ) {
+        next;
+    }
 
     my $error = $cust_pkg_discount->increment_months_used($months)
         if (defined $param->{'real_pkgpart'} 
@@ -127,11 +130,12 @@ sub calc_discount {
             && ! defined $param->{'setup_charge'});
     die "error discounting: $error" if $error;
 
+    $amount = min($amount, $br);
     $amount *= $months;
     $amount = sprintf('%.2f', $amount);
 
     next unless $amount > 0;
-            
+
     # transfer remainder of discount, if any, to setup
     if ( $discount->setup && $discount->amount
         && (!$discount->months || $discount->months != 1)