projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
apply discount to setup fees, part 1 of 2, RT11512
[freeside.git]
/
FS
/
FS
/
part_pkg
/
discount_Mixin.pm
diff --git
a/FS/FS/part_pkg/discount_Mixin.pm
b/FS/FS/part_pkg/discount_Mixin.pm
index
83f1a77
..
8ce5ba8
100644
(file)
--- 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'};
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
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;
? 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)
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;
die "error discounting: $error" if $error;
$amount *= $months;
@@
-114,9
+126,9
@@
sub calc_discount {
$months = sprintf('%.2f', $months) if $months =~ /\./;
my $d = 'Includes ';
$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 .= '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;
$d .= ": $money_char$amount" if $months != 1 || $discount->percent;
push @$details, $d;