X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FPrepaidPhone.pm;h=c7317ea23c256cf1e7838f443a0cd2bcc6c7081e;hb=a72a10f754f7465121d6137bb3dcee0a21ea6443;hp=00bc0ffd07135c0e63c7590f4d933be897a67863;hpb=40a7b3dc653e099f7bd0bd762b649b04c4432db2;p=freeside.git diff --git a/FS/FS/ClientAPI/PrepaidPhone.pm b/FS/FS/ClientAPI/PrepaidPhone.pm index 00bc0ffd0..c7317ea23 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'}; @@ -230,12 +235,17 @@ Customer balance. sub phonenum_balance { my $packet = shift; + warn "$me phonenum_balance called with countrycode ".$packet->{'countrycode'}. + " and phonenum ". $packet->{'phonenum'}. "\n" + if $DEBUG; + my $svc_phone = qsearchs('svc_phone', { 'countrycode' => ( $packet->{'countrycode'} || 1 ), 'phonenum' => $packet->{'phonenum'}, }); unless ( $svc_phone ) { + warn "$me no phone number found\n" if $DEBUG; return { 'custnum' => '', 'balance' => 0, }; @@ -243,9 +253,18 @@ 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; + + 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, }; }