diff options
author | levinse <levinse> | 2011-04-29 12:10:50 +0000 |
---|---|---|
committer | levinse <levinse> | 2011-04-29 12:10:50 +0000 |
commit | 8acc996345752f44f9bf55eff088f03739019c33 (patch) | |
tree | 266f28a86df27e0621c3fea9e384a66bce1b5312 /FS | |
parent | afd1c0b1cc9074a008885033b2ca32c24f62a8e4 (diff) |
apply discount to setup fees, part 1 of 2, RT11512
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Schema.pm | 1 | ||||
-rw-r--r-- | FS/FS/cust_pkg.pm | 3 | ||||
-rw-r--r-- | FS/FS/cust_pkg_discount.pm | 1 | ||||
-rw-r--r-- | FS/FS/discount.pm | 7 | ||||
-rw-r--r-- | FS/FS/part_pkg/discount_Mixin.pm | 18 |
5 files changed, 26 insertions, 4 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index a90e26921..32ab3807a 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1429,6 +1429,7 @@ sub tables_hashref { 'percent', 'decimal', '', '', '', '', 'months', 'decimal', 'NULL', '', '', '', 'disabled', 'char', 'NULL', 1, '', '', + 'setup', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'discountnum', 'unique' => [], diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 539c8fb43..8babbe529 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -30,6 +30,7 @@ use FS::reason; use FS::cust_pkg_discount; use FS::discount; use FS::UI::Web; +use Data::Dumper; # need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend, # setup } @@ -1411,7 +1412,6 @@ sub change { } -use Data::Dumper; use Storable 'thaw'; use MIME::Base64; sub process_bulk_cust_pkg { @@ -2603,6 +2603,7 @@ sub insert_discount { 'amount' => $self->discountnum_amount, 'percent' => $self->discountnum_percent, 'months' => $self->discountnum_months, + 'setup' => $self->discountnum_setup, #'disabled' => $self->discountnum_disabled, }; diff --git a/FS/FS/cust_pkg_discount.pm b/FS/FS/cust_pkg_discount.pm index 7b6b203b8..d41f497a6 100644 --- a/FS/FS/cust_pkg_discount.pm +++ b/FS/FS/cust_pkg_discount.pm @@ -106,6 +106,7 @@ sub insert { 'amount' => $self->amount, 'percent' => $self->percent, 'months' => $self->months, + 'setup' => $self->setup, 'disabled' => 'Y', }; my $error = $discount->insert; diff --git a/FS/FS/discount.pm b/FS/FS/discount.pm index 4f42c5b72..6fc3391ca 100644 --- a/FS/FS/discount.pm +++ b/FS/FS/discount.pm @@ -54,6 +54,11 @@ months disabled +=item setup - apply discount to setup fee (not just to recurring fee) + +If the discount is based on a percentage, then the % will be applied to the +setup and recurring portions. + =back =head1 METHODS @@ -130,6 +135,7 @@ sub check { || $self->ut_float('percent') #actually decimal, but this will do || $self->ut_floatn('months') #actually decimal, but this will do || $self->ut_enum('disabled', [ '', 'Y' ]) + || $self->ut_enum('setup', [ '', 'Y' ]) ; return $error if $error; @@ -176,6 +182,7 @@ sub description { my $self = shift; my $desc = $self->description_short; $desc .= ' for '. $self->months. ' months' if $self->months; + $desc .= ', applies to setup' if $self->setup; $desc; } 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; |