allow a default rate detail for each CDR type, #38633
[freeside.git] / FS / FS / rate_detail.pm
index 7b90452..4f1c962 100644 (file)
@@ -57,6 +57,17 @@ inherits from FS::Record.  The following fields are currently supported:
 
 =item ratetimenum - rating time period (see L<FS::rate_time) if any
 
+=item cdrtypenum - CDR type (see L<FS::cdr_type>) if any for this rate
+
+=item region_group - Group in region group for rate plan
+
+=item upstream_mult_charge - the multiplier to apply to the upstream price. 
+Defaults to zero, and should stay zero unless this rate is intended to include
+a markup on pre-rated CDRs.
+
+=item upstream_mult_cost - the multiplier to apply to the upstream price to
+calculate the wholesale cost.
+
 =back
 
 =head1 METHODS
@@ -121,16 +132,24 @@ sub check {
        $self->ut_numbern('ratedetailnum')
     || $self->ut_foreign_key('ratenum', 'rate', 'ratenum')
     || $self->ut_foreign_keyn('orig_regionnum', 'rate_region', 'regionnum' )
-    || $self->ut_foreign_key('dest_regionnum', 'rate_region', 'regionnum' )
+    || $self->ut_foreign_keyn('dest_regionnum', 'rate_region', 'regionnum' )
+    || $self->ut_foreign_keyn('cdrtypenum', 'cdr_type', 'cdrtypenum' )
     || $self->ut_number('min_included')
 
     #|| $self->ut_money('min_charge')
     #good enough for now...
+    || $self->ut_floatn('conn_charge')
+    || $self->ut_floatn('conn_cost')
     || $self->ut_float('min_charge')
+    || $self->ut_floatn('min_cost')
 
     || $self->ut_number('sec_granularity')
 
     || $self->ut_foreign_keyn('classnum', 'usage_class', 'classnum' )
+    || $self->ut_enum('region_group',    [ '', 'Y' ])
+
+    || $self->ut_floatn('upstream_mult_charge')
+    || $self->ut_floatn('upstream_mult_cost')
   ;
   return $error if $error;
 
@@ -182,10 +201,13 @@ with this call plan rate.
 
 sub dest_regionname {
   my $self = shift;
-  $self->dest_region->regionname;
+  my $dest_region = $self->dest_region;
+  $dest_region ? $dest_region->regionname : 'Global default';
+    # should be 'Anywhere' or something, to indicate that it's the
+    # cross-region default
 }
 
-=item dest_regionname
+=item dest_prefixes_short
 
 Returns a short list of the prefixes for the destination region
 (see L<FS::rate_region>) associated with this call plan rate.
@@ -194,7 +216,8 @@ Returns a short list of the prefixes for the destination region
 
 sub dest_prefixes_short {
   my $self = shift;
-  $self->dest_region->prefixes_short;
+  my $dest_region = $self->dest_region;
+  $dest_region ? $dest_region->prefixes_short : '';
 }
 
 =item rate_time
@@ -218,7 +241,7 @@ associated with this rate plan.
 
 sub rate_time_name {
   my $self = shift;
-  $self->ratetimenum ? $self->rate_time->ratetimename : '(default)';
+  $self->ratetimenum ? $self->rate_time->ratetimename : '(any time)';
 }
 
 =item classname
@@ -234,6 +257,20 @@ sub classname {
   $usage_class ? $usage_class->classname : '';
 }
 
+=item cdrtypename
+
+Returns the name of the CDR type (see L<FS::cdr_type) associated with this 
+rate, if there is one.  If not, returns the cdrtypenum itself.  This will 
+only return an empty string if cdrtypenum is NULL.
+
+=cut
+
+sub cdrtypename {
+  my $self = shift;
+  my $cdrtypenum = $self->cdrtypenum or return '';
+  my $cdr_type = qsearchs('cdr_type', { cdrtypenum => $cdrtypenum });
+  return $cdr_type ? $cdr_type->cdrtypename : $cdrtypenum;
+}
 
 =back