diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index 6535fb3ebb..21b111397e 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -542,7 +542,7 @@ sub edit :Chained('base_restricted') :PathPart('edit') :Args(0) { } } - NGCP::Panel::Utils::Subscriber::switch_prepaid(c => $c, + NGCP::Panel::Utils::Subscriber::switch_prepaid_contract(c => $c, #old_prepaid => $old_prepaid, #new_prepaid => $billing_profile->prepaid, prepaid => $billing_profile->prepaid, diff --git a/lib/NGCP/Panel/Role/API/Customers.pm b/lib/NGCP/Panel/Role/API/Customers.pm index 2f1417fe45..b5d0a56c4a 100644 --- a/lib/NGCP/Panel/Role/API/Customers.pm +++ b/lib/NGCP/Panel/Role/API/Customers.pm @@ -300,7 +300,7 @@ sub update_customer { ); } - NGCP::Panel::Utils::Subscriber::switch_prepaid(c => $c, + NGCP::Panel::Utils::Subscriber::switch_prepaid_contract(c => $c, #old_prepaid => $old_resource->{prepaid}, #new_prepaid => $billing_profile->prepaid, prepaid => $billing_profile->prepaid, diff --git a/lib/NGCP/Panel/Utils/ProfilePackages.pm b/lib/NGCP/Panel/Utils/ProfilePackages.pm index 070c87d37b..b1e8a27852 100644 --- a/lib/NGCP/Panel/Utils/ProfilePackages.pm +++ b/lib/NGCP/Panel/Utils/ProfilePackages.pm @@ -950,7 +950,7 @@ sub add_profile_mappings { $bm_actual = get_actual_billing_mapping(c => $c, contract => $contract, now => $now); - NGCP::Panel::Utils::Subscriber::switch_prepaid(c => $c, + NGCP::Panel::Utils::Subscriber::switch_prepaid_contract(c => $c, #old_prepaid => $old_prepaid, #new_prepaid => $bm_actual->billing_mappings->first->billing_profile->prepaid, prepaid => $bm_actual->billing_mappings->first->billing_profile->prepaid, diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index 9512b4d267..8f20faa6e4 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -116,7 +116,7 @@ sub get_provisoning_voip_subscriber_lock_level { sub switch_prepaid { my %params = @_; - + NGCP::Panel::Utils::Preferences::set_provisoning_voip_subscriber_first_int_attr_value(%params, value => ($params{prepaid} ? 1 : 0), attribute => 'prepaid' @@ -124,6 +124,18 @@ sub switch_prepaid { } +sub switch_prepaid_contract { + my %params = @_; + my $contract = $params{contract}; + + for my $subscriber ($contract->voip_subscribers->search_rs({ 'me.status' => { '!=' => 'terminated' } })->all) { + switch_prepaid(%params, + prov_subscriber => $subscriber->provisioning_voip_subscriber, + ) if ($subscriber->provisioning_voip_subscriber); + } + +} + sub get_lock_string { my $level = shift; return $LOCK{$level}; diff --git a/t/api-rest/api-balanceintervals.t b/t/api-rest/api-balanceintervals.t index b5dfabe08a..0d49269127 100644 --- a/t/api-rest/api-balanceintervals.t +++ b/t/api-rest/api-balanceintervals.t @@ -147,7 +147,7 @@ my $gantt_events; if (_get_allow_fake_client_time()) { # && $enable_profile_packages) { - #goto SKIP; + goto SKIP; #goto THREADED; if ('Europe/Vienna' eq NGCP::Panel::Utils::DateTime::current_local()->time_zone->name) { my $package = _create_profile_package('create','hour',1); @@ -237,10 +237,11 @@ if (_get_allow_fake_client_time()) { # && $enable_profile_packages) { _set_time(); } + SKIP: { - my $profile_initial = _create_billing_profile('UNDERRUN1_INITIAL'); - my $profile_topup = _create_billing_profile('UNDERRUN1_TOPUP'); - my $profile_underrun = _create_billing_profile('UNDERRUN1_UNDERRUN'); + my $profile_initial = _create_billing_profile('UNDERRUN1_INITIAL',prepaid => 0); + my $profile_topup = _create_billing_profile('UNDERRUN1_TOPUP',prepaid => 0); + my $profile_underrun = _create_billing_profile('UNDERRUN1_UNDERRUN',prepaid => 1); my $package = _create_profile_package('1st','month',1, initial_balance => 100, carry_over_mode => 'discard', underrun_lock_threshold => 50, underrun_lock_level => 4, underrun_profile_threshold => 50, @@ -1960,7 +1961,7 @@ sub _perform_topup_cash { } sub _create_billing_profile { - my ($name) = @_; + my ($name,@further_opts) = @_; $req = HTTP::Request->new('POST', $uri.'/api/billingprofiles/'); $req->header('Content-Type' => 'application/json'); $req->header('Prefer' => 'return=representation'); @@ -1968,6 +1969,7 @@ sub _create_billing_profile { name => $name." $t", handle => $name."_$t", reseller_id => $default_reseller_id, + @further_opts, }; $req->content(JSON::to_json($req_data)); $res = $ua->request($req);