[freeside-commits] branch master updated. 1ef17523c4d4c06b8f26e563d7f633ec7f2e7d99

Ivan ivan at 420.am
Tue Dec 4 08:59:23 PST 2012


The branch, master has been updated
       via  1ef17523c4d4c06b8f26e563d7f633ec7f2e7d99 (commit)
      from  9fa2bad9e9954ba0f838b032b4732de6847bb55b (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 1ef17523c4d4c06b8f26e563d7f633ec7f2e7d99
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Dec 4 08:59:22 2012 -0800

    prepaid API respects pkg-balances config, RT#19560

diff --git a/FS/FS/ClientAPI/PrepaidPhone.pm b/FS/FS/ClientAPI/PrepaidPhone.pm
index c346179..c7317ea 100644
--- a/FS/FS/ClientAPI/PrepaidPhone.pm
+++ b/FS/FS/ClientAPI/PrepaidPhone.pm
@@ -3,6 +3,7 @@ package FS::ClientAPI::PrepaidPhone;
 use strict;
 use vars qw($DEBUG $me);
 use FS::Record qw(qsearchs);
+use FS::Conf;
 use FS::rate;
 use FS::svc_phone;
 
@@ -156,11 +157,15 @@ sub call_time {
     return \%return;
   }
 
+  my $conf = new FS::Conf;
+  my $balance = $conf->config_bool('pkg-balances') ? $cust_pkg->balance
+                                                   : $cust_main->balance;
+
   #XXX granularity?  included minutes?  another day...
-  if ( $cust_main->balance >= 0 ) {
+  if ( $balance >= 0 ) {
     return { 'error'=>'No balance' };
   } else {
-    $return{'seconds'} = int(60 * abs($cust_main->balance) / $rate_detail->min_charge);
+    $return{'seconds'} = int(60 * abs($balance) / $rate_detail->min_charge);
   }
 
   warn "$me returning seconds: ". $return{'seconds'};
@@ -248,13 +253,18 @@ sub phonenum_balance {
 
   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
 
-  warn "$me returning ". $cust_pkg->cust_main->balance.
-       " balance for custnum ". $cust_pkg->custnum
+  my $conf = new FS::Conf;
+  my $balance = $conf->config_bool('pkg-balances')
+    ? $cust_pkg->balance
+    : $cust_pkg->cust_main->balance;
+
+  warn "$me returning $balance balance for pkgnum ".  $cust_pkg->pkgnum.
+                                        ", custnum ". $cust_pkg->custnum
     if $DEBUG;
 
   return {
     'custnum' => $cust_pkg->custnum,
-    'balance' => $cust_pkg->cust_main->balance,
+    'balance' => $balance,
   };
 
 }
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 16adea3..75a0d77 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -2650,6 +2650,18 @@ sub cust_main {
   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
 }
 
+=item balance
+
+Returns the balance for this specific package, when using
+experimental package balance.
+
+=cut
+
+sub balance {
+  my $self = shift;
+  $self->cust_main->balance_pkgnum( $self->pkgnum );
+}
+
 #these subs are in location_Mixin.pm now... unfortunately the POD doesn't mixin
 
 =item cust_location

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

Summary of changes:
 FS/FS/ClientAPI/PrepaidPhone.pm |   20 +++++++++++++++-----
 FS/FS/cust_pkg.pm               |   12 ++++++++++++
 2 files changed, 27 insertions(+), 5 deletions(-)




More information about the freeside-commits mailing list