TT#29755 free cash testcase

Change-Id: I2be104b5770c7f68f334d7d6b2867cb5383607cf
changes/05/18105/15
Rene Krenn 7 years ago
parent 16c186e610
commit f450458ec1

@ -73,6 +73,12 @@ my $connect_interval = 3;
my $maintenance_mode = $ENV{RATEOMAT_MAINTENANCE} // 'no';
# test may execute rate-o-mat on another host with different
# timezone. the connection timezone can therefore be forced to
# eg. the UTC default on ngcp.
my $connection_timezone = $ENV{RATEOMAT_CONNECTION_TIMEZONE};
# $ENV{TZ} has to be adjusted in the root thread.
# billing database
my $BillDB_Name = $ENV{RATEOMAT_BILLING_DB_NAME} || 'billing';
my $BillDB_Host = $ENV{RATEOMAT_BILLING_DB_HOST} || 'localhost';
@ -244,7 +250,8 @@ sub connect_billdbh {
FATAL "Error connecting to db: ".$DBI::errstr
unless defined($billdbh);
INFO "Successfully connected to billing db...";
$billdbh->do('SET time_zone = ?',undef,$connection_timezone) or FATAL 'error setting connection timezone' if $connection_timezone;
INFO "Successfully connected to duplication db...";
}
@ -257,6 +264,7 @@ sub connect_acctdbh {
FATAL "Error connecting to db: ".$DBI::errstr
unless defined($acctdbh);
$acctdbh->do('SET time_zone = ?',undef,$connection_timezone) or FATAL 'error setting connection timezone' if $connection_timezone;
INFO "Successfully connected to accounting db...";
}
@ -276,6 +284,7 @@ sub connect_provdbh {
FATAL "Error connecting to db: ".$DBI::errstr
unless defined($provdbh);
$provdbh->do('SET time_zone = ?',undef,$connection_timezone) or FATAL 'error setting connection timezone' if $connection_timezone;
INFO "Successfully connected to provisioning db...";
}
@ -295,6 +304,7 @@ sub connect_dupdbh {
FATAL "Error connecting to db: ".$DBI::errstr
unless defined($dupdbh);
$dupdbh->do('SET time_zone = ?',undef,$connection_timezone) or FATAL 'error setting connection timezone' if $connection_timezone;
INFO "Successfully connected to duplication db...";
}
@ -1279,6 +1289,7 @@ PREPARE_BALANCE_CATCHUP:
if($create_time > $last_start and $create_time < $last_end) {
$create_time_aligned = truncate_day($create_time);
$create_time_aligned = $create_time if $create_time_aligned < $last_start;
DEBUG sub { "last ratio = " . ($last_end + 1 - $create_time_aligned) . ' / ' . ($last_end + 1 - $last_start) . ", create_time = $create_time, create_time_aligned = $create_time_aligned"; };
$ratio = ($last_end + 1 - $create_time_aligned) / ($last_end + 1 - $last_start);
}
DEBUG "last ratio: $ratio";
@ -1290,9 +1301,10 @@ PREPARE_BALANCE_CATCHUP:
# the customer didn't spent all of the the old free cash, but
# only e.g. 2euro overall. to get the raw balance, subtract the
# unused rest of the old free cash, e.g. -3euro.
DEBUG sub { "cash balance = $cash_balance, last_cash_balance_int = $last_cash_balance_int, old_free_cash = $old_free_cash"; };
$cash_balance += $last_cash_balance_int - $old_free_cash;
} #the customer spent all free cash
# new free cash can be added ...
DEBUG sub { "free cash refill: " . (($last_cash_balance_int - $old_free_cash) + ($profile->{int_free_cash} // 0.0)); };
}
} else {
DEBUG "discarding cash balance (mode '$carry_over_mode'".($notopup_expiration ? ", notopup expiration " . $notopup_expiration : "").")";
}

@ -14,10 +14,11 @@ use DateTime::Format::ISO8601 qw();
use Data::Rmap qw();
use Data::Dumper;
use Utils::Env qw();
my $uri = $ENV{CATALYST_SERVER} // 'https://127.0.0.1:443';
my $user = $ENV{API_USER} // 'administrator';
my $pass = $ENV{API_PASS} // 'administrator';
my $split_peak_parts = $ENV{RATEOMAT_SPLIT_PEAK_PARTS} // 0;
require Exporter;
our @ISA = qw(Exporter);
@ -36,6 +37,7 @@ our @EXPORT_OK = qw(
create_subscriber
update_item
set_cash_balance
get_cash_balance
perform_topup
is_infinite_future
get_subscriber_preferences
@ -281,11 +283,11 @@ sub current_unix {
sub _current_local {
if ($is_fake_time) {
return DateTime->from_epoch(epoch => Time::Warp::time,
time_zone => DateTime::TimeZone->new(name => 'local')
time_zone => DateTime::TimeZone->new(name => 'local' )
);
} else {
return DateTime->now(
time_zone => DateTime::TimeZone->new(name => 'local')
time_zone => DateTime::TimeZone->new(name => 'local' )
);
}
}
@ -375,6 +377,20 @@ sub set_cash_balance {
}
sub get_cash_balance {
my ($customer) = @_;
$req = HTTP::Request->new('GET', $uri.'/api/customerbalances/' . $customer->{id});
$req->header('X-Fake-Clienttime' => _get_fake_clienttime_now());
$res = _ua_request($req);
if (is($res->code, 200, "fetch customer id " . $customer->{id} . " customerbalance")) {
return _from_json($res->decoded_content);
} else {
eval {
diag(_from_json($res->decoded_content)->{message});
};
}
}
sub get_subscriber_preferences {
my ($subscriber) = @_;
$req = HTTP::Request->new('GET', $uri.'/api/subscriberpreferences/'.$subscriber->{id});
@ -468,7 +484,11 @@ sub _compare_interval {
}
if (defined $expected->{cash}) {
$ok = is($got->{cash_balance},$expected->{cash},$label . "check interval " . $got->{id} . " cash balance $got->{cash_balance} = $expected->{cash}") && $ok;
if (substr($expected->{cash},0,1) eq '~') {
$ok = is_float_approx($got->{cash_balance},substr($expected->{cash},1),$label . "check interval " . $got->{id} . " cash balance") && $ok;
} else {
$ok = is($got->{cash_balance},$expected->{cash},$label . "check interval " . $got->{id} . " cash balance $got->{cash_balance} = $expected->{cash}") && $ok;
}
}
if (defined $expected->{debit}) {
@ -764,14 +784,14 @@ sub _setup_fees {
my $peaktime_weekdays = delete $params{peaktime_weekdays};
my $peaktime_specials = delete $params{peaktime_special};
my $interval_free_time = delete $params{interval_free_time};
#my $interval_free_cash = delete $params{interval_free_cash};
my $interval_free_cash = delete $params{interval_free_cash};
my $profile = create_billing_profile(
reseller_id => $reseller->{id},
(defined $prepaid ? (prepaid => $prepaid) : ()),
(defined $peaktime_weekdays ? (peaktime_weekdays => $peaktime_weekdays) : ()),
(defined $peaktime_specials ? (peaktime_special => $peaktime_specials) : ()),
(defined $interval_free_time ? (interval_free_time => $interval_free_time) : ()),
#(defined $interval_free_cash ? (interval_free_cash => $interval_free_cash) : ()),
(defined $interval_free_cash ? (interval_free_cash => $interval_free_cash) : ()),
);
my $zone = create_billing_zone(
billing_profile_id => $profile->{id},

@ -0,0 +1,32 @@
package Utils::Env;
use strict;
use warnings;
use Test::More;
use POSIX qw(tzset strftime);
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(
set_local_timezone
);
## no critic (Variables::RequireLocalizedPunctuationVars)
#$ENV{RATEOMAT_BILLING_DB_HOST} = '192.168.0.84';
#$ENV{RATEOMAT_PROVISIONING_DB_HOST} = '192.168.0.84';
#$ENV{RATEOMAT_ACCOUNTING_DB_HOST} = '192.168.0.84';
$ENV{CATALYST_SERVER} = 'https://127.0.0.1:1443';
sub set_local_timezone {
(my $tz,$ENV{RATEOMAT_CONNECTION_TIMEZONE}) = @_;
if ($tz) {
my $old_tz = strftime("%Z", localtime());
$ENV{TZ} = $tz;
tzset;
diag("switching local timezone from $old_tz to " . strftime("%Z", localtime()));
}
}
1;

@ -11,6 +11,7 @@ use Data::Dumper;
use Time::HiRes qw();
use Data::Rmap qw();
use Utils::Env qw();
require Exporter;
our @ISA = qw(Exporter);
@ -330,9 +331,10 @@ sub generate_call_id {
}
sub decimal_to_string {
my $value = shift;
my ($value,$decimals) = @_;
$decimals //= 6;
if (defined $value) {
return sprintf('%6f',$value);
return sprintf('%.' . $decimals . 'f',$value);
} else {
return;
}
@ -789,8 +791,8 @@ sub check_cdr_cash_balance_data {
my $result = _get_cdr_cash_balance_data($cdr_id,$direction,$provider,$relation);
if (defined $expected) {
if ((scalar @$result) == 1) {
return is($result->[0]->{val_before},decimal_to_string($expected->{before}),$label.'before '.$result->[0]->{val_before}.' = '.decimal_to_string($expected->{before})) &
is($result->[0]->{val_after},decimal_to_string($expected->{after}),$label.'after '.$result->[0]->{val_after}.' = '.decimal_to_string($expected->{after}));
return is(decimal_to_string($result->[0]->{val_before},4),decimal_to_string($expected->{before},4),$label.'before '.decimal_to_string($result->[0]->{val_before},4).' = '.decimal_to_string($expected->{before},4)) &
is(decimal_to_string($result->[0]->{val_after},4),decimal_to_string($expected->{after},4),$label.'after '.decimal_to_string($result->[0]->{val_after},4).' = '.decimal_to_string($expected->{after},4));
} else {
return is(scalar @$result,1,$label.'number of records '.(scalar @$result).' = 1');
}
@ -977,6 +979,7 @@ sub _connect_accounting_db {
$accountingdb_user, $accountingdb_pass,
{AutoCommit => 1, mysql_auto_reconnect => 0, mysql_no_autocommit_cmd => 0, PrintError => 1, PrintWarn => 0});
die("Error connecting to accounting db: ".$DBI::errstr."\n") unless defined($dbh);
$dbh->do('SET time_zone = ?',undef,$ENV{RATEOMAT_CONNECTION_TIMEZONE}) or die('error setting connection timezone') if $ENV{RATEOMAT_CONNECTION_TIMEZONE};
return $dbh;
}
@ -985,6 +988,7 @@ sub _connect_provisioning_db {
$provisioningdb_user, $provisioningdb_pass,
{AutoCommit => 1, mysql_auto_reconnect => 0, mysql_no_autocommit_cmd => 0, PrintError => 1, PrintWarn => 0});
die("Error connecting to provisioning db: ".$DBI::errstr."\n") unless defined($dbh);
$dbh->do('SET time_zone = ?',undef,$ENV{RATEOMAT_CONNECTION_TIMEZONE}) or die('error setting connection timezone') if $ENV{RATEOMAT_CONNECTION_TIMEZONE};
return $dbh;
}

@ -101,7 +101,7 @@ foreach my $prepaid ((0,1)) { # prepaid, postpaid
my $balance_id = Utils::Rateomat::get_cdr_relation_data($label,$caller_cdr_map->{$contract_id},'source','customer','contract_balance_id');
Utils::Api::check_interval_history($label,$contract_id,[
{ cash => $cash_balance/100.0,
debit => (($no_balance && !$prepaid_costs) ? $caller_call_costs : 0.0)/100.0,
debit => ($prepaid_costs ? 0.0 : $caller_call_costs)/100.0, #(($no_balance && !$prepaid_costs) ? $caller_call_costs : 0.0)/100.0,
id => $balance_id,
},
]);
@ -113,7 +113,7 @@ foreach my $prepaid ((0,1)) { # prepaid, postpaid
$balance_id = Utils::Rateomat::get_cdr_relation_data($label,$caller_cdr_map->{$contract_id},'source','customer','contract_balance_id');
Utils::Api::check_interval_history($label,$contract_id,[
{ cash => $cash_balance/100.0,
debit => (($no_balance && !$prepaid_costs) ? $caller_call_costs : 0.0)/100.0,
debit => ($prepaid_costs ? 0.0 : $caller_call_costs)/100.0, #(($no_balance && !$prepaid_costs) ? $caller_call_costs : 0.0)/100.0,
id => $balance_id,
},
]);
@ -125,7 +125,7 @@ foreach my $prepaid ((0,1)) { # prepaid, postpaid
$balance_id = Utils::Rateomat::get_cdr_relation_data($label,$caller_cdr_map->{$contract_id},'source','customer','contract_balance_id');
Utils::Api::check_interval_history($label,$contract_id,[
{ cash => $cash_balance/100.0,
debit => (($no_balance && !$prepaid_costs) ? $caller_call_costs : 0.0)/100.0,
debit => ($prepaid_costs ? 0.0 : $caller_call_costs)/100.0, #(($no_balance && !$prepaid_costs) ? $caller_call_costs : 0.0)/100.0,
id => $balance_id,
},
]);
@ -138,7 +138,7 @@ foreach my $prepaid ((0,1)) { # prepaid, postpaid
$balance_id = Utils::Rateomat::get_cdr_relation_data($label,$cdr_ids[0],'destination','customer','contract_balance_id');
Utils::Api::check_interval_history($label,$contract_id,[
{ cash => $cash_balance/100.0,
debit => ($no_balance ? 3 * $callee_call_costs : 0.0)/100.0,
debit => 3 * $callee_call_costs/100.0, #($no_balance ? 3 * $callee_call_costs : 0.0)/100.0,
id => $balance_id,
},
]);

@ -96,7 +96,7 @@ my @offnet_subscribers = (Utils::Rateomat::prepare_offnet_subsriber_info({ cc =>
my $balance_id = Utils::Rateomat::get_cdr_relation_data($label,$cdr_ids[0],'source','customer','contract_balance_id');
Utils::Api::check_interval_history($label,$caller->{customer}->{id},[
{ cash => $cash_balance/100.0,
debit => (($no_balance && !$prepaid) ? 3 * $caller_call_costs : 0.0)/100.0,
debit => ((!$prepaid) ? 3 * $caller_call_costs : 0.0)/100.0,
id => $balance_id,
},
]);
@ -224,7 +224,7 @@ my @offnet_subscribers = (Utils::Rateomat::prepare_offnet_subsriber_info({ cc =>
my $balance_id = Utils::Rateomat::get_cdr_relation_data($label,$cdr_ids[0],'destination','customer','contract_balance_id');
Utils::Api::check_interval_history($label,$callee->{customer}->{id},[
{ cash => $cash_balance/100.0,
debit => ($no_balance ? 3 * $callee_call_costs : 0.0)/100.0,
debit => 3 * $callee_call_costs/100.0, #(!$prepaid ? 3 * $callee_call_costs : 0.0)/100.0,
id => $balance_id,
},
]);

@ -117,7 +117,6 @@ sub create_provider {
offpeak_init_interval => $init_secs,
offpeak_follow_rate => 2,
offpeak_follow_interval => $follow_secs,
interval_free_time => $free_time_in,
use_free_time => 1,
},
]

@ -0,0 +1,215 @@
use strict;
use warnings;
use File::Basename;
use Cwd;
use lib Cwd::abs_path(File::Basename::dirname(__FILE__));
use Utils::Api qw();
use Utils::Rateomat qw();
use Utils::Env qw();
use Test::More;
### testcase outline:
### onnet calls that consume profile's freecash
###
### this tests verify the free cash refill,
### for both prepaid and postpaid (new).
local $ENV{RATEOMAT_WRITE_CDR_RELATION_DATA} = 1;
Utils::Env::set_local_timezone('UTC','+00:00'); #'UTC'; #vagrant SYSTEM timezone is "Etc/UTC"
my $init_secs = 50;
my $follow_secs = 20;
my $free_cash_in = 60; #callee
my $free_cash_out = 50; #caller
foreach my $prepaid ((0,1)) { #0,1)) {
foreach my $balance ((undef,5,65)) { #undef,5,65)) {
my $now = Utils::Api::get_now();
my $begin = $now->clone->subtract(months => 3);
Utils::Api::set_time($begin);
my $provider = create_provider($prepaid,$free_cash_in,$free_cash_out);
my $caller = Utils::Api::setup_subscriber($provider,$provider->{subscriber_fees}->[0]->{profile},$balance,{ cc => 888, ac => '1<n>', sn => '<t>' });
my $caller_ratio = _get_free_ratio(Utils::Api::datetime_from_string($caller->{customer}->{create_timestamp}),
Utils::Api::datetime_from_string($caller->{first_interval}->{start}),
Utils::Api::datetime_from_string($caller->{first_interval}->{stop}));
is(Utils::Api::get_cash_balance($caller->{customer})->{ratio},$caller_ratio,"caller ratio $caller_ratio");
Utils::Api::set_time($begin->clone->add(days => 10));
my $callee = Utils::Api::setup_subscriber($provider,$provider->{subscriber_fees}->[1]->{profile},$balance,{ cc => 888, ac => '2<n>', sn => '<t>' });
my $callee_ratio = _get_free_ratio(Utils::Api::datetime_from_string($callee->{customer}->{create_timestamp}),
Utils::Api::datetime_from_string($callee->{first_interval}->{start}),
Utils::Api::datetime_from_string($callee->{first_interval}->{stop}));
is(Utils::Api::get_cash_balance($callee->{customer})->{ratio},$callee_ratio,"callee ratio $callee_ratio");
my ($caller_delta,$callee_delta) = (0,0);
if (defined $balance) {
$caller_delta = $free_cash_out * $caller_ratio - $balance;
$callee_delta = $free_cash_in * $callee_ratio - $balance;
}
my $caller_costs = (($provider->{subscriber_fees}->[0]->{fees}->[0]->{onpeak_init_rate} *
$init_secs) + ($provider->{subscriber_fees}->[0]->{fees}->[0]->{onpeak_follow_rate} * $follow_secs))/100.0;
my $callee_costs = (($provider->{subscriber_fees}->[1]->{fees}->[0]->{onpeak_init_rate} *
$init_secs) + ($provider->{subscriber_fees}->[1]->{fees}->[0]->{onpeak_follow_rate} * $follow_secs))/100.0;
my $call_duration = $init_secs + $follow_secs - 1;
Utils::Api::set_time($now->clone->subtract(months => 2));
my $start_time1 = Utils::Api::current_unix() - $call_duration;
Utils::Api::set_time($now->clone->subtract(months => 1));
my $start_time2 = Utils::Api::current_unix() - $call_duration;
my @cdr_ids = ();
#if ($prepaid) {
# @cdr_ids = map { $_->{cdr}->{id}; } @{ Utils::Rateomat::create_prepaid_costs_cdrs([
# Utils::Rateomat::prepare_prepaid_costs_cdr($caller->{subscriber}, undef,
# $caller->{reseller}, $callee->{subscriber}, undef,
# $callee->{reseller}, '192.168.0.1', $start_time1, $call_duration,$caller_costs,0),
# Utils::Rateomat::prepare_prepaid_costs_cdr($caller->{subscriber}, undef,
# $caller->{reseller}, $callee->{subscriber}, undef,
# $callee->{reseller}, '192.168.0.1', $start_time2, $call_duration,$caller_costs,0),
# ]) };
#} else {
@cdr_ids = map { $_->{id}; } @{ Utils::Rateomat::create_cdrs([
Utils::Rateomat::prepare_cdr($caller->{subscriber}, undef,
$caller->{reseller}, $callee->{subscriber}, undef,
$callee->{reseller}, '192.168.0.1', $start_time1, $call_duration),
Utils::Rateomat::prepare_cdr($caller->{subscriber}, undef,
$caller->{reseller}, $callee->{subscriber}, undef,
$callee->{reseller}, '192.168.0.1', $start_time2, $call_duration),
]) };
#}
Utils::Api::set_time();
if (ok((scalar @cdr_ids) > 0 && Utils::Rateomat::run_rateomat_threads(),'rate-o-mat executed')) {
#ok(Utils::Rateomat::check_prepaid_costs_cdrs('',0,
# map { $_ => {
# id => $_,
# rating_status => 'ok',
# source_customer_cost => Utils::Rateomat::decimal_to_string(0),
# destination_customer_cost => Utils::Rateomat::decimal_to_string(0),
# };
# } @cdr_ids),'cdrs were all processed') if $prepaid;
ok(Utils::Rateomat::check_cdrs('',
map { $_ => {
id => $_,
rating_status => 'ok',
source_customer_cost => Utils::Rateomat::decimal_to_string($prepaid ? $caller_costs*100 : 0),
destination_customer_cost => Utils::Rateomat::decimal_to_string($prepaid ? $callee_costs*100 : 0),
};
} @cdr_ids),'cdrs were all processed'); # unless $prepaid;
my $label = ($prepaid ? 'prepaid ' : 'postpaid ') . 'freecash ' . (defined $balance ? "(balance $balance) " : '') . '- caller: ';
Utils::Api::check_interval_history($label,$caller->{customer}->{id}, [ {
profile => $provider->{subscriber_fees}->[0]->{profile}->{id},
cash => '~' . (defined $balance ? $balance : $free_cash_out * $caller_ratio),
},{
profile => $provider->{subscriber_fees}->[0]->{profile}->{id},
id => Utils::Rateomat::get_cdr_relation_data($label,$cdr_ids[0],'source','customer','contract_balance_id'),
cash => '~' . (($free_cash_out - $caller_costs) - $caller_delta),
},{
profile => $provider->{subscriber_fees}->[0]->{profile}->{id},
id => Utils::Rateomat::get_cdr_relation_data($label,$cdr_ids[1],'source','customer','contract_balance_id'),
cash => '~' . (($free_cash_out - $caller_costs) - $caller_delta),
},{
profile => $provider->{subscriber_fees}->[0]->{profile}->{id},
cash => '~' . ($free_cash_out - $caller_delta), #by panel
}]);
Utils::Rateomat::check_cdr_cash_balance_data($label,$cdr_ids[0],'source','customer','cash_balance',
{ before => ($free_cash_out - $caller_delta) * 100, after => ($free_cash_out - $caller_costs - $caller_delta) * 100 });
Utils::Rateomat::check_cdr_cash_balance_data($label,$cdr_ids[1],'source','customer','cash_balance',
{ before => ($free_cash_out - $caller_delta) * 100, after => ($free_cash_out - $caller_costs - $caller_delta) * 100 });
$label = ($prepaid ? 'prepaid ' : 'postpaid ') . 'freecash ' . (defined $balance ? "(balance $balance) " : '') . '- callee: ';
Utils::Api::check_interval_history($label,$callee->{customer}->{id}, [ {
profile => $provider->{subscriber_fees}->[1]->{profile}->{id},
cash => '~' . (defined $balance ? $balance : $free_cash_in * $callee_ratio),
},{
profile => $provider->{subscriber_fees}->[1]->{profile}->{id},
id => Utils::Rateomat::get_cdr_relation_data($label,$cdr_ids[0],'destination','customer','contract_balance_id'),
cash => '~' . ($free_cash_in - $callee_costs - $callee_delta),
},{
profile => $provider->{subscriber_fees}->[1]->{profile}->{id},
id => Utils::Rateomat::get_cdr_relation_data($label,$cdr_ids[1],'destination','customer','contract_balance_id'),
cash => '~' . ($free_cash_in - $callee_costs - $callee_delta),
},{
profile => $provider->{subscriber_fees}->[1]->{profile}->{id},
cash => '~' . ($free_cash_in - $callee_delta), #by panel
}]);
Utils::Rateomat::check_cdr_cash_balance_data($label,$cdr_ids[0],'destination','customer','cash_balance',
{ before => ($free_cash_in - $callee_delta) * 100, after => ($free_cash_in - $callee_costs - $callee_delta) * 100 });
Utils::Rateomat::check_cdr_cash_balance_data($label,$cdr_ids[1],'destination','customer','cash_balance',
{ before => ($free_cash_in - $callee_delta) * 100, after => ($free_cash_in - $callee_costs - $callee_delta) * 100 });
}
}
}
done_testing();
exit;
sub create_provider {
my ($prepaid,$free_cash_in,$free_cash_out) = @_;
return Utils::Api::setup_provider('test<n>.com', [
# rates:
{
interval_free_cash => $free_cash_out * 100,
prepaid => $prepaid,
fees => [
{
direction => 'out',
destination => '.',
onpeak_init_rate => 3,
onpeak_init_interval => $init_secs,
onpeak_follow_rate => 3,
onpeak_follow_interval => $follow_secs,
offpeak_init_rate => 2,
offpeak_init_interval => $init_secs,
offpeak_follow_rate => 2,
offpeak_follow_interval => $follow_secs,
},
]
}, {
interval_free_cash => $free_cash_in * 100,
prepaid => $prepaid,
fees => [
{
direction => 'in',
destination => '.',
source => '.',
onpeak_init_rate => 4,
onpeak_init_interval => $init_secs,
onpeak_follow_rate => 4,
onpeak_follow_interval => $follow_secs,
offpeak_init_rate => 2,
offpeak_init_interval => $init_secs,
offpeak_follow_rate => 2,
offpeak_follow_interval => $follow_secs,
},
]
},
], [
# billing networks:
]);
}
sub _get_free_ratio {
my ($ctime,$stime,$etime) = @_;
my $start_of_next_interval = _add_second($etime->clone,1);
$ctime = $ctime->clone->truncate(to => 'day') > $stime ? $ctime->clone->truncate(to => 'day') : $ctime;
diag('ratio = ' . ($start_of_next_interval->epoch - $ctime->epoch) . ' / ' . ($start_of_next_interval->epoch - $stime->epoch));
return ($start_of_next_interval->epoch - $ctime->epoch) / ($start_of_next_interval->epoch - $stime->epoch);
}
sub _add_second {
my ($dt,$skip_leap_seconds) = @_;
$dt->add(seconds => 1);
while ($skip_leap_seconds and $dt->second() >= 60) {
$dt->add(seconds => 1);
}
return $dt;
}

@ -177,8 +177,8 @@ foreach my $start_mode ('create','1st') {
#SKIP:
foreach my $carry_over_mode ('carry_over','carry_over_timely') {
my @cash_values;
@cash_values = ( [ cash => $amount - $costs, debit => 0 ], [ cash => $amount - $costs ], [ cash => 0, debit => $underrun_costs ] ) if 'carry_over' eq $carry_over_mode;
@cash_values = ( [ cash => $amount - $costs, debit => 0 ], [ cash => 0, debit => $underrun_costs ], [ cash => 0, debit => $underrun_costs ] ) if 'carry_over_timely' eq $carry_over_mode;
@cash_values = ( [ cash => $amount - $costs, debit => $costs ], [ cash => $amount - $costs ], [ cash => 0, debit => $underrun_costs ] ) if 'carry_over' eq $carry_over_mode;
@cash_values = ( [ cash => $amount - $costs, debit => $costs ], [ cash => 0, debit => $underrun_costs ], [ cash => 0, debit => $underrun_costs ] ) if 'carry_over_timely' eq $carry_over_mode;
foreach my $start_mode ('topup','topup_interval') {
my $profiles_setup = Utils::Api::setup_package($provider,

Loading…
Cancel
Save