hide unused usage columns
authorjeff <jeff>
Wed, 18 Mar 2009 00:30:43 +0000 (00:30 +0000)
committerjeff <jeff>
Wed, 18 Mar 2009 00:30:43 +0000 (00:30 +0000)
FS/FS/part_pkg/flat.pm
FS/FS/svc_acct.pm
httemplate/edit/part_svc.cgi

index 3ac44c4..8fd0286 100644 (file)
@@ -195,12 +195,17 @@ sub is_prepaid {
   0; #no, we're postpaid
 }
 
+sub usage_valuehash {
+  my $self = shift;
+  map { $_, $self->option($_) } 
+    grep { $self->option($_, 'hush') } 
+    qw(seconds upbytes downbytes totalbytes);
+}
+
 sub reset_usage {
   my($self, $cust_pkg, %opt) = @_;
   warn "    resetting usage counters" if $opt{debug} > 1;
-  my %values = map { $_, $self->option($_) } 
-    grep { $self->option($_, 'hush') } 
-    qw(seconds upbytes downbytes totalbytes);
+  my %values = $self->usage_valuehash;
   if ($self->option('usage_rollover', 1)) {
     $cust_pkg->recharge(\%values);
   }else{
index 6f11051..57ef615 100644 (file)
@@ -26,6 +26,7 @@ use FS::Conf;
 use FS::Record qw( qsearch qsearchs fields dbh dbdef );
 use FS::Msgcat qw(gettext);
 use FS::UI::bytecount;
+use FS::part_pkg;
 use FS::svc_Common;
 use FS::cust_svc;
 use FS::part_svc;
@@ -277,6 +278,7 @@ sub table_info {
                          type  => 'text',
                          disable_inventory => 1,
                          disable_select => 1,
+                         disable_part_svc_column => 1,
                        },
         'upbytes'   => { label => 'Upload',
                          type  => 'text',
@@ -284,6 +286,7 @@ sub table_info {
                          disable_select => 1,
                          'format' => \&FS::UI::bytecount::display_bytecount,
                          'parse' => \&FS::UI::bytecount::parse_bytecount,
+                         disable_part_svc_column => 1,
                        },
         'downbytes' => { label => 'Download',
                          type  => 'text',
@@ -291,6 +294,7 @@ sub table_info {
                          disable_select => 1,
                          'format' => \&FS::UI::bytecount::display_bytecount,
                          'parse' => \&FS::UI::bytecount::parse_bytecount,
+                         disable_part_svc_column => 1,
                        },
         'totalbytes'=> { label => 'Total up and download',
                          type  => 'text',
@@ -298,11 +302,13 @@ sub table_info {
                          disable_select => 1,
                          'format' => \&FS::UI::bytecount::display_bytecount,
                          'parse' => \&FS::UI::bytecount::parse_bytecount,
+                         disable_part_svc_column => 1,
                        },
         'seconds_threshold'   => { label => 'Seconds threshold',
                                    type  => 'text',
                                    disable_inventory => 1,
                                    disable_select => 1,
+                                   disable_part_svc_column => 1,
                                  },
         'upbytes_threshold'   => { label => 'Upload threshold',
                                    type  => 'text',
@@ -310,6 +316,7 @@ sub table_info {
                                    disable_select => 1,
                                    'format' => \&FS::UI::bytecount::display_bytecount,
                                    'parse' => \&FS::UI::bytecount::parse_bytecount,
+                                   disable_part_svc_column => 1,
                                  },
         'downbytes_threshold' => { label => 'Download threshold',
                                    type  => 'text',
@@ -317,6 +324,7 @@ sub table_info {
                                    disable_select => 1,
                                    'format' => \&FS::UI::bytecount::display_bytecount,
                                    'parse' => \&FS::UI::bytecount::parse_bytecount,
+                                   disable_part_svc_column => 1,
                                  },
         'totalbytes_threshold'=> { label => 'Total up and download threshold',
                                    type  => 'text',
@@ -324,6 +332,7 @@ sub table_info {
                                    disable_select => 1,
                                    'format' => \&FS::UI::bytecount::display_bytecount,
                                    'parse' => \&FS::UI::bytecount::parse_bytecount,
+                                   disable_part_svc_column => 1,
                                  },
         'last_login'=>           {
                                    label     => 'Last login',
@@ -503,6 +512,26 @@ sub insert {
     $self->svcpart($cust_svc->svcpart);
   }
 
+  # set usage fields and thresholds if unset but set in a package def
+  if ( $self->pkgnum ) {
+    my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
+    my $part_pkg = $cust_pkg->part_pkg if $cust_pkg;
+    if ( $part_pkg && $part_pkg->can('usage_valuehash') ) {
+
+      my %values = $part_pkg->usage_valuehash;
+      my $multiplier = $conf->exists('svc_acct-usage_threshold') 
+                         ? 1 - $conf->config('svc_acct-usage_threshold')/100
+                         : 0.20;
+
+      foreach ( keys %values ) {
+        next if $self->getfield($_);
+        $self->setfield( $_, $values{$_} );
+        $self->setfield( $_. '_threshold', int( $values{$_} * $multiplier ) );
+      }
+
+    }
+  }
+
   my @jobnums;
   $error = $self->SUPER::insert(
     'jobnums'       => \@jobnums,
index e0fb615..deb3c80 100755 (executable)
@@ -131,7 +131,14 @@ that field.
 %
 %      #yucky kludge
 %      my @fields = defined( dbdef->table($layer) )
-%                      ? grep { $_ ne 'svcnum' } fields($layer)
+%                      ? grep {
+%                               $_ ne 'svcnum' &&
+%                               ( !FS::part_svc->svc_table_fields($layer)
+%                                     ->{$_}->{disable_part_svc_column}   ||
+%                                 $part_svc->part_svc_column($_)->columnflag
+%                               )
+%                             }
+%                             fields($layer)
 %                      : ();
 %      push @fields, 'usergroup' if $layer eq 'svc_acct'; #kludge
 %      $part_svc->svcpart($clone) if $clone; #haha, undone below