package FS::part_pkg::discount_Mixin;
use strict;
-use vars qw(@ISA %info);
-use FS::part_pkg;
+use vars qw( %info );
+use Time::Local qw( timelocal );
+use List::Util qw( min );
use FS::cust_pkg;
use FS::cust_bill_pkg_discount;
-use Time::Local qw(timelocal);
-use List::Util 'min';
-@ISA = qw(FS::part_pkg);
%info = ( 'disabled' => 1 );
=head1 NAME
sub calc_discount {
my($self, $cust_pkg, $sdate, $details, $param ) = @_;
- my $br = $self->base_recur($cust_pkg, $sdate);
+ my $br = $self->base_recur_permonth($cust_pkg, $sdate);
$br += $param->{'override_charges'} if $param->{'override_charges'};
my $tot_discount = 0;
$param->{'discount_left_recur'}{$discount->discountnum} = 0;
$months = 1;
}
+ elsif ( $discount->setup && $discount->months == 1 && $discount->amount ) {
+ next;
+ }
my $error = $cust_pkg_discount->increment_months_used($months)
if (defined $param->{'real_pkgpart'}
&& ! defined $param->{'setup_charge'});
die "error discounting: $error" if $error;
+ $amount = min($amount, $br);
$amount *= $months;
$amount = sprintf('%.2f', $amount);
next unless $amount > 0;
-
+
# transfer remainder of discount, if any, to setup
if ( $discount->setup && $discount->amount
&& (!$discount->months || $discount->months != 1)