From d2b55d07a9e6e64a38877136d7974ab93e14f1ed Mon Sep 17 00:00:00 2001 From: Mitch Jackson Date: Tue, 13 Feb 2018 18:11:03 -0600 Subject: [PATCH] RT# 79284 Updated discounts UI for Change Package screen --- httemplate/elements/select-table.html | 19 ++++++++++++++----- httemplate/elements/tr-select-pkg-discount.html | 24 +++++++++++++++++++++++- httemplate/misc/change_pkg.cgi | 8 +++++--- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index 6fb6b388b..a52fdfaaa 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -195,13 +195,22 @@ if ( ref( $value ) eq 'ARRAY' ) { $value = { map { $_ => 1 } @$value }; } -unless ( !ref($value) && $value < 1 # !$value #ignore negatives too - or ! exists( $opt{hashref}->{disabled} ) #?? - #or grep { $value == $_->$key() } @records - ) { + +if ( + (ref $value && $value) + or (ref $opt{hashref} && exists $opt{hashref}->{disabled}) + or $opt{also_show_option} +) { + delete $opt{hashref}->{disabled}; - foreach my $v ( ref($value) ? keys %$value : ($value) ) { + # also_show_option: (hack for change_pkg form): + # Include an absent select option, without selecting it + # as the curr_value + my @also_show = ref($value) ? keys %$value : ($value); + push @also_show, $opt{also_show_option} if $opt{also_show_option}; + + foreach my $v ( @also_show ) { next if grep { $v == $_->$key() } @records; $opt{hashref}->{$key} = $v; diff --git a/httemplate/elements/tr-select-pkg-discount.html b/httemplate/elements/tr-select-pkg-discount.html index 39b0ff31f..810e46230 100644 --- a/httemplate/elements/tr-select-pkg-discount.html +++ b/httemplate/elements/tr-select-pkg-discount.html @@ -7,7 +7,9 @@ In order_pkg.html or similar: curr_value_recur => ($cgi->param('recur_discountnum') || ''), disable_setup => 0, disable_recur => 0, - disable_waive_setup => 0 + disable_waive_setup => 0, + carry_value_setup => $carry_setup_discountnum, + carry_value_recur => $carry_recur_discountnum, &> This provides the following: @@ -20,6 +22,8 @@ This provides the following: checkbox to waive setup fee. - Same for recurring fee, but without the "waive setup fee" stuff, obviously. - Custom recurring discounts also have an option for a duration in months. +- When changing a package, the original package's discount option is + labeled in the select options "disable_setup" locks the setup discount, but will still show a static description if curr_value_setup is set. Likewise "disable_recur". @@ -47,6 +51,8 @@ description if curr_value_setup is set. Likewise "disable_recur". curr_value => $opt{'curr_value_setup'}, disable_empty => 1, pre_options => $pre_options, + also_show_option => $opt{carry_value_setup}, + label_callback => $opt{carry_value_setup} ? $carry_setup_sub : undef, &> @@ -107,6 +113,8 @@ description if curr_value_setup is set. Likewise "disable_recur". id => 'recur_discountnum', hashref => { disabled => '' }, curr_value => $opt{'curr_value_recur'}, + also_show_option => $opt{carry_value_recur}, + label_callback => $opt{carry_value_recur} ? $carry_recur_sub : undef, &> @@ -196,4 +204,18 @@ my %opt = ( my $curuser = $FS::CurrentUser::CurrentUser; my $money_char = FS::Conf->new->config('money_char') || '$'; +# Change the label for the select-option when it matches the carryover +# discountnum +my $carry_recur_sub = sub { + my ($rec) = @_; + $rec->discountnum eq $opt{carry_value_recur} + ? $rec->description() . ' [Continues existing discount]' + : $rec->description(); +}; +my $carry_setup_sub = sub { + my ($rec) = @_; + $rec->discountnum eq $opt{carry_value_setup} + ? $rec->description() . ' [Continues existing discount]' + : $rec->description(); +}; diff --git a/httemplate/misc/change_pkg.cgi b/httemplate/misc/change_pkg.cgi index 2470ee135..c588c9e6c 100755 --- a/httemplate/misc/change_pkg.cgi +++ b/httemplate/misc/change_pkg.cgi @@ -91,11 +91,13 @@ <% mt('Discounting') |h %> <& /elements/tr-select-pkg-discount.html, - curr_value_setup => $discount{setup}, - curr_value_recur => $discount{recur}, + # curr_value_setup => $discount{setup}, + # curr_value_recur => $discount{recur}, disable_setup => 0, disable_recur => 0, - disable_waive_setup => 0 + disable_waive_setup => 0, + carry_value_setup => $discount{setup}, + carry_value_recur => $discount{recur}, &>

-- 2.11.0