MT#8645 - add billing_profile terminate functionality for API

changes/52/552/1
Kirill Solomko 11 years ago
parent 64dd9c01e2
commit fd8d5974d4

@ -18,7 +18,8 @@ has_block 'fields' => (
render_list => [qw/reseller handle name prepaid 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
currency id/],
currency id
status/],
);

@ -148,6 +148,14 @@ has_field 'currency' => (
},
);
has_field 'status' => (
type => 'Hidden',
options => [
{ label => 'active', value => 'active' },
{ label => 'terminated', value => 'terminated' },
],
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
@ -161,7 +169,8 @@ has_block 'fields' => (
render_list => [qw/handle name prepaid 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
currency id/],
currency id
status/],
);
has_block 'actions' => (

@ -20,11 +20,21 @@ sub item_rs {
my ($self, $c) = @_;
my $item_rs = $c->model('DB')->resultset('billing_profiles');
my $search_xtra = {
join => { 'billing_mappings' => 'contract_active' },
'+select' => { count => 'contract_active.status', -as => 'used' },
'group_by' => [ qw(me.id) ] };
if($c->user->roles eq "admin") {
$item_rs = $item_rs->search({ 'me.status' => { '!=' => 'terminated' } },
$search_xtra);
} elsif($c->user->roles eq "reseller") {
$item_rs = $item_rs->search({ reseller_id => $c->user->reseller_id });
$item_rs = $item_rs->search({ reseller_id => $c->user->reseller_id,
'me.status' => { '!=' => 'terminated' } },
$search_xtra);
} else {
$item_rs = $item_rs->search({ reseller_id => $c->user->contract->contact->reseller_id});
$item_rs = $item_rs->search({ reseller_id => $c->user->contract->contact->reseller_id,
'me.status' => { '!=' => 'terminated' } },
$search_xtra);
}
return $item_rs;
}
@ -101,6 +111,17 @@ sub update_profile {
}
}
if(exists $resource->{status} && $resource->{status} eq 'terminated') {
my $profile_used = {$profile->get_inflated_columns}->{used};
if ($profile_used) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY,
"Cannnot terminate billing_profile that is used (count: $profile_used)");
return;
} else {
$resource->{terminate_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
}
}
my $old_prepaid = $profile->prepaid;
$profile->update($resource);

Loading…
Cancel
Save