MT#19015 correctly use notopup_interval for periodic balance intervals

Change-Id: Iada0d0040c7a785ed0d2195edf4d1515b0ca5815
changes/37/6137/2
Rene Krenn 10 years ago
parent 9d49424995
commit 9f9dc0b08f

@ -410,13 +410,13 @@ sub init_db {
) or FATAL "Error preparing get last contract balance statement: ".$billdbh->errstr;
$sth_get_first_cbalance = $billdbh->prepare(
"SELECT UNIX_TIMESTAMP(start) ".
"SELECT UNIX_TIMESTAMP(start),UNIX_TIMESTAMP(end) ".
"FROM billing.contract_balances ".
"WHERE contract_id = ? ".
"ORDER BY start ASC LIMIT 1"
) or FATAL "Error preparing get first contract balance statement: ".$billdbh->errstr;
$sth_get_last_topup_cbalance = $billdbh->prepare(
"SELECT UNIX_TIMESTAMP(start) ".
"SELECT UNIX_TIMESTAMP(start),UNIX_TIMESTAMP(end) ".
"FROM billing.contract_balances ".
"WHERE contract_id = ? AND ".
"topup_count > 0 ".
@ -1070,21 +1070,26 @@ sub get_notopup_expiration {
my $sth;
my $notopup_expiration = undef;
my $last_topup_start_time;
my $last_topup_end_time;
if ($notopup_discard_intervals) { #get notopup_expiration:
if (defined $last_start_time) {
$last_topup_start_time = $last_start_time;
} else {
$sth = $sth_get_last_topup_cbalance;
$sth->execute($contract_id) or FATAL "Error executing get latest contract balance statement: ".$sth->errstr;
($last_topup_start_time) = $sth->fetchrow_array();
($last_topup_start_time,$last_topup_end_time) = $sth->fetchrow_array();
$sth->finish;
if (!$last_topup_start_time) {
$sth = $sth_get_first_cbalance;
$sth->execute($contract_id) or FATAL "Error executing get first contract balance statement: ".$sth->errstr;
($last_topup_start_time) = $sth->fetchrow_array();
($last_topup_start_time,$last_topup_end_time) = $sth->fetchrow_array();
$sth->finish;
}
$notopup_discard_intervals += 1;
if ($last_topup_start_time) {
if (!is_infinite_unix($last_topup_end_time)) {
$last_topup_start_time = $last_topup_end_time + 1;
}
}
}
if ($last_topup_start_time) {
$notopup_expiration = add_interval($interval_unit, $notopup_discard_intervals,

@ -44,7 +44,7 @@ our @EXPORT_OK = qw(
$ENV{RATEOMAT_BILLING_DB_USER} //= 'root';
$ENV{RATEOMAT_PROVISIONING_DB_USER} //= 'root';
$ENV{RATEOMAT_ACCOUNTING_DB_USER} //= 'root';
$ENV{RATEOMAT_DUPLICATE_DB_USER} //= 'root';
#$ENV{RATEOMAT_DUPLICATE_DB_USER} //= 'root';
$ENV{RATEOMAT_DEBUG} //= 1;
$ENV{RATEOMAT_DAEMONIZE} = 0;

@ -105,14 +105,14 @@ foreach my $start_mode ('create','1st') {
stop => Utils::Api::datetime_to_string($begin->add(days => $interval_days)->clone->subtract(seconds => 1)),
}; } 1..4;
if ('carry_over' eq $carry_over_mode) {
if (not Utils::Api::check_interval_history($label . ' no topup: ',$caller_notopup->{customer}->{id},[
Utils::Api::check_interval_history($label . ' no topup: ',$caller_notopup->{customer}->{id},[
set_cash($intervals[0],$amount - $costs),
set_cash($intervals[1],$amount - $costs),
set_cash($intervals[2],0),
set_cash($intervals[2],$amount - $costs), #0),
set_cash($intervals[3],0),
]) ){
print "FAIL due to bug";
}
]);
#print "FAIL due to bug";
#}
Utils::Api::check_interval_history($label . ' topup: ',$caller_topup->{customer}->{id},[
set_cash($intervals[0],2*$amount - $costs),
set_cash($intervals[1],2*$amount - $costs),

Loading…
Cancel
Save