From 4427ad71b12bf27eac2a05d88141a82f9372d03f Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Tue, 7 Jan 2014 22:55:58 -0800 Subject: time/data/etc. unit pricing add-ons, RT#24392 --- httemplate/browse/part_pkg.cgi | 15 +++++++++++++ httemplate/edit/part_pkg.cgi | 8 ++++--- httemplate/edit/process/part_pkg.cgi | 16 ++++++++++++++ httemplate/elements/part_pkg_usageprice.html | 32 ++++++++-------------------- 4 files changed, 45 insertions(+), 26 deletions(-) (limited to 'httemplate') diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index 8b50a509f..b07386618 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -277,6 +277,21 @@ push @fields, sub { : () ), ], + ( + map { my $amount = $_->amount + / (FS::part_pkg_usageprice->targets->{$_->target}{multiplier}||1); + my $label = FS::part_pkg_usageprice->targets->{$_->target}{label}; + [ + { data => "Plus $money_char". $_->price. ' '. + ( $_->action eq 'increment' ? 'per' : 'for' ). + " $amount $label", + align => 'center', #left? + colspan => 2, + }, + ]; + } + $part_pkg->part_pkg_usageprice + ), ( map { my $dst_pkg = $_->dst_pkg; [ { data => 'Supplemental:  '. diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 23de7c146..3fee36b36 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -806,13 +806,15 @@ my $javascript = <<'END'; var plan = what.options[what.selectedIndex].value; - var term_table = document.getElementById('TableNumber7') // XXX NOT ROBUST + var term_table = document.getElementById('TableNumber8') // XXX NOT ROBUST if ( plan == 'flat' || plan == 'prorate' || plan == 'subscription' ) { //term_table.disabled = false; - term_table.style.visibility = ''; + //term_table.style.visibility = ''; + term_table.style.display = ''; } else { //term_table.disabled = true; - term_table.style.visibility = 'hidden'; + //term_table.style.visibility = 'hidden'; + term_table.style.display = 'none'; } var currency_regex = /^(setup|recur)_fee_[A-Z]{3}$/; diff --git a/httemplate/edit/process/part_pkg.cgi b/httemplate/edit/process/part_pkg.cgi index 82c4e1e15..69138bc65 100755 --- a/httemplate/edit/process/part_pkg.cgi +++ b/httemplate/edit/process/part_pkg.cgi @@ -264,6 +264,21 @@ if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) { }; } +my $targets = FS::part_pkg_usageprice->targets; +foreach my $amount_param ( grep /^usagepricepart(\d+)_amount$/, $cgi->param ) { + $amount_param =~ /^usagepricepart(\d+)_amount$/ or die 'unpossible'; + my $num = $1; + my $amount = $cgi->param($amount_param); + if ( ! $amount && ! $cgi->param("usagepricepart${num}_price") ) { + #don't add empty rows just because the dropdowns have a value + $cgi->param("usagepricepart${num}_$_", '') for qw( currency action target ); + next; + } + my $target = $cgi->param("usagepricepart${num}_target"); + $amount *= $targets->{$target}{multiplier} if $targets->{$target}{multiplier}; + $cgi->param($amount_param, $amount); +} + my @process_o2m = ( { 'table' => 'part_pkg_msgcat', @@ -272,6 +287,7 @@ my @process_o2m = ( { 'table' => 'part_pkg_usageprice', 'fields' => [qw( price currency action target amount )], + } ); diff --git a/httemplate/elements/part_pkg_usageprice.html b/httemplate/elements/part_pkg_usageprice.html index 5663469c2..548213747 100644 --- a/httemplate/elements/part_pkg_usageprice.html +++ b/httemplate/elements/part_pkg_usageprice.html @@ -64,24 +64,27 @@ ID = "<%$id%>_target" <% $onchange %> > -% foreach my $target (keys %targets) { +% foreach my $target (keys %$targets) {