From: ivan Date: Thu, 22 Oct 2009 12:50:05 +0000 (+0000) Subject: restrict additinal package order option, RT#6029 X-Git-Tag: root_of_svc_elec_features~753 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=09d3b99715ac707d64b1a06d8a2432b76ddb173d restrict additinal package order option, RT#6029 --- diff --git a/FS/FS/ClientAPI/MasonComponent.pm b/FS/FS/ClientAPI/MasonComponent.pm index 88baf0764..2027840f3 100644 --- a/FS/FS/ClientAPI/MasonComponent.pm +++ b/FS/FS/ClientAPI/MasonComponent.pm @@ -59,6 +59,21 @@ my %session_callbacks = ( } qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case? + my $conf = new FS::Conf; + if ( $conf->exists('pkg-addon_classnum') ) { + + my %classnum = map { ( $_->addon_classnum => 1 ) } + grep { $_->freq !~ /^0/ } + map { $_->part_pkg } + $cust_main->ncancelled_pkgs; + + warn "classnums: ". join(',', keys %classnum). "\n"; + + unless ( $classnum{''} ) { + @part_pkg = grep $classnum{ $_->classnum }, @part_pkg; + } + } + my %args = @$argsref; $args{part_pkg} = \@part_pkg; @$argsref = ( %args ); diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 13bec18b1..f0e2f4595 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -230,6 +230,7 @@ sub invoice_templatenames { } } + map { $_ } #handle scalar context sort keys %templatenames; } @@ -576,7 +577,7 @@ worry that config_items is freeside-specific and icky. { 'key' => 'alert_expiration', 'section' => 'billing', - 'description' => 'Enable alerts about billing method expiration.', + 'description' => 'Enable alerts about billing method expiration (i.e. expiring credit cards).', 'type' => 'checkbox', 'per_agent' => 1, }, @@ -584,7 +585,7 @@ worry that config_items is freeside-specific and icky. { 'key' => 'alerter_template', 'section' => 'billing', - 'description' => 'Template file for billing method expiration alerts. See the billing documentation for details.', + 'description' => 'Template file for billing method expiration alerts (i.e. expiring credit cards). See the billing documentation for details.', 'type' => 'textarea', 'per_agent' => 1, }, @@ -1583,14 +1584,14 @@ worry that config_items is freeside-specific and icky. { 'key' => 'declinetemplate', 'section' => 'billing', - 'description' => 'Template file for credit card decline emails.', + 'description' => 'Template file for credit card and electronic check decline emails.', 'type' => 'textarea', }, { 'key' => 'emaildecline', 'section' => 'billing', - 'description' => 'Enable emailing of credit card decline notices.', + 'description' => 'Enable emailing of credit card and electronic check decline notices.', 'type' => 'checkbox', }, @@ -3190,6 +3191,13 @@ worry that config_items is freeside-specific and icky. }, { + 'key' => 'pkg-addon_classnum', + 'section' => 'billing', + 'description' => 'Enable the ability to restrict additional package orders based on package class.', + 'type' => 'checkbox', + }, + + { 'key' => 'cust_main-edit_signupdate', 'section' => 'UI', 'descritpion' => 'Enable manual editing of the signup date.', diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index cf3a88989..dfa33288d 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1274,6 +1274,7 @@ sub tables_hashref { 'custom', 'char', 'NULL', 1, '', '', 'taxclass', 'varchar', 'NULL', $char_d, '', '', 'classnum', 'int', 'NULL', '', '', '', + 'addon_classnum','int', 'NULL', '', '', '', 'taxproductnum', 'int', 'NULL', '', '', '', 'setup_cost', @money_typen, '', '', 'recur_cost', @money_typen, '', '', @@ -1284,7 +1285,9 @@ sub tables_hashref { ], 'primary_key' => 'pkgpart', 'unique' => [], - 'index' => [ [ 'promo_code' ], [ 'disabled' ], [ 'agentnum' ], ], + 'index' => [ [ 'promo_code' ], [ 'disabled' ], [ 'classnum' ], + [ 'agentnum' ], + ], }, 'part_pkg_link' => { diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 287453f3c..70dcd4934 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -465,6 +465,8 @@ sub check { || $self->ut_floatn('pay_weight') || $self->ut_floatn('credit_weight') || $self->ut_numbern('taxproductnum') + || $self->ut_foreign_keyn('classnum', 'pkg_class', 'classnum') + || $self->ut_foreign_keyn('addon_classnum', 'pkg_class', 'classnum') || $self->ut_foreign_keyn('taxproductnum', 'part_pkg_taxproduct', 'taxproductnum' @@ -477,13 +479,6 @@ sub check { ; return $error if $error; - if ( $self->classnum !~ /^$/ ) { - my $error = $self->ut_foreign_key('classnum', 'pkg_class', 'classnum'); - return $error if $error; - } else { - $self->classnum(''); - } - return 'Unknown plan '. $self->plan unless exists($plans{$self->plan}); @@ -536,6 +531,22 @@ sub pkg_class { } } +=item addon_pkg_class + +Returns the add-on package class, as an FS::pkg_class object, or the empty +string if there is no add-on package class. + +=cut + +sub addon_pkg_class { + my $self = shift; + if ( $self->addon_classnum ) { + qsearchs('pkg_class', { 'classnum' => $self->addon_classnum } ); + } else { + return ''; + } +} + =item categoryname Returns the package category name, or the empty string if there is no package @@ -566,6 +577,21 @@ sub classname { : ''; } +=item addon_classname + +Returns the add-on package class name, or the empty string if there is no +add-on package class. + +=cut + +sub addon_classname { + my $self = shift; + my $pkg_class = $self->addon_pkg_class; + $pkg_class + ? $pkg_class->classname + : ''; +} + =item agent Returns the associated agent for this event, if any, as an FS::agent object. diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index c6cbb81a3..e226ce13e 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -177,6 +177,12 @@ unless ( 0 ) { #already showing only one class or something? $align .= 'l'; } +if ( $conf->exists('pkg-addon_classnum') ) { + push @header, "Add'l order class"; + push @fields, sub { shift->addon_classname || '(none)'; }; + $align .= 'l'; +} + tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() }; tie my %plan_labels, 'Tie::IxHash', diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 690e884db..fcde22bf6 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -29,6 +29,7 @@ 'pkg' => 'Package (customer-visible)', 'comment' => 'Comment (customer-hidden)', 'classnum' => 'Package class', + 'addon_classnum' => 'Restrict additional orders to package class', 'promo_code' => 'Promotional code', 'freq' => 'Recurring fee frequency', 'setuptax' => 'Setup fee tax exempt', @@ -76,6 +77,13 @@ onchange => 'agent_changed', }, {field=>'classnum', type=>'select-pkg_class' }, + ( $conf->exists('pkg-addon_classnum') + ? ( { field=>'addon_classnum', + type =>'select-pkg_class', + } + ) + : () + ), {field=>'disabled', type=>$disabled_type, value=>'Y'}, { type => 'tablebreak-tr-title',