From d3e18527e2fa36b7b7fe7b8b0a5906caae3cb8de Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 11 Aug 2011 00:39:00 +0000 Subject: [PATCH] hide start date on package order for specific package definitions, RT#13783 --- FS/FS/cust_pkg.pm | 2 +- FS/FS/part_pkg.pm | 2 ++ FS/FS/part_pkg/delayed_Mixin.pm | 6 ++++-- FS/FS/part_pkg/flat.pm | 2 ++ httemplate/elements/order_pkg.js | 17 ++++++++++++++++- httemplate/elements/select-part_pkg.html | 2 +- httemplate/elements/tr-select-cust-part_pkg.html | 21 +++++++++++---------- httemplate/misc/cust-part_pkg.cgi | 12 +++++++++--- httemplate/misc/order_pkg.html | 1 - 9 files changed, 46 insertions(+), 19 deletions(-) diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 740561771..c2b3c04b5 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -284,7 +284,7 @@ sub insert { } my $free_days = $part_pkg->option('free_days'); - if ( $free_days && $part_pkg->option('delay_setup') ) { #&& !$self->start_date + if ( $free_days && $part_pkg->option('delay_setup',1) ) { #&& !$self->start_date my ($mday,$mon,$year) = (localtime(time) )[3,4,5]; #my $start_date = ($self->start_date || timelocal(0,0,0,$mday,$mon,$year)) + 86400 * $free_days; my $start_date = timelocal(0,0,0,$mday,$mon,$year) + 86400 * $free_days; diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index f658dcf99..03239aeff 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -798,6 +798,8 @@ sub is_free { sub can_discount { 0; } +sub can_start_date { 1; } + sub freqs_href { # moved to FS::Misc to make this accessible to other packages # at initialization diff --git a/FS/FS/part_pkg/delayed_Mixin.pm b/FS/FS/part_pkg/delayed_Mixin.pm index 027cfff06..4228a4a3d 100644 --- a/FS/FS/part_pkg/delayed_Mixin.pm +++ b/FS/FS/part_pkg/delayed_Mixin.pm @@ -25,7 +25,7 @@ use vars qw(%info); sub calc_setup { my($self, $cust_pkg, $time ) = @_; - unless ( $self->option('delay_setup') ) { + unless ( $self->option('delay_setup', 1) ) { my $d = $cust_pkg->bill || $time; $d += 86400 * $self->option('free_days'); $cust_pkg->bill($d); @@ -37,7 +37,7 @@ sub calc_setup { sub calc_remain { my ($self, $cust_pkg, %options) = @_; - unless ( $self->option('delay_setup') ) { + unless ( $self->option('delay_setup', 1) ) { my $last_bill = $cust_pkg->last_bill || 0; my $next_bill = $cust_pkg->getfield('bill') || 0; my $free_days = $self->option('free_days'); @@ -49,4 +49,6 @@ sub calc_remain { return $self->SUPER::calc_remain($cust_pkg, %options); } +sub can_start_date { ! shift->option('delay_setup', 1) } + 1; diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index 4566c87ce..c1d1f56b2 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -196,6 +196,8 @@ sub is_free_options { sub is_prepaid { 0; } #no, we're postpaid +sub can_start_date { ! shift->option('start_1st', 1) } + #XXX discounts only on recurring fees for now (no setup/one-time or usage) sub can_discount { my $self = shift; diff --git a/httemplate/elements/order_pkg.js b/httemplate/elements/order_pkg.js index 2c13ed254..2f53e3631 100644 --- a/httemplate/elements/order_pkg.js +++ b/httemplate/elements/order_pkg.js @@ -1,8 +1,9 @@ -function enable_order_pkg () { +function pkg_changed () { var form = document.OrderPkgForm; var discountnum = form.discountnum; if ( form.pkgpart.selectedIndex > 0 ) { + form.submitButton.disabled = false; if ( discountnum ) { if ( form.pkgpart.options[form.pkgpart.selectedIndex].getAttribute('data-can_discount') == 1 ) { @@ -11,6 +12,20 @@ function enable_order_pkg () { form.discountnum.disabled = true; } } + + if ( form.pkgpart.options[form.pkgpart.selectedIndex].getAttribute('data-can_start_date') == 1 ) { + form.start_date_text.disabled = false; + form.start_date.style.backgroundColor = '#ffffff'; + form.start_date_button.style.display = ''; + form.start_date_button_disabled.style.display = 'none'; + form.invoice_terms.disabled = true; + } else { + form.start_date_text.disabled = true; + form.start_date.style.backgroundColor = '#dddddd'; + form.start_date_button.style.display = 'none'; + form.start_date_button_disabled.style.display = ''; + } + } else { form.submitButton.disabled = true; if ( discountnum ) { form.discountnum.disabled = true; } diff --git a/httemplate/elements/select-part_pkg.html b/httemplate/elements/select-part_pkg.html index 885bb806b..439c4b53e 100644 --- a/httemplate/elements/select-part_pkg.html +++ b/httemplate/elements/select-part_pkg.html @@ -23,7 +23,7 @@ Example: 'empty_label' => 'Select package', #should this be the default? 'label_callback' => sub { shift->pkg_comment }, 'hashref' => \%hash, - 'extra_option_attributes' => [ 'can_discount' ], + 'extra_option_attributes' => [ 'can_discount', 'can_start_date' ], %opt, ) %> diff --git a/httemplate/elements/tr-select-cust-part_pkg.html b/httemplate/elements/tr-select-cust-part_pkg.html index 878af4d90..7d0b0dc9c 100644 --- a/httemplate/elements/tr-select-cust-part_pkg.html +++ b/httemplate/elements/tr-select-cust-part_pkg.html @@ -8,9 +8,10 @@