[freeside-commits] branch master updated. 8e3646075dfae1246f287ba3384eb34a83c67b08

Mark Wells mark at 420.am
Thu Mar 13 15:25:02 PDT 2014


The branch, master has been updated
       via  8e3646075dfae1246f287ba3384eb34a83c67b08 (commit)
      from  4549ed888d5cf6e89d8795fbbc7d58eebee73d7f (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 8e3646075dfae1246f287ba3384eb34a83c67b08
Author: Mark Wells <mark at freeside.biz>
Date:   Thu Mar 13 15:24:53 2014 -0700

    make region group included minutes work again, probably fallout from #5738

diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index 0fdcbdf..583e728 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -577,25 +577,19 @@ sub parse_number {
 
 Rates this CDR according and sets the status to 'rated'.
 
-Available options are: part_pkg, svcnum, single_price_included_minutes, region_group, region_group_included_minutes.
+Available options are: part_pkg, svcnum, plan_included_min,
+detail_included_min_hashref.
 
 part_pkg is required.
 
 If svcnum is specified, will also associate this CDR with the specified svcnum.
 
-single_price_included_minutes is requried for single_price price plans
-(otherwise unused/ignored).  It should be set to a scalar reference of the
-number of included minutes and will be decremented by the rated minutes of this
+plan_included_min should be set to a scalar reference of the number of 
+included minutes and will be decremented by the rated minutes of this
 CDR.
 
-region_group_included_minutes is required for prefix price plans which have
-included minutes (otherwise unused/ignored).  It should be set to a scalar
-reference of the number of included minutes and will be decremented by the
-rated minutes of this CDR.
-
-region_group_included_minutes_hashref is required for prefix price plans which
-have included minues (otherwise unused/ignored).  It should be set to an empty
-hashref at the start of a month's rating and then preserved across CDRs.
+detail_included_min_hashref should be set to an empty hashref at the 
+start of a month's rating and then preserved across CDRs.
 
 =cut
 
@@ -897,20 +891,19 @@ sub rate_prefix {
     $seconds += $charge_sec;
 
     if ( $rate_detail->min_included ) {
-      # the old, kind of deprecated way to do this
-      my $included_min = $opt{'region_group_included_min_hashref'} || {};
+      # the old, kind of deprecated way to do this:
+      # 
+      # The rate detail itself has included minutes.  We MUST have a place
+      # to track them.
+      my $included_min = $opt{'detail_included_min_hashref'}
+        or die "unable to rate CDR: rate detail has included minutes, but ".
+               "no detail_included_min_hashref provided.\n";
 
       # by default, set the included minutes for this region/time to
       # what's in the rate_detail
       $included_min->{$regionnum}{$ratetimenum} = $rate_detail->min_included
         unless exists $included_min->{$regionnum}{$ratetimenum};
 
-      # the way that doesn't work
-      #my $region_group = ($part_pkg->option_cacheable('min_included') || 0) > 0;
-
-      #${$opt{region_group_included_min}} -= $minutes 
-      #    if $region_group && $rate_detail->region_group;
-
       if ( $included_min->{$regionnum}{$ratetimenum} >= $minutes ) {
         $charge_sec = 0;
         $included_min->{$regionnum}{$ratetimenum} -= $minutes;
@@ -918,6 +911,18 @@ sub rate_prefix {
         $charge_sec -= ($included_min->{$regionnum}{$ratetimenum} * 60);
         $included_min->{$regionnum}{$ratetimenum} = 0;
       }
+    } elsif ( ${ $opt{'plan_included_min'} } > 0 ) {
+      # The package definition has included minutes, but only for in-group
+      # rate details.  Decrement them if this is an in-group call.
+      if ( $rate_detail->region_group ) {
+        if ( ${ $opt{'plan_included_min'} } >= $minutes ) {
+          $charge_sec = 0;
+          ${ $opt{'plan_included_min'} } -= $minutes;
+        } else {
+          $charge_sec -= (${ $opt{'plan_included_min'} } * 60);
+          ${ $opt{'plan_included_min'} } = 0;
+        }
+      }
     } else {
       # the new way!
       my $applied_min = $cust_pkg->apply_usage(
@@ -1020,12 +1025,12 @@ sub rate_single_price {
 
   my $charge_min = $minutes;
 
-  ${$opt{single_price_included_min}} -= $minutes;
-  if ( ${$opt{single_price_included_min}} > 0 ) {
+  ${$opt{plan_included_min}} -= $minutes;
+  if ( ${$opt{plan_included_min}} > 0 ) {
     $charge_min = 0;
   } else {
-     $charge_min = 0 - ${$opt{single_price_included_min}};
-     ${$opt{single_price_included_min}} = 0;
+     $charge_min = 0 - ${$opt{plan_included_min}};
+     ${$opt{plan_included_min}} = 0;
   }
 
   my $charge =
diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm
index 3a210ba..7e21b0f 100644
--- a/FS/FS/part_pkg/voip_cdr.pm
+++ b/FS/FS/part_pkg/voip_cdr.pm
@@ -402,13 +402,15 @@ sub calc_usage {
 
   my $charges = 0;
 
-  my $included_min = $self->option('min_included', 1) || 0; #single price rating
+  my $included_min = $self->option('min_included', 1) || 0;
+    #single price rating
+    #or region group
+
   my $included_calls = $self->option('calls_included', 1) || 0;
 
   my $cdr_svc_method    = $self->option('cdr_svc_method',1)||'svc_phone.phonenum';
   my $rating_method     = $self->option('rating_method') || 'prefix';
-  my $region_group_included_min = $self->option('min_included',1) || 0;
-  my %region_group_included_min = ();
+  my %detail_included_min = ();
 
   my $output_format     = $self->option('output_format', 'Hush!')
                           || ( $rating_method eq 'upstream_simple'
@@ -470,6 +472,7 @@ sub calc_usage {
     #my @invoice_details_sort;
 
     #first rate any outstanding CDRs not yet rated
+    # XXX eventually use an FS::Cursor for this
     my $cdr_search = $svc_x->psearch_cdrs(%options);
     $cdr_search->limit(1000);
     $cdr_search->increment(0); # because we're changing their status as we go
@@ -479,9 +482,8 @@ sub calc_usage {
         'part_pkg'                          => $self,
         'cust_pkg'                          => $cust_pkg,
         'svcnum'                            => $svc_x->svcnum,
-        'single_price_included_min'         => \$included_min,
-        'region_group_included_min'         => \$region_group_included_min,
-        'region_group_included_min_hashref' => \%region_group_included_min,
+        'plan_included_min'                 => \$included_min,
+        'detail_included_min_hashref'       => \%detail_included_min,
       );
       die $error if $error; #??
 

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

Summary of changes:
 FS/FS/cdr.pm               |   53 ++++++++++++++++++++++++--------------------
 FS/FS/part_pkg/voip_cdr.pm |   14 ++++++-----
 2 files changed, 37 insertions(+), 30 deletions(-)




More information about the freeside-commits mailing list