From: Ivan Kohler Date: Fri, 5 Dec 2014 22:24:01 +0000 (-0800) Subject: disable agent types, RT#31446 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=e68a2a20972de41485c438c46d197b5abeee3267 disable agent types, RT#31446 --- diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 91dfc5d97..492f8e2b7 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -556,12 +556,13 @@ sub tables_hashref { 'agent_type' => { 'columns' => [ - 'typenum', 'serial', '', '', '', '', - 'atype', 'varchar', '', $char_d, '', '', + 'typenum', 'serial', '', '', '', '', + 'atype', 'varchar', '', $char_d, '', '', + 'disabled', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'typenum', 'unique' => [], - 'index' => [], + 'index' => [ ['disabled'] ], }, 'type_pkgs' => { diff --git a/FS/FS/agent_type.pm b/FS/FS/agent_type.pm index 5d6b94e0c..e0f749500 100644 --- a/FS/FS/agent_type.pm +++ b/FS/FS/agent_type.pm @@ -45,9 +45,17 @@ FS::Record. The following fields are currently supported: =over 4 -=item typenum - primary key (assigned automatically for new agent types) +=item typenum -=item atype - Text name of this agent type +primary key (assigned automatically for new agent types) + +=item atype + +Text name of this agent type + +=item disabled + +Disabled flag, empty or 'Y' =back @@ -103,8 +111,9 @@ sub check { my $self = shift; $self->ut_numbern('typenum') - or $self->ut_text('atype') - or $self->SUPER::check; + || $self->ut_text('atype') + || $self->ut_enum('disabled', [ '', 'Y' ] ) + || $self->SUPER::check; } diff --git a/httemplate/browse/agent_type.cgi b/httemplate/browse/agent_type.cgi index 7711dccf7..0c011ceed 100755 --- a/httemplate/browse/agent_type.cgi +++ b/httemplate/browse/agent_type.cgi @@ -1,27 +1,28 @@ -<% include( 'elements/browse.html', - 'title' => 'Agent Types', - 'menubar' => [ 'Agents' =>"${p}browse/agent.cgi", ], - 'html_init' => $html_init, - 'name' => 'agent types', - 'query' => { 'table' => 'agent_type', - 'hashref' => {}, - 'order_by' => 'ORDER BY typenum', # 'ORDER BY atype', - }, - 'count_query' => $count_query, - 'header' => [ '#', - 'Agent Type', - 'Packages', - ], - 'fields' => [ 'typenum', - 'atype', - $packages_sub, - ], - 'links' => [ $link, - $link, - '', - ], - ) -%> +<& elements/browse.html, + 'title' => 'Agent Types', + 'menubar' => [ 'Agents' => "${p}browse/agent.cgi" ], + 'html_init' => $html_init, + 'name' => 'agent types', + 'disableable' => 1, + 'disabled_statuspos' => 2, + 'query' => { 'table' => 'agent_type', + 'hashref' => {}, + 'order_by' => 'ORDER BY typenum', # atype? + }, + 'count_query' => $count_query, + 'header' => [ '#', + 'Agent Type', + 'Packages', + ], + 'fields' => [ 'typenum', + 'atype', + $packages_sub, + ], + 'links' => [ $link, + $link, + '', + ], +&> <%init> die "access denied" @@ -36,25 +37,26 @@ my $count_query = 'SELECT COUNT(*) FROM agent_type'; #false laziness w/access_user.html my $packages_sub = sub { -my $agent_type = shift; - -[ map { - my $type_pkgs = $_; - #my $part_pkg = $type_pkgs->part_pkg; - [ - { - #'data' => $part_pkg->pkg. ' - '. $part_pkg->comment, - 'data' => encode_entities($type_pkgs->pkg). ' - '. - ( $type_pkgs->custom ? '(CUSTOM) ' : '' ). - encode_entities($type_pkgs->comment), - 'align' => 'left', - 'link' => $p. 'edit/part_pkg.cgi?'. $type_pkgs->pkgpart, - }, - ]; - } - - $agent_type->type_pkgs_enabled -]; + my $agent_type = shift; + my @type_pkgs = $agent_type->type_pkgs_enabled; + return '(lots; edit agent type to view)' if scalar(@type_pkgs) > 32; + + [ map { + my $type_pkgs = $_; + #my $part_pkg = $type_pkgs->part_pkg; + [ + { + #'data' => $part_pkg->pkg. ' - '. $part_pkg->comment, + 'data' => encode_entities($type_pkgs->pkg). ' - '. + ( $type_pkgs->custom ? '(CUSTOM) ' : '' ). + encode_entities($type_pkgs->comment), + 'align' => 'left', + 'link' => $p. 'edit/part_pkg.cgi?'. $type_pkgs->pkgpart, + }, + ]; + } + @type_pkgs + ]; }; diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index 1eb55c88a..87aa79255 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -77,11 +77,11 @@ if ( $cgi->param('classnum') =~ /^(\d+)$/ ) { $cgi->delete('classnum'); if ( $cgi->param('missing_recur_fee') ) { - push @where, "0 = ( SELECT COUNT(*) FROM part_pkg_option - WHERE optionname = 'recur_fee' - AND part_pkg_option.pkgpart = part_pkg.pkgpart - AND CAST( optionvalue AS NUMERIC ) > 0 - )"; + push @where, "NOT EXISTS ( SELECT 1 FROM part_pkg_option + WHERE optionname = 'recur_fee' + AND part_pkg_option.pkgpart = part_pkg.pkgpart + AND CAST( optionvalue AS NUMERIC ) > 0 + )"; } if ( $cgi->param('family') =~ /^(\d+)$/ ) { @@ -419,7 +419,8 @@ push @fields, sub { #agent type if ( $acl_edit_global ) { #really we just want a count, but this is fine unless someone has tons - my @all_agent_types = map {$_->typenum} qsearch('agent_type',{}); + my @all_agent_types = map {$_->typenum} + qsearch('agent_type', { 'disabled'=>'' }); if ( scalar(@all_agent_types) > 1 ) { push @header, 'Agent types'; my $typelink = $p. 'edit/agent_type.cgi?'; diff --git a/httemplate/edit/agent.cgi b/httemplate/edit/agent.cgi index 15da2f043..c4963e470 100755 --- a/httemplate/edit/agent.cgi +++ b/httemplate/edit/agent.cgi @@ -35,7 +35,7 @@ Agent type + + Agent Type #<% $agent_type->typenum || "(NEW)" %> + + + + + + + + + + + + + + +
Agent Type
Disabledisabled eq 'Y' ? ' CHECKED' : '' %>>

-Agent Type - -

+ +Package definitions that agents of this type can sell + -Select which packages agents of this type may sell to customers
-<% ntable("#cccccc", 2) %>
+ @@ -22,6 +21,6 @@ my %opt = @_; my $typenum = $opt{'curr_value'} || $opt{'value'}; -my @agent_types = qsearch('agent_type', {}); +my @agent_types = qsearch('agent_type', { 'disabled' => '' });
<% include('/elements/checkboxes-table.html', 'source_obj' => $agent_type, 'link_table' => 'type_pkgs', diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 2ae9df3ec..c4db83aee 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -654,8 +654,7 @@ my $new_callback = sub { my $conf = new FS::Conf; if ( $conf->exists('agent_defaultpkg') ) { - #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{}); - @agent_type = map {$_->typenum} qsearch('agent_type',{}); + @agent_type = map {$_->typenum} qsearch('agent_type', { 'disabled'=>'' }); } $options{'suspend_bill'}=1 if $conf->exists('part_pkg-default_suspend_bill'); diff --git a/httemplate/elements/tr-select-agent_type.html b/httemplate/elements/tr-select-agent_type.html index 9ea943b51..3e6ce0752 100644 --- a/httemplate/elements/tr-select-agent_type.html +++ b/httemplate/elements/tr-select-agent_type.html @@ -7,11 +7,10 @@
<% $opt{'label'} || 'Agent Type' %> - <% include( '/elements/select-agent_type.html', - 'curr_value' => $typenum, - %opt, - ) - %> + <& /elements/select-agent_type.html, + 'curr_value' => $typenum, + %opt, + &>