RT#25563: Better handling of commissions which do not have rates configured [more...
[freeside.git] / FS / FS / part_event / Action / Mixin / credit_bill.pm
index 694f965..91fa21f 100644 (file)
@@ -50,6 +50,7 @@ our %part_pkg_cache;
 # 2. the recipient of the commission; may be FS::sales, FS::agent, 
 # FS::access_user, etc. Here we don't use it, but it will be passed through
 # to _calc_credit_percent.
+# 3. optional scalar reference for recording a warning message
 
 sub _calc_credit {
   my $self = shift;
@@ -106,9 +107,12 @@ sub _calc_credit {
     # don't multiply by quantity here; it's already included
   }
 
-  $$warnref .= $warning if ref($warnref);
+  if ($charge < 0) { # e.g. prorate
+    $charge = 0;
+    $warning .= 'Negative charge set to zero ';
+  }
 
-  $charge = 0 if $charge < 0; # e.g. prorate
+  $$warnref .= $warning if ref($warnref);
   return ($percent * $charge / 100);
 }