X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_event%2FAction%2FMixin%2Fcredit_pkg.pm;h=2842218f3509babeb383726dd4cff13a3aaf50df;hp=400ece97b4cc02d4244370a8636ef10722293dbb;hb=e8e6cb9e129eb20fef8e4fa19239c76b4280cf5f;hpb=a2671c1396fed27ff620a58fb46773408d21d194 diff --git a/FS/FS/part_event/Action/Mixin/credit_pkg.pm b/FS/FS/part_event/Action/Mixin/credit_pkg.pm index 400ece97b..2842218f3 100644 --- a/FS/FS/part_event/Action/Mixin/credit_pkg.pm +++ b/FS/FS/part_event/Action/Mixin/credit_pkg.pm @@ -52,10 +52,14 @@ sub option_fields { # arguments: # 1. cust_pkg # 2. recipient of the credit (passed through to _calc_credit_percent) +# 3. optional scalar reference for recording a warning message sub _calc_credit { my $self = shift; my $cust_pkg = shift; + my $who = shift; + my $warnref = shift; + my $warning = ''; my $cust_main = $self->cust_main($cust_pkg); @@ -75,15 +79,19 @@ sub _calc_credit { my $percent; if ( $self->can('_calc_credit_percent') ) { - $percent = $self->_calc_credit_percent($cust_pkg, @_); + $percent = $self->_calc_credit_percent($cust_pkg, $who) || 0; + $warning = 'Percent calculated to zero ' unless $percent+0; } else { $percent = $self->option('percent') || 0; + $warning = 'Percent set to zero ' unless $percent+0; } my @arg = ($what eq 'setup_cost') ? () : ($cust_pkg); + my $charge = $part_pkg->$what(@arg) || 0; + $warning .= "$what is zero" unless $charge+0; - sprintf('%.2f', $part_pkg->$what(@arg) * $percent / 100 ); - + $$warnref .= $warning if ref($warnref); + return sprintf('%.2f', $charge * $percent / 100 ); } 1;