From e93b81ba22b5f772fbbea7370cde3b9760ef7080 Mon Sep 17 00:00:00 2001 From: levinse Date: Thu, 13 Jan 2011 16:35:16 +0000 Subject: [PATCH] optionally generate line items which are fully discounted, RT10481 --- FS/FS/Conf.pm | 7 +++++++ FS/FS/cust_bill.pm | 11 ++++++++--- FS/FS/cust_bill_pkg.pm | 11 +++++++++++ FS/FS/cust_main/Billing.pm | 24 ++++++++++++++++++------ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index e3fc7e33a..ea9a536f9 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -653,6 +653,13 @@ my %payment_gateway_options = ( 'description' => 'IP address to assign to new virtual hosts', 'type' => 'text', }, + + { + 'key' => 'discount-show-always', + 'section' => 'billing', + 'description' => 'Generate a line item on an invoice even when a package is discounted 100%', + 'type' => 'checkbox', + }, { 'key' => 'encryption', diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 7727c9982..b54a1d15b 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -4125,19 +4125,23 @@ sub _items_cust_bill_pkg { my $summary_page = $opt{summary_page} || ''; my $multilocation = $opt{multilocation} || ''; my $multisection = $opt{multisection} || ''; + my $discount_show_always = 0; my @b = (); my ($s, $r, $u) = ( undef, undef, undef ); foreach my $cust_bill_pkg ( @$cust_bill_pkg ) { + $discount_show_always = ($cust_bill_pkg->cust_bill_pkg_discount + && $conf->exists('discount-show-always')); + foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) { if ( $_ && !$cust_bill_pkg->hidden ) { $_->{amount} = sprintf( "%.2f", $_->{amount} ), $_->{amount} =~ s/^\-0\.00$/0.00/; $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ), push @b, { %$_ } - unless $_->{amount} == 0; + unless ( $_->{amount} == 0 && !$discount_show_always ); $_ = undef; } } @@ -4211,7 +4215,8 @@ sub _items_cust_bill_pkg { } - if ( ( $cust_bill_pkg->recur != 0 || $cust_bill_pkg->setup == 0 ) && + if ( ( $cust_bill_pkg->recur != 0 || $cust_bill_pkg->setup == 0 || + ($discount_show_always && $cust_bill_pkg->recur == 0) ) && ( !$type || $type eq 'R' || $type eq 'U' ) ) { @@ -4336,7 +4341,7 @@ sub _items_cust_bill_pkg { $_->{amount} =~ s/^\-0\.00$/0.00/; $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ), push @b, { %$_ } - unless $_->{amount} == 0; + unless ( $_->{amount} == 0 && !$discount_show_always ); } } diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index d396f8239..aa6c90b47 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -874,6 +874,17 @@ sub cust_bill_pkg_detail { } +=item cust_bill_pkg_discount + +Returns the list of associated cust_bill_pkg_discount objects. + +=cut + +sub cust_bill_pkg_discount { + my $self = shift; + qsearch ( 'cust_bill_pkg_discount', { 'billpkgnum' => $self->billpkgnum } ); +} + =back =head1 BUGS diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm index 9fa1e4168..7ae3d459e 100644 --- a/FS/FS/cust_main/Billing.pm +++ b/FS/FS/cust_main/Billing.pm @@ -584,17 +584,23 @@ sub _omit_zero_value_bundles { 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); @@ -956,9 +962,13 @@ sub _make_lines { 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" @@ -1004,9 +1014,11 @@ sub _make_lines { # 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; -- 2.11.0