my $pass = ($cust_pkg->no_auto || $part_pkg->no_auto) ? 'no_auto' : '';
- my $error =
- $self->_make_lines( 'part_pkg' => $part_pkg,
- 'cust_pkg' => $cust_pkg,
- 'precommit_hooks' => \@precommit_hooks,
- 'line_items' => $cust_bill_pkg{$pass},
- 'setup' => $total_setup{$pass},
- 'recur' => $total_recur{$pass},
- 'tax_matrix' => $taxlisthash{$pass},
- 'time' => $time,
- 'real_pkgpart' => $real_pkgpart,
- 'options' => \%options,
- );
+ my $next_bill = $cust_pkg->getfield('bill') || 0;
+ my $error;
+ while ( $next_bill <= $time ) {
+ $error =
+ $self->_make_lines( 'part_pkg' => $part_pkg,
+ 'cust_pkg' => $cust_pkg,
+ 'precommit_hooks' => \@precommit_hooks,
+ 'line_items' => $cust_bill_pkg{$pass},
+ 'setup' => $total_setup{$pass},
+ 'recur' => $total_recur{$pass},
+ 'tax_matrix' => $taxlisthash{$pass},
+ 'time' => $time,
+ 'real_pkgpart' => $real_pkgpart,
+ 'options' => \%options,
+ );
+ # Stop if anything goes wrong, or if we're not incrementing
+ # the bill date.
+ last if $error;
+ last if ($cust_pkg->getfield('bill') || 0) == $next_bill;
+ $next_bill = $cust_pkg->getfield('bill') || 0;
+ }
if ($error) {
$dbh->rollback if $oldAutoCommit && !$options{no_commit};
return $error;
my $setup = 0;
my $unitsetup = 0;
+ my %setup_param = ();
if ( ! $options{recurring_only}
and ! $options{cancel}
and ( $options{'resetup'}
unless ( $cust_pkg->waive_setup ) {
$lineitems++;
- $setup = eval { $cust_pkg->calc_setup( $time, \@details ) };
+ $setup = eval { $cust_pkg->calc_setup( $time, \@details, \%setup_param ) };
return "$@ running calc_setup for $cust_pkg\n"
if $@;
'real_pkgpart' => $real_pkgpart,
'freq_override' => $options{freq_override} || '',
'setup_fee' => 0,
+ %setup_param,
);
my $method = $options{cancel} ? 'calc_cancel' : 'calc_recur';
$lineitems++;
}
+ if ( defined $param{'discount_left_setup'} ) {
+ foreach my $discount_setup ( values %{$param{'discount_left_setup'}} ) {
+ $setup -= $discount_setup;
+ }
+ }
+
}
warn "\$setup is undefined" unless defined($setup);