disable agent types, RT#31446
authorIvan Kohler <ivan@freeside.biz>
Fri, 5 Dec 2014 22:24:01 +0000 (14:24 -0800)
committerIvan Kohler <ivan@freeside.biz>
Fri, 5 Dec 2014 22:24:01 +0000 (14:24 -0800)
FS/FS/Schema.pm
FS/FS/agent_type.pm
httemplate/browse/agent_type.cgi
httemplate/browse/part_pkg.cgi
httemplate/edit/agent.cgi
httemplate/edit/agent_type.cgi
httemplate/edit/part_pkg.cgi
httemplate/elements/tr-select-agent_type.html

index 91dfc5d..492f8e2 100644 (file)
@@ -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' => {
index 5d6b94e..e0f7495 100644 (file)
@@ -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;
 
 }
 
index 7711dcc..0c011ce 100755 (executable)
@@ -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
+  ];
 
 };
 
index 1eb55c8..87aa792 100755 (executable)
@@ -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?';
index 15da2f0..c4963e4 100755 (executable)
@@ -35,7 +35,7 @@
     <TH ALIGN="right">Agent type</TH>
     <TD>
       <SELECT NAME="typenum" SIZE=1>
-%       foreach my $agent_type (qsearch('agent_type',{})) { 
+%       foreach my $agent_type ( qsearch('agent_type', { 'disabled'=>'' }) ) { 
 
           <OPTION VALUE="<% $agent_type->typenum %>"<% ( $agent->typenum && ( $agent->typenum == $agent_type->typenum ) ) ? ' SELECTED' : '' %>>
     <% $agent_type->getfield('typenum') %>: <% $agent_type->getfield('atype') %>
index b75757f..f16d76c 100755 (executable)
@@ -7,15 +7,31 @@
 
 <FORM ACTION="<% popurl(1) %>process/agent_type.cgi" METHOD=POST>
 <INPUT TYPE="hidden" NAME="typenum" VALUE="<% $agent_type->typenum %>">
+
+<FONT CLASS="fsinnerbox-title">
 Agent Type #<% $agent_type->typenum || "(NEW)" %>
+</FONT>
+
+<TABLE CLASS="fsinnerbox">
+
+  <TR>
+    <TH ALIGN="right">Agent Type</TH>
+    <TD><INPUT TYPE="text" NAME="atype" SIZE=32 VALUE="<% $agent_type->atype %>"></TD>
+  </TR>
+
+  <TR>
+    <TH ALIGN="right">Disable</TH>
+    <TD><INPUT TYPE="checkbox" NAME="disabled" VALUE="Y" <% $agent_type->disabled eq 'Y' ? ' CHECKED' : '' %>></TD>
+  </TR>
+
+<TABLE>
 <BR>
 
-Agent Type
-<INPUT TYPE="text" NAME="atype" SIZE=32 VALUE="<% $agent_type->atype %>">
-<BR><BR>
+<FONT CLASS="fsinnerbox-title">
+Package definitions that agents of this type can sell
+</FONT>
 
-Select which packages agents of this type may sell to customers<BR>
-<% ntable("#cccccc", 2) %><TR><TD>
+<TABLE CLASS="fsinnerbox"><TR><TD>
 <% include('/elements/checkboxes-table.html',
               'source_obj'    => $agent_type,
               'link_table'    => 'type_pkgs',
index 2ae9df3..c4db83a 100755 (executable)
@@ -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');
index 9ea943b..3e6ce07 100644 (file)
@@ -7,11 +7,10 @@
   <TR>
     <TD ALIGN="right"><% $opt{'label'} || 'Agent Type' %></TD>
     <TD>
-      <% include( '/elements/select-agent_type.html',
-                     'curr_value'  => $typenum,
-                     %opt,
-                 )
-      %>
+      <& /elements/select-agent_type.html,
+           'curr_value'  => $typenum,
+           %opt,
+      &>
     </TD>
   </TR>
 
@@ -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' => '' });
 
 </%init>