diff --git a/lib/NGCP/Panel/Form/CustomerFraudPreferences/PreferencesAPI.pm b/lib/NGCP/Panel/Form/CustomerFraudPreferences/PreferencesAPI.pm index c808eb8813..267abeedb4 100644 --- a/lib/NGCP/Panel/Form/CustomerFraudPreferences/PreferencesAPI.pm +++ b/lib/NGCP/Panel/Form/CustomerFraudPreferences/PreferencesAPI.pm @@ -3,14 +3,44 @@ use HTML::FormHandler::Moose; use HTML::FormHandler::Widget::Block::Bootstrap; extends 'HTML::FormHandler'; +has_field 'current_fraud_interval_source' => ( + required => 0, + type => 'Select', + label => 'Fraud preferences interval source (customer or billing_profile)', + options => [ + { value => 'customer', label => 'Customer' }, + { value => 'billng_profile', label => 'Billing Profile' }, + ], +); + has_field 'fraud_interval_limit' => ( type => 'Integer', - label => 'Fraud detection threshold per month in cents.', + label => 'Fraud detection threshold per month in cents', +); + +has_field 'current_fraud_interval_limit' => ( + type => 'Integer', + required => 0, + label => 'Current fraud detection threshold per month in cents', ); has_field 'fraud_interval_lock' => ( type => 'Select', - label => 'Lock Level', + label => 'Lock level', + options => [ + { value => 0, label => 'none' }, + { value => 1, label => 'foreign calls' }, + { value => 2, label => 'all outgoing calls' }, + { value => 3, label => 'incoming and outgoing' }, + { value => 4, label => 'global (including CSC)' }, + { value => 5, label => 'ported (call forwarding only)' }, + ], +); + +has_field 'current_fraud_interval_lock' => ( + type => 'Select', + required => 0, + label => 'Current lock level', options => [ { value => 0, label => 'none' }, { value => 1, label => 'foreign calls' }, @@ -24,17 +54,53 @@ has_field 'fraud_interval_lock' => ( has_field 'fraud_interval_notify' => ( type => '+NGCP::Panel::Field::EmailList', maxlength => 255, - label => 'Comma-separated list of e-mail addresses for notification.' + label => 'Comma-separated list of e-mail addresses for notification' +); + +has_field 'current_fraud_interval_notify' => ( + type => '+NGCP::Panel::Field::EmailList', + required => 0, + maxlength => 255, + label => 'Current comma-separated list of e-mail addresses for notification' +); + +has_field 'current_fraud_daily_source' => ( + required => 0, + type => 'Select', + label => 'Fraud daily preferences source (customer or billing_profile)', + options => [ + { value => 'customer', label => 'Customer' }, + { value => 'billng_profile', label => 'Billing Profile' }, + ], ); has_field 'fraud_daily_limit' => ( type => 'Integer', - label => 'Fraud detection threshold per day in cents.', + label => 'Fraud detection threshold per day in cents', +); + +has_field 'current_fraud_daily_limit' => ( + type => 'Integer', + label => 'Current fraud detection threshold per day in cents', ); has_field 'fraud_daily_lock' => ( type => 'Select', - label => 'Lock Level', + label => 'Daily lock level', + options => [ + { value => 0, label => 'none' }, + { value => 1, label => 'foreign calls' }, + { value => 2, label => 'all outgoing calls' }, + { value => 3, label => 'incoming and outgoing' }, + { value => 4, label => 'global (including CSC)' }, + { value => 5, label => 'ported (call forwarding only)' }, + ], +); + +has_field 'current_fraud_daily_lock' => ( + type => 'Select', + required => 0, + label => 'Current daily lock level', options => [ { value => 0, label => 'none' }, { value => 1, label => 'foreign calls' }, @@ -48,7 +114,14 @@ has_field 'fraud_daily_lock' => ( has_field 'fraud_daily_notify' => ( type => '+NGCP::Panel::Field::EmailList', maxlength => 255, - label => 'Comma-separated list of e-mail addresses for notification.' + label => 'Comma-separated list of e-mail addresses for notification' +); + +has_field 'current_fraud_daily_notify' => ( + type => '+NGCP::Panel::Field::EmailList', + required => 0, + maxlength => 255, + label => 'Current comma-separated list of e-mail addresses for notification' ); 1; diff --git a/lib/NGCP/Panel/Role/API/CustomerFraudPreferences.pm b/lib/NGCP/Panel/Role/API/CustomerFraudPreferences.pm index bb58d25d10..c744310304 100644 --- a/lib/NGCP/Panel/Role/API/CustomerFraudPreferences.pm +++ b/lib/NGCP/Panel/Role/API/CustomerFraudPreferences.pm @@ -57,14 +57,19 @@ sub resource_from_item { my ($self, $c, $customer, $form) = @_; my $item = $customer->contract_fraud_preference; + my $bp_item = $customer->actual_billing_profile->billing_profile; my $resource; - if ($item) { - $resource = { $item->get_inflated_columns }; + + my ($prefs, $bp_prefs); + $bp_prefs = { $bp_item->get_inflated_columns }; + $prefs = $item ? { $item->get_inflated_columns } : undef; + + if ($prefs) { + $resource = $prefs; delete $resource->{contract_id}; delete $resource->{id}; } else { $resource = { - #contract_id => $customer->id, fraud_interval_limit => undef, fraud_interval_lock => undef, fraud_interval_notify => undef, @@ -73,6 +78,23 @@ sub resource_from_item { fraud_daily_notify => undef, } } + + foreach my $type (qw(interval daily)) { + my $prefix = 'fraud_'.$type.'_'; + my $c_prefix = 'current_fraud_'.$type.'_'; + $resource->{$c_prefix.'source'} = + $prefs && $prefs->{$prefix.'limit'} + ? 'customer' + : 'billing_profile'; + my $sel_prefs = + $resource->{$c_prefix.'source'} eq 'customer' + ? $prefs + : $bp_prefs; + map { + $resource->{$c_prefix.$_} = $sel_prefs->{$prefix.$_} + } qw(limit lock notify); + } + return $resource; }