#UI enforces one or the other (for now? probably for good)
my $amount = 0;
$amount += $discount->amount
- if defined $param->{'real_pkgpart'} && $cust_pkg->pkgpart == $param->{'real_pkgpart'};
+ if $cust_pkg->pkgpart == $param->{'real_pkgpart'};
$amount += sprintf('%.2f', $discount->percent * $br / 100 );
- my $chg_months = $param->{'months'} || $cust_pkg->part_pkg->freq;
+ my $chg_months = defined($param->{'months'}) ?
+ $param->{'months'} :
+ $cust_pkg->part_pkg->freq;
my $months = $discount->months
? min( $chg_months,
}
if ( ! defined $param->{'setup_charge'} ) {
- my $error = $cust_pkg_discount->increment_months_used($months)
- if defined $param->{'real_pkgpart'}
- && $cust_pkg->pkgpart == $param->{'real_pkgpart'};
- die "error discounting: $error" if $error;
+ if ( $cust_pkg->pkgpart == $param->{'real_pkgpart'} ) {
+ push @{ $param->{precommit_hooks} }, sub {
+ my $error = $cust_pkg_discount->increment_months_used($months);
+ die "error discounting: $error" if $error;
+ };
+ }
$amount = min($amount, $br);
$amount *= $months;
}
- $amount = sprintf('%.2f', $amount);
+ $amount = sprintf('%.2f', $amount + 0.00000001 ); #so 1.005 rounds to 1.01
next unless $amount > 0;