sub base_setup {
my($self, $cust_pkg, $sdate, $details ) = @_;
-
- $self->option('setup_fee') || 0;
+ ( exists( $self->{'Hash'}{'_opt_setup_fee'} )
+ ? $self->{'Hash'}{'_opt_setup_fee'}
+ : $self->option('setup_fee', 1)
+ )
+ || 0;
}
sub calc_recur {
sub base_recur {
my($self, $cust_pkg, $sdate) = @_;
- $self->option('recur_fee', 1) || 0;
+ ( exists( $self->{'Hash'}{'_opt_recur_fee'} )
+ ? $self->{'Hash'}{'_opt_recur_fee'}
+ : $self->option('recur_fee', 1)
+ )
+ || 0;
}
sub base_recur_permonth {
foreach my $cust_bill_pkg (
qsearch('cust_bill_pkg', {
pkgnum => $cust_pkg->pkgnum,
- sdate => {op => '<' , value => $time},
edate => {op => '>=', value => $time},
recur => {op => '>' , value => 0},
})
$edate = $self->add_freq($cust_bill_pkg->sdate);
}
- my $amount = ($cust_bill_pkg->recur - $cust_bill_pkg->usage) *
- ($edate - $time) / ($edate - $cust_bill_pkg->sdate);
+ # this will also get any package charges that are _entirely_ after the
+ # cancellation date (can happen with advance billing). in that case,
+ # use the entire recurring charge:
+ my $amount = $cust_bill_pkg->recur - $cust_bill_pkg->usage;
+
+ # but if the cancellation happens during the interval, prorate it:
+ # (XXX obey prorate_round_day here?)
+ if ( $cust_bill_pkg->sdate < $time ) {
+ $amount = $amount * ($edate - $time) / ($edate - $cust_bill_pkg->sdate);
+ }
+
$credit += $amount;
push @{ $options{'cust_credit_source_bill_pkg'} },