add some more customer output formats that include service address, RT#4583
[freeside.git] / FS / FS / rate_detail.pm
index ad41b40..62c0fa1 100644 (file)
@@ -5,6 +5,7 @@ use vars qw( @ISA );
 use FS::Record qw( qsearch qsearchs );
 use FS::rate;
 use FS::rate_region;
+use Tie::IxHash;
 
 @ISA = qw(FS::Record);
 
@@ -48,6 +49,8 @@ inherits from FS::Record.  The following fields are currently supported:
 
 =item sec_granularity - granularity in seconds, i.e. 6 or 60; 0 for per-call
 
+=item classnum - usage class (see L<FS::usage_class>) if any for this rate
+
 =back
 
 =head1 METHODS
@@ -120,6 +123,8 @@ sub check {
     || $self->ut_float('min_charge')
 
     || $self->ut_number('sec_granularity')
+
+    || $self->ut_foreign_keyn('classnum', 'usage_class', 'classnum' )
   ;
   return $error if $error;
 
@@ -186,6 +191,44 @@ sub dest_prefixes_short {
   $self->dest_region->prefixes_short;
 }
 
+=item classname
+
+Returns the name of the usage class (see L<FS::usage_class>) associated with
+this call plan rate.
+
+=cut
+
+sub classname {
+  my $self = shift;
+  my $usage_class = qsearchs('usage_class', { classnum => $self->classnum });
+  $usage_class ? $usage_class->classname : '';
+}
+
+
+=back
+
+=head1 SUBROUTINES
+
+=over 4
+
+=item granularities
+
+  Returns an (ordered) hash of granularity => name pairs
+
+=cut
+
+tie my %granularities, 'Tie::IxHash',
+  '1', => '1 second',
+  '6'  => '6 second',
+  '30' => '30 second', # '1/2 minute',
+  '60' => 'minute',
+  '0'  => 'call',
+;
+
+sub granularities {
+  %granularities;
+}
+
 
 =back