[freeside-commits] branch FREESIDE_4_BRANCH updated. eb8176675b99422a309534808e38d51571228cfe

Mark Wells mark at 420.am
Fri Oct 23 13:54:10 PDT 2015


The branch, FREESIDE_4_BRANCH has been updated
       via  eb8176675b99422a309534808e38d51571228cfe (commit)
      from  e8a7a756aa97a62dec29cdbdc24e6bb3c15aa5ee (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit eb8176675b99422a309534808e38d51571228cfe
Author: Mark Wells <mark at freeside.biz>
Date:   Fri Oct 23 12:03:24 2015 -0700

    allow a default rate detail for each CDR type, #38633

diff --git a/FS/FS/rate.pm b/FS/FS/rate.pm
index d26d116..9b90dd2 100644
--- a/FS/FS/rate.pm
+++ b/FS/FS/rate.pm
@@ -54,6 +54,8 @@ it may still be processed under a different pricing addon package), or be
 marked as 'skipped', or throw a fatal error, depending on the setting of 
 the 'ignore_unrateable' package option.
 
+Deprecated; we now find the default detail by its lack of regionnum.
+
 =item 
 
 =back
@@ -347,7 +349,11 @@ sub dest_detail {
       });
     }
 
-    return $self->default_detail unless $rate_prefix;
+    if ( !$rate_prefix ) {
+      # then this call doesn't match any known region; just return the
+      # appropriate anywhere rate
+      return $self->default_detail($cdrtypenum) || $self->default_detail('');
+    }
 
     $regionnum = $rate_prefix->regionnum;
 
@@ -365,7 +371,14 @@ sub dest_detail {
       %hash,
       'cdrtypenum' => $cdrtypenum
     });
-  # find all rates maching ratenum, regionnum and null cdrtypenum
+  # failing that, return the global default for this plan with the correct
+  # cdrtypenum (skips weektime processing)
+  if ( !@details and $cdrtypenum ) {
+    my $detail = $self->default_detail($cdrtypenum);
+    return $detail if $detail;
+  }
+  # failing that, find all rates maching ratenum, regionnum and null cdrtypenum
+  # (these can have weektime stuff)
   if ( !@details and $cdrtypenum ) {
     @details = qsearch( 'rate_detail', {
         %hash,
@@ -391,7 +404,7 @@ sub dest_detail {
     return $_ if $_->ratetimenum eq '';
   }
   # if still nothing, return the global default rate for this plan
-  return $self->default_detail;
+  return $self->default_detail('');
 }
 
 =item rate_detail
@@ -400,16 +413,24 @@ Returns all region-specific details  (see L<FS::rate_detail>) for this rate.
 
 =back
 
-=item default_detail
+=item default_detail [ CDRTYPENUM ]
 
-Returns the default rate detail, if there is one.
+Returns the default rate detail for CDRTYPENUM (or for null CDR type, if not
+specified).
 
 =cut
 
 sub default_detail {
   my $self = shift;
-  $self->default_detailnum ?
-    FS::rate_detail->by_key($self->default_detailnum) : ''
+  my $cdrtypenum = shift || '';
+#  $self->default_detailnum ?
+#    FS::rate_detail->by_key($self->default_detailnum) : ''
+  qsearchs( 'rate_detail', {
+      ratenum         => $self->ratenum,
+      cdrtypenum      => $cdrtypenum,
+      dest_regionnum  => '',
+      orig_regionnum  => '',
+  }) || '';
 }
 
 =head1 SUBROUTINES
diff --git a/FS/FS/rate_detail.pm b/FS/FS/rate_detail.pm
index fcd9f58..8933354 100644
--- a/FS/FS/rate_detail.pm
+++ b/FS/FS/rate_detail.pm
@@ -132,6 +132,7 @@ sub check {
     || $self->ut_foreign_key('ratenum', 'rate', 'ratenum')
     || $self->ut_foreign_keyn('orig_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')
@@ -194,6 +195,8 @@ sub dest_regionname {
   my $self = shift;
   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_prefixes_short
@@ -230,7 +233,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
diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi
index 07f104e..1e8b510 100755
--- a/httemplate/browse/part_pkg.cgi
+++ b/httemplate/browse/part_pkg.cgi
@@ -88,6 +88,14 @@ if ( $cgi->param('missing_recur_fee') ) {
                            )";
 }
 
+if ( $cgi->param('ratenum') =~ /^(\d+)$/ ) {
+  push @where, "EXISTS( SELECT 1 FROM part_pkg_option
+                          WHERE optionname LIKE '%ratenum'
+                            AND optionvalue = '$1'
+                            AND part_pkg_option.pkgpart = part_pkg.pkgpart
+                      )";
+}
+
 if ( $cgi->param('family') =~ /^(\d+)$/ ) {
   $family_pkgpart = $1;
   push @where, "family_pkgpart = $1";
diff --git a/httemplate/edit/elements/rate_detail.html b/httemplate/edit/elements/rate_detail.html
index 7b5ec31..32dd502 100644
--- a/httemplate/edit/elements/rate_detail.html
+++ b/httemplate/edit/elements/rate_detail.html
@@ -61,18 +61,18 @@ with row headers showing the region name and prefixes.
 %   $row++;
 % }# foreach @rate_region
 % if ( !$opt{regionnum} ) {
-%# global default
+%   # global default for this cdrtypenum
 <TR>
   <TD COLSPAN=2 STYLE="padding-top: 10px">
     <B>Global default</B> (for calls not matching any prefix)
   </TD>
   <TD STYLE="padding-top: 10px">
-%   # default rate: set a null region
+%   # default rate: set a null region for this cdr type
     <B>
     <& .detail_box,
-      detail      => $rate->default_detail,
+      detail      => $rate->default_detail($cdrtypenum),
       ratetimenum => '',
-      cdrtypenum  => '',
+      cdrtypenum  => $cdrtypenum,
       regionnum   => '',
       ratenum     => $rate->ratenum
     &>
diff --git a/httemplate/edit/process/rate_detail.html b/httemplate/edit/process/rate_detail.html
index f8a7444..4020ce9 100644
--- a/httemplate/edit/process/rate_detail.html
+++ b/httemplate/edit/process/rate_detail.html
@@ -2,7 +2,7 @@
   'table' => 'rate_detail',
   'popup_reload' => 'Rate changed', #a popup "parent reload" for now
               #someday change the individual element and go away instead
-  'noerror_callback' => $set_default_detail
+  #'noerror_callback' => $set_default_detail
 &>
 <%init>
 
@@ -12,19 +12,11 @@ die "access denied"
 
 my $set_default_detail = sub {
   my ($cgi, $rate_detail) = @_;
-  if (!$rate_detail->dest_regionnum) {
+  if (!$rate_detail->dest_regionnum and !$rate_detail->cdrtypenum) {
     # then this is a global default rate
+    # default_detailnum is no longer used, but maintain it anyway (and point
+    # it at the one with null cdrtypenum)
     my $rate = $rate_detail->rate;
-    if ($rate->default_detailnum) {
-      if ($rate->default_detailnum == $rate_detail->ratedetailnum) {
-        return;
-      } else {
-        # there's somehow an existing default rate. remove it.
-        my $old_default = $rate->default_detail;
-        my $error = $old_default->delete;
-        die "$error (removing old default rate)\n" if $error;
-      }
-    }
     $rate->set('default_detailnum' => $rate_detail->ratedetailnum);
     my $error = $rate->replace;
     die "$error (setting default rate)\n" if $error;
diff --git a/httemplate/edit/rate.cgi b/httemplate/edit/rate.cgi
index 1b052d6..5bfc108 100644
--- a/httemplate/edit/rate.cgi
+++ b/httemplate/edit/rate.cgi
@@ -1,7 +1,11 @@
-<% include("/elements/header.html","$action Rate plan", menubar(
+<& /elements/header.html,
+  "$action Rate plan",
+  menubar(
       'View all rate plans' => "${p}browse/rate.cgi",
-    ))
-%>
+      'View packages that use this plan' => "${p}browse/part_pkg.cgi?ratenum="
+                                            . $rate->ratenum,
+  )
+&>
 
 <% include('/elements/progress-init.html',
               'OneTrueForm',

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/rate.pm                             |   35 +++++++++++++++++++++++------
 FS/FS/rate_detail.pm                      |    5 ++++-
 httemplate/browse/part_pkg.cgi            |    8 +++++++
 httemplate/edit/elements/rate_detail.html |    8 +++----
 httemplate/edit/process/rate_detail.html  |   16 ++++---------
 httemplate/edit/rate.cgi                  |   10 ++++++---
 6 files changed, 55 insertions(+), 27 deletions(-)




More information about the freeside-commits mailing list