TT#42260 remove prepaid and prepaid_library pref usage

Change-Id: Iebd75291f0648ea054b82ace4251b1a98e629198
changes/51/22751/5
Rene Krenn 8 years ago
parent 1f75abe1a6
commit 7d045b9ffc

@ -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 };

@ -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

@ -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

@ -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

@ -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);

@ -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},

@ -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'
);
}
}
}
}

@ -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};

@ -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);

@ -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;
}

@ -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);
}
}

Loading…
Cancel
Save