X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fdiscount_plan.pm;h=6a456766d4d790599f2e13428f8656ab45db041d;hp=4f97e3351dc99b5c59c61a4e053e720fb748b29d;hb=ff27c3f36240aee48ed50153dd5d8fe3ac3f2443;hpb=ee2ee290c82013f870e2b23e4235e70998e59ee1 diff --git a/FS/FS/discount_plan.pm b/FS/FS/discount_plan.pm index 4f97e3351..6a456766d 100644 --- a/FS/FS/discount_plan.pm +++ b/FS/FS/discount_plan.pm @@ -63,7 +63,7 @@ sub new { my $recur = $cust_bill_pkg->recur || 0; if ( $freq eq '1' ) { # monthly recurring package - my $permonth = $part_pkg->base_recur_permonth || 0; + my $permonth = $part_pkg->base_recur_permonth($cust_pkg) || 0; my ($discount) = grep { $_->months == $months } map { $_->discount } $part_pkg->part_pkg_discount; @@ -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