From c7bf005860b761a55ca075df987fb3b5ade8c242 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 10 Jun 2011 03:33:44 +0000 Subject: [PATCH] add package def option to show $0 recurring on invoices, RT#9777 --- FS/FS/Schema.pm | 3 +- FS/FS/cust_bill.pm | 64 ++++++++++++++++++-------------- FS/FS/cust_bill_pkg.pm | 28 ++++++++++++-- FS/FS/cust_main/Billing.pm | 36 ++++++++++++++---- FS/FS/part_pkg.pm | 1 + httemplate/browse/part_pkg.cgi | 10 ++++- httemplate/edit/part_pkg.cgi | 35 ++++++++++++++++- httemplate/elements/checkbox.html | 6 +++ httemplate/elements/input-text.html | 4 +- httemplate/elements/tr-select-agent.html | 6 ++- 10 files changed, 148 insertions(+), 45 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index ab4752f4b..25912a22f 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1626,7 +1626,8 @@ sub tables_hashref { 'credit_weight', 'real', 'NULL', '', '', '', 'agentnum', 'int', 'NULL', '', '', '', 'fcc_ds0s', 'int', 'NULL', '', '', '', - 'no_auto', 'char', 'NULL', 1, '', '', + 'no_auto', 'char', 'NULL', 1, '', '', + 'recur_show_zero', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'pkgpart', 'unique' => [], diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index fd3b63820..7106d1fa8 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -4575,23 +4575,10 @@ sub _items_cust_bill_pkg { foreach my $cust_bill_pkg ( @$cust_bill_pkgs ) { - warn "$me _items_cust_bill_pkg considering cust_bill_pkg $cust_bill_pkg\n" + warn "$me _items_cust_bill_pkg considering cust_bill_pkg ". + $cust_bill_pkg->billpkgnum. ", pkgnum ". $cust_bill_pkg->pkgnum. "\n" if $DEBUG > 1; - $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 && !$discount_show_always ); - $_ = undef; - } - } - foreach my $display ( grep { defined($section) ? $_->section eq $section : 1 @@ -4670,9 +4657,13 @@ sub _items_cust_bill_pkg { } - 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' ) + if ( ( !$type || $type eq 'R' || $type eq 'U' ) + && ( + $cust_bill_pkg->recur != 0 + || $cust_bill_pkg->setup == 0 + || $discount_show_always + || $cust_bill_pkg->recur_show_zero + ) ) { @@ -4817,21 +4808,38 @@ sub _items_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, { %$_ } + if $_->{amount} != 0 + || $discount_show_always + || $cust_bill_pkg->recur_show_zero; + $_ = undef; + } + } + } + #foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) { + # if ( $_ ) { + # $_->{amount} = sprintf( "%.2f", $_->{amount} ), + # $_->{amount} =~ s/^\-0\.00$/0.00/; + # $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ), + # push @b, { %$_ } + # if $_->{amount} != 0 + # || $discount_show_always + # } + #} + warn "$me _items_cust_bill_pkg done considering cust_bill_pkgs\n" if $DEBUG > 1; - foreach ( $s, $r, ($opt{skip_usage} ? () : $u ) ) { - if ( $_ ) { - $_->{amount} = sprintf( "%.2f", $_->{amount} ), - $_->{amount} =~ s/^\-0\.00$/0.00/; - $_->{unit_amount} = sprintf( "%.2f", $_->{unit_amount} ), - push @b, { %$_ } - unless ( $_->{amount} == 0 && !$discount_show_always ); - } - } - @b; } diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 37c4a2735..2c79209c5 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -413,7 +413,8 @@ sub previous_cust_bill_pkg { Returns an array of detail information for the invoice line item. -Currently available options are: I I +Currently available options are: I, I and +I. If I is set to html or latex then the array members are improved for tabular appearance in those environments if possible. @@ -421,6 +422,12 @@ for tabular appearance in those environments if possible. If I is set then the array members are processed by this function before being returned. +I overrides the normal HTML or LaTeX function for returning +formatted CDRs. It can be set to a subroutine which returns an empty list +to skip usage detail: + + 'format_function' => sub { () }, + =cut sub details { @@ -872,7 +879,7 @@ sub cust_bill_pkg_detail { my %hash = ( 'billpkgnum' => $self->billpkgnum ); $hash{classnum} = $classnum if $classnum; - qsearch ( 'cust_bill_pkg_detail', { %hash } ), + qsearch( 'cust_bill_pkg_detail', \%hash ), } @@ -883,8 +890,21 @@ 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 } ); + my $self = shift; + qsearch( 'cust_bill_pkg_discount', { 'billpkgnum' => $self->billpkgnum } ); +} + +=item recur_show_zero + +=cut + +sub recur_show_zero { + my $self = shift; + + $self->recur == 0 + && $self->pkgnum + && $self->cust_pkg->part_pkg->recur_show_zero; + } =back diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm index f6a608053..d565a327c 100644 --- a/FS/FS/cust_main/Billing.pm +++ b/FS/FS/cust_main/Billing.pm @@ -603,27 +603,47 @@ sub bill { #discard bundled packages of 0 value sub _omit_zero_value_bundles { + my @in = @_; my @cust_bill_pkg = (); my @cust_bill_pkg_bundle = (); my $sum = 0; my $discount_show_always = 0; - foreach my $cust_bill_pkg ( @_ ) { + foreach my $cust_bill_pkg ( @in ) { + $discount_show_always = ($cust_bill_pkg->get('discounts') && scalar(@{$cust_bill_pkg->get('discounts')}) && $conf->exists('discount-show-always')); + + warn " pkgnum ". $cust_bill_pkg->pkgnum. + " sum $sum, recur_show_zero ". $cust_bill_pkg->recur_show_zero. "\n" + if $DEBUG > 0; + if (scalar(@cust_bill_pkg_bundle) && !$cust_bill_pkg->pkgpart_override) { push @cust_bill_pkg, @cust_bill_pkg_bundle - if ($sum > 0 || ($sum == 0 && $discount_show_always)); + if $sum > 0 + || ($sum == 0 && ( $discount_show_always + || grep $_->recur_show_zero, @cust_bill_pkg_bundle ) + ); @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 || ($sum == 0 && $discount_show_always)); + if $sum > 0 + || ($sum == 0 && ( $discount_show_always + || grep $_->recur_show_zero, @cust_bill_pkg_bundle ) + ); + + warn " _omit_zero_value_bundles: ". scalar(@in). + '->'. scalar(@cust_bill_pkg). "\n" #. Dumper(@cust_bill_pkg). "\n" + if $DEBUG > 2; (@cust_bill_pkg); @@ -1024,10 +1044,12 @@ sub _make_lines { 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 - $discount_show_always ) + if ( $setup != 0 + || $recur != 0 + || (!$part_pkg->hidden && $options{has_hidden}) #include some $0 lines + || $discount_show_always + || ($recur == 0 && $part_pkg->recur_show_zero) + ) { warn " charges (setup=$setup, recur=$recur); adding line items\n" diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 17af4d73f..285970009 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -553,6 +553,7 @@ sub check { || $self->ut_enum('disabled', [ '', 'Y' ] ) || $self->ut_enum('custom', [ '', 'Y' ] ) || $self->ut_enum('no_auto', [ '', 'Y' ]) + || $self->ut_enum('recur_show_zero', [ '', 'Y' ]) #|| $self->ut_moneyn('setup_cost') #|| $self->ut_moneyn('recur_cost') || $self->ut_floatn('setup_cost') diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index dd20f8d31..ae869dda6 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -226,7 +226,7 @@ push @fields, sub { ], [ { data=>( $is_recur - ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') ) + ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee')) : $part_pkg->freq_pretty ), align=> ( $is_recur ? 'right' : 'center' ), @@ -239,6 +239,14 @@ push @fields, sub { : () ), ], + [ { data => + ( $part_pkg->option('recur_fee') == 0 && $part_pkg->recur_show_zero ) + ? ' (printed on invoices)' + : '', + align => 'center', #? + colspan => 2, + }, + ], ( map { my $dst_pkg = $_->dst_pkg; [ diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index be8b0f68f..93a3b24c3 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -45,6 +45,7 @@ 'agentnum' => 'Agent', 'setup_fee' => 'Setup fee', 'recur_fee' => 'Recurring fee', + 'recur_show_zero' => 'Show zero recurring', 'discountnum' => 'Offer discounts for longer terms', 'bill_dst_pkgpart' => 'Include line item(s) from package', 'svc_dst_pkgpart' => 'Include services of package', @@ -107,8 +108,15 @@ { field => 'recur_fee', type => 'money', disabled => sub { $recur_disabled }, + onchange => 'recur_changed', }, - + + { field => 'recur_show_zero', + type => 'checkbox', + value => 'Y', + disabled => sub { $recur_show_zero_disabled }, + }, + #price plan #setup fee #recurring frequency @@ -324,6 +332,7 @@ my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) ); my %options = (); my $recur_disabled = 1; +my $recur_show_zero_disabled = 1; my $pkgpart = ''; @@ -335,6 +344,10 @@ my $error_callback = sub { $opt->{action} = 'Custom' if $cgi->param('pkgnum'); $recur_disabled = $cgi->param('freq') ? 0 : 1; + $recur_show_zero_disabled = + $cgi->param('freq') + ? $cgi->param('recur_fee') ? 0 : 1 + : 1; foreach ($cgi->param) { /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1); @@ -512,16 +525,34 @@ my $javascript = <<'END'; if ( freq == '0' ) { what.form.recur_fee.disabled = true; what.form.recur_fee.style.backgroundColor = '#dddddd'; + what.form.recur_show_zero.disabled = true; + //what.form.recur_show_zero.style.backgroundColor= '#dddddd'; } else { what.form.recur_fee.disabled = false; what.form.recur_fee.style.backgroundColor = '#ffffff'; + what.form.recur_show_zero.disabled = false; + //what.form.recur_show_zero.style.backgroundColor= '#ffffff'; } } + function recur_changed(what) { + var recur = what.value; + if ( recur == 0 ) { + what.form.recur_show_zero.disabled = false; + } else { + what.form.recur_show_zero.disabled = true; + } + } + function agent_changed(what) { - var agentnum = what.options[what.selectedIndex].value; + var agentnum; + if ( what.type == 'select-one' ) { + agentnum = what.options[what.selectedIndex].value; + } else { + agentnum = what.value; + } if ( agentnum == 0 ) { what.form.agent_type.disabled = false; diff --git a/httemplate/elements/checkbox.html b/httemplate/elements/checkbox.html index 51760701e..91efe8578 100644 --- a/httemplate/elements/checkbox.html +++ b/httemplate/elements/checkbox.html @@ -6,6 +6,7 @@ ? ' CHECKED' : '' %> + <% $opt{disabled} %> <% $onchange %> ><% $opt{'postfix'} %> <%init> @@ -16,4 +17,9 @@ my $onchange = $opt{'onchange'} ? 'onChange="'. $opt{'onchange'}. '(this)"' : ''; +$opt{'disabled'} = &{ $opt{'disabled'} }( \%opt ) + if ref($opt{'disabled'}) eq 'CODE'; +$opt{'disabled'} = 'DISABLED' + if $opt{'disabled'} && $opt{'disabled'} !~ /disabled/i; # uuh... yeah? + diff --git a/httemplate/elements/input-text.html b/httemplate/elements/input-text.html index fb50a5070..827941501 100644 --- a/httemplate/elements/input-text.html +++ b/httemplate/elements/input-text.html @@ -15,7 +15,9 @@ my %opt = @_; my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value}; my $onchange = $opt{'onchange'} - ? 'onChange="'. $opt{'onchange'}. '(this)"' + ? join(' ', map $_.'="'. $opt{'onchange'}. '(this)"', + qw( onChange onKeyDown onKeyUp onKeyPress ) + ) : ''; my $size = $opt{'size'} diff --git a/httemplate/elements/tr-select-agent.html b/httemplate/elements/tr-select-agent.html index 0985d1aa7..ce03c40f5 100644 --- a/httemplate/elements/tr-select-agent.html +++ b/httemplate/elements/tr-select-agent.html @@ -24,7 +24,11 @@ Example: % if ( scalar(@agents) == 1 ) { - + %# YUCK. empty row so we don't throw g_row in edit.html off :/ -- 2.11.0