diff options
author | levinse <levinse> | 2011-04-29 12:12:45 +0000 |
---|---|---|
committer | levinse <levinse> | 2011-04-29 12:12:45 +0000 |
commit | e774555a6ae69da65e7774c701232fdf9dd052b1 (patch) | |
tree | 3807379817a297a53b27b1f6d8c8c7ec758f6713 /FS/FS/part_pkg/discount_Mixin.pm | |
parent | 91fd4ea0e91ee9e6717e0b12e01eebb8f8b21322 (diff) |
apply discount to setup fees, part 1 of 2, RT11512
Diffstat (limited to 'FS/FS/part_pkg/discount_Mixin.pm')
-rw-r--r-- | FS/FS/part_pkg/discount_Mixin.pm | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/FS/FS/part_pkg/discount_Mixin.pm b/FS/FS/part_pkg/discount_Mixin.pm index 83f1a77..8ce5ba8 100644 --- a/FS/FS/part_pkg/discount_Mixin.pm +++ b/FS/FS/part_pkg/discount_Mixin.pm @@ -43,6 +43,8 @@ sub calc_discount { my $br = $self->base_recur($cust_pkg, $sdate); $br += $param->{'override_charges'} if $param->{'override_charges'}; + + return 0 if defined $param->{'setup_charge'} && $param->{'setup_charge'} == 0; my $tot_discount = 0; #UI enforces just 1 for now, will need ordering when they can be stacked @@ -90,9 +92,19 @@ sub calc_discount { ? min( $chg_months, $discount->months - $cust_pkg_discount->months_used ) : $chg_months; + + if(defined $param->{'setup_charge'}) { + next unless $discount->setup; + + if ( $discount->percent ) { + $amount = sprintf('%.2f', $discount->percent * $param->{'setup_charge'} / 100 ); + $months = 1; + } + } my $error = $cust_pkg_discount->increment_months_used($months) - if $cust_pkg->pkgpart == $param->{real_pkgpart}; + if ($cust_pkg->pkgpart == $param->{real_pkgpart} + && ! defined $param->{'setup_charge'}); die "error discounting: $error" if $error; $amount *= $months; @@ -114,9 +126,9 @@ sub calc_discount { $months = sprintf('%.2f', $months) if $months =~ /\./; my $d = 'Includes '; - $d .= $discount->name. ' ' if $discount->name; + $d .= 'setup ' if defined $param->{'setup_charge'}; $d .= 'discount of '. $discount->description_short; - $d .= " for $months month". ( $months!=1 ? 's' : '' ); + $d .= " for $months month". ( $months!=1 ? 's' : '' ) unless defined $param->{'setup_charge'}; $d .= ": $money_char$amount" if $months != 1 || $discount->percent; push @$details, $d; |