$options{'skip_usage'} =
scalar(@$extra_sections) && !grep{$section == $_} @$extra_sections;
$options{'multilocation'} = $multilocation;
+ $options{'multisection'} = $multisection;
foreach my $line_item ( $self->_items_pkg(%options) ) {
my $detail = {
my $section = $opt{section}->{description} if $opt{section};
my $summary_page = $opt{summary_page} || '';
my $multilocation = $opt{multilocation} || '';
+ my $multisection = $opt{multisection} || '';
my @b = ();
my ($s, $r, $u) = ( undef, undef, undef );
? $_->section eq $section
: 1
}
- grep { !$_->summary || !$summary_page }
+ #grep { !$_->summary || !$summary_page } # bunk!
+ grep { !$_->summary || $multisection }
$cust_bill_pkg->cust_bill_pkg_display
)
{
}
- if ( $cust_bill_pkg->recur != 0 &&
+ if ( ( $cust_bill_pkg->recur != 0 || $cust_bill_pkg->setup == 0 ) &&
( !$type || $type eq 'R' || $type eq 'U' )
)
{
};
}
- } elsif ( $amount ) { # && $type eq 'U'
+ } else { # $type eq 'U'
if ( $cust_bill_pkg->hidden ) {
$u->{amount} += $amount;
my $real_pkgpart = $cust_pkg->pkgpart;
my %hash = $cust_pkg->hash;
- foreach my $part_pkg ( $cust_pkg->part_pkg->self_and_bill_linked ) {
+ # we could implement this bit as FS::part_pkg::has_hidden, but we already
+ # suffer from performance issues
+ $options{has_hidden} = 0;
+ my @part_pkg = $cust_pkg->part_pkg->self_and_bill_linked;
+ $options{has_hidden} = 1 if ($part_pkg[1] && $part_pkg[1]->hidden);
+
+ foreach my $part_pkg ( @part_pkg ) {
$cust_pkg->set($_, $hash{$_}) foreach qw ( setup last_bill bill );
} elsif ( $postal_pkg ) {
my $real_pkgpart = $postal_pkg->pkgpart;
- foreach my $part_pkg ( $postal_pkg->part_pkg->self_and_bill_linked ) {
+ # we could implement this bit as FS::part_pkg::has_hidden, but we already
+ # suffer from performance issues
+ $options{has_hidden} = 0;
+ my @part_pkg = $postal_pkg->part_pkg->self_and_bill_linked;
+ $options{has_hidden} = 1 if ($part_pkg[1] && $part_pkg[1]->hidden);
+
+ foreach my $part_pkg ( @part_pkg ) {
my %postal_options = %options;
delete $postal_options{cancel};
my $error =
return "can't create invoice for customer #". $self->custnum. ": $error";
}
+ my @cust_bill_pkg_bundle = ();
foreach my $cust_bill_pkg ( @cust_bill_pkg ) {
$cust_bill_pkg->invnum($cust_bill->invnum);
- my $error = $cust_bill_pkg->insert;
+ if (scalar(@cust_bill_pkg_bundle) && !$cust_bill_pkg->pkgpart_override) {
+ $error = $self->_insert_cust_bill_pkg_bundle( @cust_bill_pkg_bundle );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ @cust_bill_pkg_bundle = ();
+ }
+ push @cust_bill_pkg_bundle, $cust_bill_pkg;
+ }
+ if (scalar(@cust_bill_pkg_bundle)) {
+ $error = $self->_insert_cust_bill_pkg_bundle( @cust_bill_pkg_bundle );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
- return "can't create invoice line item: $error";
+ return $error;
}
}
''; #no error
}
+#insert line items while discarding bundled packages of 0 value
+sub _insert_cust_bill_pkg_bundle {
+ my $self = shift;
+ my @cust_bill_pkg = @_;
+
+ my $sum = 0;
+ $sum += $_->setup + $_->recur foreach @cust_bill_pkg;
+ return '' unless $sum > 0;
+
+ foreach my $cust_bill_pkg ( @cust_bill_pkg ) {
+ my $error = $cust_bill_pkg->insert;
+ return "can't create invoice line item: $error" if $error;
+ }
+
+}
+
=item calculate_taxes LINEITEMREF TAXHASHREF INVOICE_TIME
This is a weird one. Perhaps it should not even be exposed.
# If $cust_pkg has been modified, update it (if we're a real pkgpart)
###
- if ( $lineitems ) {
+ if ( $lineitems || $options{has_hidden} ) {
if ( $cust_pkg->modified && $cust_pkg->pkgpart == $real_pkgpart ) {
# hmm.. and if just the options are modified in some weird price plan?
return "negative recur $recur for pkgnum ". $cust_pkg->pkgnum;
}
- if ( $setup != 0 || $recur != 0 ) {
+ if ( $setup != 0 ||
+ $recur != 0 ||
+ !$part_pkg->hidden && $options{has_hidden} ) #include some $0 lines
+ {
warn " charges (setup=$setup, recur=$recur); adding line items\n"
if $DEBUG > 1;
my @display = ();
my $separate = $conf->exists('separate_usage');
- my $usage_mandate = $cust_pkg->part_pkg->option('usage_mandate', 'Hush!');
- if ( $separate || $cust_bill_pkg->hidden || $usage_mandate ) {
+ my $temp_pkg = new FS::cust_pkg { pkgpart => $real_pkgpart };
+ my $usage_mandate = $temp_pkg->part_pkg->option('usage_mandate', 'Hush!');
+ my $section = $temp_pkg->part_pkg->categoryname;
+ if ( $separate || $section || $usage_mandate ) {
- my $temp_pkg = new FS::cust_pkg { pkgpart => $real_pkgpart };
- my %hash = $cust_bill_pkg->hidden # maybe for all bill linked?
- ? ( 'section' => $temp_pkg->part_pkg->categoryname )
- : ();
+ my %hash = ( 'section' => $section );
- my $section = $cust_pkg->part_pkg->option('usage_section', 'Hush!');
- my $summary = $cust_pkg->part_pkg->option('summarize_usage', 'Hush!');
+ $section = $temp_pkg->part_pkg->option('usage_section', 'Hush!');
+ my $summary = $temp_pkg->part_pkg->option('summarize_usage', 'Hush!');
if ( $separate ) {
push @display, new FS::cust_bill_pkg_display { type => 'S', %hash };
push @display, new FS::cust_bill_pkg_display { type => 'R', %hash };
$hash{post_total} = 'Y';
}
- $hash{section} = $section if ($separate || $usage_mandate);
- push @display, new FS::cust_bill_pkg_display { type => 'U', %hash };
+ if ($separate || $usage_mandate) {
+ $hash{section} = $section if ($separate || $usage_mandate);
+ push @display, new FS::cust_bill_pkg_display { type => 'U', %hash };
+ }
}
$cust_bill_pkg->set('display', \@display);