#create the new invoice
my $cust_bill = new FS::cust_bill ( {
'custnum' => $self->custnum,
- '_date' => ( $invoice_time ),
+ '_date' => $invoice_time,
'charged' => $charged,
'billing_balance' => $balance,
'previous_balance' => $previous_balance,
my @cust_bill_pkg = ();
my @cust_bill_pkg_bundle = ();
my $sum = 0;
+ my $discount_show_always = 0;
foreach my $cust_bill_pkg ( @_ ) {
+ $discount_show_always = ($cust_bill_pkg->get('discounts')
+ && scalar(@{$cust_bill_pkg->get('discounts')})
+ && $conf->exists('discount-show-always'));
if (scalar(@cust_bill_pkg_bundle) && !$cust_bill_pkg->pkgpart_override) {
- push @cust_bill_pkg, @cust_bill_pkg_bundle if $sum > 0;
+ push @cust_bill_pkg, @cust_bill_pkg_bundle
+ if ($sum > 0 || ($sum == 0 && $discount_show_always));
@cust_bill_pkg_bundle = ();
$sum = 0;
}
$sum += $cust_bill_pkg->setup + $cust_bill_pkg->recur;
push @cust_bill_pkg_bundle, $cust_bill_pkg;
}
- push @cust_bill_pkg, @cust_bill_pkg_bundle if $sum > 0;
+ push @cust_bill_pkg, @cust_bill_pkg_bundle
+ if ($sum > 0 || ($sum == 0 && $discount_show_always));
(@cust_bill_pkg);
'discounts' => \@discounts,
'real_pkgpart' => $real_pkgpart,
'freq_override' => $options{freq_override} || '',
+ 'setup_fee' => 0,
);
my $method = $options{cancel} ? 'calc_cancel' : 'calc_recur';
}
+ if ( $param{'setup_fee'} ) {
+ # Add an additional setup fee at the billing stage.
+ # Used for prorate_defer_bill.
+ $setup += $param{'setup_fee'};
+ $unitsetup += $param{'setup_fee'};
+ $lineitems++;
+ }
+
}
warn "\$setup is undefined" unless defined($setup);
if $DEBUG >1;
my $error = $cust_pkg->replace( $old_cust_pkg,
+ 'depend_jobnum'=>$options{depend_jobnum},
'options' => { $cust_pkg->options },
)
unless $options{no_commit};
return "negative recur $recur for pkgnum ". $cust_pkg->pkgnum;
}
+ my $discount_show_always = ($recur == 0 && scalar(@discounts)
+ && $conf->exists('discount-show-always'));
+
if ( $setup != 0 ||
$recur != 0 ||
- !$part_pkg->hidden && $options{has_hidden} ) #include some $0 lines
+ (!$part_pkg->hidden && $options{has_hidden}) || #include some $0 lines
+ $discount_show_always )
{
warn " charges (setup=$setup, recur=$recur); adding line items\n"
# handle taxes
###
- my $error =
- $self->_handle_taxes($part_pkg, $taxlisthash, $cust_bill_pkg, $cust_pkg, $options{invoice_time}, $real_pkgpart, \%options);
- return $error if $error;
+ unless ( $discount_show_always ) {
+ my $error =
+ $self->_handle_taxes($part_pkg, $taxlisthash, $cust_bill_pkg, $cust_pkg, $options{invoice_time}, $real_pkgpart, \%options);
+ return $error if $error;
+ }
push @$cust_bill_pkgs, $cust_bill_pkg;
=back
+=head1 FLOW
+
+ bill_and_collect
+
+ cancel_expired_pkgs
+ suspend_adjourned_pkgs
+
+ bill
+ (do_cust_event pre-bill)
+ _make_lines
+ _handle_taxes
+ (vendor-only) _gather_taxes
+ _omit_zero_value_bundles
+ calculate_taxes
+
+ apply_payments_and_credits
+ collect
+ do_cust_event
+ due_cust_event
+
=head1 BUGS
=head1 SEE ALSO