From 7d045b9ffcb7c3112681252cc9bbe8bb2b211bbb Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 2 Aug 2018 08:34:06 +0200 Subject: [PATCH] TT#42260 remove prepaid and prepaid_library pref usage Change-Id: Iebd75291f0648ea054b82ace4251b1a98e629198 --- lib/NGCP/Panel/Controller/Customer.pm | 4 --- lib/NGCP/Panel/Form/BillingProfile/Admin.pm | 2 +- .../Panel/Form/BillingProfile/PeaktimeAPI.pm | 2 +- .../Panel/Form/BillingProfile/Reseller.pm | 14 +++++++- lib/NGCP/Panel/Role/API/Customers.pm | 2 +- lib/NGCP/Panel/Role/API/Subscribers.pm | 18 ---------- lib/NGCP/Panel/Utils/Billing.pm | 36 +++---------------- lib/NGCP/Panel/Utils/BillingMappings.pm | 18 +++++----- lib/NGCP/Panel/Utils/ProfilePackages.pm | 1 + lib/NGCP/Panel/Utils/SMS.pm | 23 +++--------- lib/NGCP/Panel/Utils/Subscriber.pm | 14 -------- 11 files changed, 34 insertions(+), 100 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index 068b947410..b81da4a21e 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -826,10 +826,6 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) { if(defined $form->values->{external_id}) { $preferences->{ext_subscriber_id} = $form->values->{external_id}; } - if($c->stash->{billing_mapping}->billing_profile->prepaid) { - # todo: drop setting the prepaid pref - $preferences->{prepaid} = 1; - } my @events_to_create = (); my $event_context = { events_to_create => \@events_to_create }; diff --git a/lib/NGCP/Panel/Form/BillingProfile/Admin.pm b/lib/NGCP/Panel/Form/BillingProfile/Admin.pm index b080a83059..09c8cbc8e7 100644 --- a/lib/NGCP/Panel/Form/BillingProfile/Admin.pm +++ b/lib/NGCP/Panel/Form/BillingProfile/Admin.pm @@ -15,7 +15,7 @@ has_field 'reseller' => ( has_block 'fields' => ( tag => 'div', class => [qw/modal-body/], - render_list => [qw/reseller handle name prepaid advice_of_charge interval_charge interval_free_time interval_free_cash + render_list => [qw/reseller handle name prepaid prepaid_library advice_of_charge interval_charge interval_free_time interval_free_cash fraud_interval_limit fraud_interval_lock fraud_interval_notify fraud_daily_limit fraud_daily_lock fraud_daily_notify fraud_use_reseller_rates currency id diff --git a/lib/NGCP/Panel/Form/BillingProfile/PeaktimeAPI.pm b/lib/NGCP/Panel/Form/BillingProfile/PeaktimeAPI.pm index 39affd3c3e..4f1f84c2cf 100644 --- a/lib/NGCP/Panel/Form/BillingProfile/PeaktimeAPI.pm +++ b/lib/NGCP/Panel/Form/BillingProfile/PeaktimeAPI.pm @@ -55,7 +55,7 @@ has_field 'peaktime_special.stop' => ( has_block 'fields' => ( tag => 'div', class => [qw/modal-body/], - render_list => [qw/reseller handle name prepaid interval_charge interval_free_time interval_free_cash + render_list => [qw/reseller handle name prepaid prepaid_library advice_of_charge interval_charge interval_free_time interval_free_cash fraud_interval_limit fraud_interval_lock fraud_interval_notify fraud_daily_limit fraud_daily_lock fraud_daily_notify fraud_use_reseller_rates currency id diff --git a/lib/NGCP/Panel/Form/BillingProfile/Reseller.pm b/lib/NGCP/Panel/Form/BillingProfile/Reseller.pm index 6a3a4adb98..7ffb092418 100644 --- a/lib/NGCP/Panel/Form/BillingProfile/Reseller.pm +++ b/lib/NGCP/Panel/Form/BillingProfile/Reseller.pm @@ -45,6 +45,18 @@ has_field 'prepaid' => ( }, ); +has_field 'prepaid_library' => ( + type => 'Select', + options => [ + { value => 'libswrate', label => 'libswrate' }, + { value => 'libinewrate', label => 'libinewrate' }, + ], + element_attr => { + rel => ['tooltip'], + title => ['Which prepaid rating library to use.'] + }, +); + has_field 'advice_of_charge' => ( type => 'Boolean', default => 0, @@ -191,7 +203,7 @@ has_field 'save' => ( has_block 'fields' => ( tag => 'div', class => [qw/modal-body/], - render_list => [qw/handle name prepaid advice_of_charge interval_charge interval_free_time interval_free_cash + render_list => [qw/handle name prepaid prepaid_library advice_of_charge interval_charge interval_free_time interval_free_cash fraud_interval_limit fraud_interval_lock fraud_interval_notify fraud_daily_limit fraud_daily_lock fraud_daily_notify fraud_use_reseller_rates currency id diff --git a/lib/NGCP/Panel/Role/API/Customers.pm b/lib/NGCP/Panel/Role/API/Customers.pm index 4cbd54e021..185ae9974f 100644 --- a/lib/NGCP/Panel/Role/API/Customers.pm +++ b/lib/NGCP/Panel/Role/API/Customers.pm @@ -135,7 +135,7 @@ sub update_customer { my $old_package = $customer->profile_package; - $old_resource->{prepaid} = $billing_profile->prepaid; + #$old_resource->{prepaid} = $billing_profile->prepaid; $old_resource->{billing_mapping} = $billing_mapping; $form //= $self->get_form($c); diff --git a/lib/NGCP/Panel/Role/API/Subscribers.pm b/lib/NGCP/Panel/Role/API/Subscribers.pm index 641015a83e..11d227c81e 100644 --- a/lib/NGCP/Panel/Role/API/Subscribers.pm +++ b/lib/NGCP/Panel/Role/API/Subscribers.pm @@ -288,18 +288,6 @@ sub get_customer { return $customer; } -sub get_billing_profile { - my ($self, $c, $customer, $now) = @_; - - my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $customer, ); - if($billing_mapping) { - return $billing_mapping->billing_profile; - } else { - $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'customer_id', doesn't have a valid billing mapping."); - return; - } -} - sub prepare_resource { my ($self, $c, $schema, $resource, $item) = @_; @@ -550,12 +538,6 @@ sub prepare_resource { $preferences->{ext_contract_id} = $customer->external_id; } - my $billing_profile = $self->get_billing_profile($c, $customer); - return unless($billing_profile); - if($billing_profile->prepaid) { - $preferences->{prepaid} = 1; - } - my $subscriber = $c->model('DB')->resultset('voip_subscribers')->find({ username => $resource->{username}, domain_id => $resource->{domain_id}, diff --git a/lib/NGCP/Panel/Utils/Billing.pm b/lib/NGCP/Panel/Utils/Billing.pm index 4ef71cfcc8..8fe93be8f7 100644 --- a/lib/NGCP/Panel/Utils/Billing.pm +++ b/lib/NGCP/Panel/Utils/Billing.pm @@ -27,6 +27,10 @@ sub check_profile_update_item { return 0 unless &{$err_code}("Billing profile is already terminated and cannot be changed.",'status'); } + #if ($new_resource->{prepaid} && not $new_resource->{prepaid_library}) { + # return 0 unless &{$err_code}("The prepaid rating library is mandatory for a prepaid profile.",'prepaid_library'); + #} + my $contract_cnt = $old_item->get_column('contract_cnt'); #my $package_cnt = $old_item->get_column('package_cnt'); @@ -400,38 +404,6 @@ sub clone_billing_profile_tackles{ sub switch_prepaid { my %params = @_; my ($c,$profile_id,$old_prepaid,$new_prepaid) = @params{qw/c profile_id old_prepaid new_prepaid/}; - my $schema = $c->model('DB'); - - # todo: drop switching the prepaid flag. - - # if prepaid flag changed, update all subscribers for customers - # who currently have the billing profile active - my $rs = $schema->resultset('actual_billing_profiles')->search({ - billing_profile_id => $profile_id, - 'contact.reseller_id' => { '-not' => undef }, - },{ - join => { contract => 'contact', }, - }); - - if($old_prepaid && !$new_prepaid || - !$old_prepaid && $new_prepaid) { - - #this will taking too long, prohibit it: - #die("changing the prepaid flag is not allowed"); - - foreach my $mapping ($rs->all) { - my $contract = $mapping->contract; - foreach my $sub ($contract->voip_subscribers->all) { - my $prov_sub = $sub->provisioning_voip_subscriber; - next unless($sub->provisioning_voip_subscriber); - NGCP::Panel::Utils::Preferences::set_provisoning_voip_subscriber_first_int_attr_value(c => $c, - prov_subscriber => $prov_sub, - value => ($new_prepaid ? 1 : 0), - attribute => 'prepaid' - ); - } - } - } } diff --git a/lib/NGCP/Panel/Utils/BillingMappings.pm b/lib/NGCP/Panel/Utils/BillingMappings.pm index 8173fa3552..30f361002b 100644 --- a/lib/NGCP/Panel/Utils/BillingMappings.pm +++ b/lib/NGCP/Panel/Utils/BillingMappings.pm @@ -155,7 +155,7 @@ sub prepare_billing_mappings { } # my $product_id = undef; #any subsequent create will fail without product_id - my $prepaid = undef; + #my $prepaid = undef; my $billing_profile_id = undef; if (defined $old_resource) { # TODO: what about changed product, do we allow it? @@ -170,7 +170,7 @@ sub prepare_billing_mappings { # return 0 unless &{$err_code}("No billing mapping or contract defined"); } # $product_id = $billing_mapping->contract->product->id; - $prepaid = $billing_mapping->billing_profile->prepaid; + #$prepaid = $billing_mapping->billing_profile->prepaid; $billing_profile_id = $billing_mapping->billing_profile->id; # } else { # if (exists $resource->{type} || exists $c->stash->{type}) { @@ -260,13 +260,13 @@ sub prepare_billing_mappings { network_id_field => 'network_id', ); my ($profile,$network) = @$entities{qw/profile network/}; - if (defined $prepaid) { - if ($profile->prepaid != $prepaid) { - return 0 unless &{$err_code}("Future switching between prepaid and post-paid billing profiles is not supported (" . $profile->name . ").",$billing_profiles_field); - } - } else { - $prepaid = $profile->prepaid; - } + #if (defined $prepaid) { + # if ($profile->prepaid != $prepaid) { + # return 0 unless &{$err_code}("Future switching between prepaid and post-paid billing profiles is not supported (" . $profile->name . ").",$billing_profiles_field); + # } + #} else { + # $prepaid = $profile->prepaid; + #} # TODO: what about changed product, do we allow it? #my $product_class = delete $mapping->{type}; diff --git a/lib/NGCP/Panel/Utils/ProfilePackages.pm b/lib/NGCP/Panel/Utils/ProfilePackages.pm index 7f58aff629..afa91626dd 100644 --- a/lib/NGCP/Panel/Utils/ProfilePackages.pm +++ b/lib/NGCP/Panel/Utils/ProfilePackages.pm @@ -1311,6 +1311,7 @@ sub prepare_package_profile_set { if (defined $reseller_id && defined $profile->reseller_id && $reseller_id != $profile->reseller_id) { #($profile->reseller_id // -1)) { return 0 unless &{$err_code}("The reseller of the profile package doesn't match the reseller of the billing profile (" . $profile->name . ").",$field); } + # for now we keep all profiles either postpaid or prepaid: if (defined $prepaid) { if ($profile->prepaid != $prepaid) { return 0 unless &{$err_code}("Mixing prepaid and post-paid billing profiles is not supported (" . $profile->name . ").",$field); diff --git a/lib/NGCP/Panel/Utils/SMS.pm b/lib/NGCP/Panel/Utils/SMS.pm index 2875c57be9..bc33e4c149 100644 --- a/lib/NGCP/Panel/Utils/SMS.pm +++ b/lib/NGCP/Panel/Utils/SMS.pm @@ -207,27 +207,12 @@ sub init_prepaid_billing { }; my ($prepaid_lib, $is_prepaid); - my $prepaid_pref_rs = NGCP::Panel::Utils::Preferences::get_dom_preference_rs( - c => $c, attribute => 'prepaid_library', - prov_domain => $prov_subscriber->domain, - ); - if($prepaid_pref_rs && $prepaid_pref_rs->first) { - $prepaid_lib = $prepaid_pref_rs->first->value; - } - - # todo: get prepaid flag from actual profile and use prepaid pref to override it, or designate the prepaid pref for sms only. - $prepaid_pref_rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs( - c => $c, attribute => 'prepaid', - prov_subscriber => $prov_subscriber, - ); - if($prepaid_pref_rs && $prepaid_pref_rs->first && $prepaid_pref_rs->first->value) { - $is_prepaid = 1; - } else { - $is_prepaid = 0; - } + my $bm_actual = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, contract => $prov_subscriber->contract, ); + $prepaid_lib = $bm_actual->billing_profile->prepaid_library if $bm_actual; + $is_prepaid = ($bm_actual->billing_profile->prepaid ? 1 : 0) if $bm_actual; # currently only inew rating supported, let others pass - unless ($is_prepaid && $prepaid_lib eq "libinewrate") { + unless ($is_prepaid && $prepaid_lib && $prepaid_lib eq "libinewrate") { $session->{reason} = 'not prepaid/libinewrate'; return $session; } diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index e83eeff525..0b68119d2b 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -186,24 +186,10 @@ sub get_provisoning_voip_subscriber_lock_level { sub switch_prepaid { my %params = @_; - # todo: drop switching the prepaid flag. - NGCP::Panel::Utils::Preferences::set_provisoning_voip_subscriber_first_int_attr_value(%params, - value => ($params{prepaid} ? 1 : 0), - attribute => 'prepaid' - ); - } sub switch_prepaid_contract { my %params = @_; - my $contract = $params{contract}; - - # todo: drop switching the prepaid flag. - 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); - } }