X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fdiscount_Mixin.pm;h=8ce5ba8755cbfa3ac52388b82e8ab37271b6337d;hp=83f1a77c1cd3d3aef56fe225de49d5785afc153a;hb=e774555a6ae69da65e7774c701232fdf9dd052b1;hpb=91fd4ea0e91ee9e6717e0b12e01eebb8f8b21322 diff --git a/FS/FS/part_pkg/discount_Mixin.pm b/FS/FS/part_pkg/discount_Mixin.pm index 83f1a77c1..8ce5ba875 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;