[freeside-commits] branch master updated. 36ad5e538cb56de33c779e34baf9abdf63c4312e

Ivan ivan at 420.am
Tue Sep 3 22:52:31 PDT 2013


The branch, master has been updated
       via  36ad5e538cb56de33c779e34baf9abdf63c4312e (commit)
       via  04c1a98c9bcf2b6f0da8f18b627eec703dbafd49 (commit)
       via  6de95595e5e7eb53fd70fe6c30d96fb946091e93 (commit)
      from  aae697565c071b2880d0106b00a4a01d0ddab7bf (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 36ad5e538cb56de33c779e34baf9abdf63c4312e
Merge: 04c1a98 aae6975
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Sep 3 22:52:26 2013 -0700

    Merge branch 'master' of git.freeside.biz:/home/git/freeside


commit 04c1a98c9bcf2b6f0da8f18b627eec703dbafd49
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Sep 3 22:52:21 2013 -0700

    consider prerated CDRs in prepaid API responses, RT#22200

diff --git a/FS/FS/ClientAPI/PrepaidPhone.pm b/FS/FS/ClientAPI/PrepaidPhone.pm
index c7317ea..b05fb4f 100644
--- a/FS/FS/ClientAPI/PrepaidPhone.pm
+++ b/FS/FS/ClientAPI/PrepaidPhone.pm
@@ -157,9 +157,7 @@ sub call_time {
     return \%return;
   }
 
-  my $conf = new FS::Conf;
-  my $balance = $conf->config_bool('pkg-balances') ? $cust_pkg->balance
-                                                   : $cust_main->balance;
+  my $balance = FS::ClientAPI::PrepaidPhone->prepaid_phone_balance( $cust_pkg );
 
   #XXX granularity?  included minutes?  another day...
   if ( $balance >= 0 ) {
@@ -253,10 +251,7 @@ sub phonenum_balance {
 
   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
 
-  my $conf = new FS::Conf;
-  my $balance = $conf->config_bool('pkg-balances')
-    ? $cust_pkg->balance
-    : $cust_pkg->cust_main->balance;
+  my $balance = FS::ClientAPI::PrepaidPhone->prepaid_phone_balance( $cust_pkg );
 
   warn "$me returning $balance balance for pkgnum ".  $cust_pkg->pkgnum.
                                         ", custnum ". $cust_pkg->custnum
@@ -269,4 +264,65 @@ sub phonenum_balance {
 
 }
 
+sub prepaid_phone_balance {
+  my $class = shift; # i guess
+  my ($cust_pkg) = @_;
+
+  my $conf = new FS::Conf;
+
+  my $pkg_balances = $conf->config_bool('pkg-balances');
+  
+  my $balance = $pkg_balances ? $cust_pkg->balance
+                              : $cust_pkg->cust_main->balance;
+
+  if ( $conf->config_bool('cdr-prerate') ) {
+    my @cust_pkg = $pkg_balances ? ( $cust_pkg )
+                                 : ( $cust_pkg->cust_main->ncancelled_pkgs );
+    foreach my $cust_pkg ( @cust_pkg ) {
+
+      #we only support prerated CDRs with "VOIP/telco CDR rating (standard)"
+      # and "Phone numbers (svc_phone.phonenum)" CDR service matching for now
+      my $part_pkg = $cust_pkg->part_pkg;
+      next unless $part_pkg->plan eq 'voip_cdr'
+               && ($part_pkg->option('cdr_svc_method') || 'svc_phone.phonenum')
+                    eq 'svc_phone.phonenum'
+               && ! $part_pkg->option('bill_inactive_svcs');
+      #XXX skip when there's included minutes
+
+      #select prerated cdrs & subtract them from balance
+
+      # false laziness w/ part_pkg/voip_cdr.pm sorta
+
+      my %options = (
+          'disable_src'    => $part_pkg->option('disable_src'),
+          'default_prefix' => $part_pkg->option('default_prefix'),
+          'cdrtypenum'     => $part_pkg->option('use_cdrtypenum'),
+          'calltypenum'    => $part_pkg->option('use_calltypenum'),
+          'status'         => 'rated',
+          'by_svcnum'      => 1,
+      );  # $last_bill, $$sdate )
+
+      my @cust_svc = grep { $_->part_svc->svcdb eq 'svc_phone' }
+                       $cust_pkg->cust_svc;
+      foreach my $cust_svc ( @cust_svc ) {
+        
+        my $svc_x = $cust_svc->svc_x;
+
+        #XXX optimization: a single SQL query to return the total amount
+        my $cdr_search = $svc_x->psearch_cdrs(%options);
+        $cdr_search->limit(1000);
+        $cdr_search->increment(0);
+        while ( my $cdr = $cdr_search->fetch ) {
+          $balance -= $cdr->rated_price;
+        }
+
+      }
+
+    }
+  }
+
+  $balance;
+
+}
+
 1;

commit 6de95595e5e7eb53fd70fe6c30d96fb946091e93
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Sep 3 22:52:05 2013 -0700

    rounding

diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm
index 3ebe6c4..e127e8b 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -951,9 +951,15 @@ sub rate_prefix {
   # this is why we need regionnum/rate_region....
   warn "  (rate region $rate_region)\n" if $DEBUG;
 
+  # NOW round it.
+  my $rounding = $part_pkg->option_cacheable('rounding') || 2;
+  my $sprintformat = '%.'. $rounding. 'f';
+  my $roundup = 10**(-3-$rounding);
+  my $price = sprintf($sprintformat, $charge + $roundup);
+
   $self->set_status_and_rated_price(
     'rated',
-    sprintf('%.2f', $charge + 0.000001), # NOW round it.
+    $price,
     $opt{'svcnum'},
     'rated_pretty_dst'    => $pretty_dst,
     'rated_regionname'    => $rate_region->regionname,

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

Summary of changes:
 FS/FS/ClientAPI/PrepaidPhone.pm |   70 +++++++++++++++++++++++++++++++++++----
 FS/FS/cdr.pm                    |    8 ++++-
 2 files changed, 70 insertions(+), 8 deletions(-)




More information about the freeside-commits mailing list