diff --git a/lib/NGCP/Panel/Controller/Contract.pm b/lib/NGCP/Panel/Controller/Contract.pm index fc0e11f70b..00a2c5a56e 100644 --- a/lib/NGCP/Panel/Controller/Contract.pm +++ b/lib/NGCP/Panel/Controller/Contract.pm @@ -209,7 +209,10 @@ sub terminate :Chained('base') :PathPart('terminate') :Args(0) { try { my $old_status = $contract->status; - $contract->update({ status => 'terminated' }); + $contract->update({ + status => 'terminated', + terminate_timestamp => NGCP::Panel::Utils::DateTime::current_local, + }); my $schema = $c->model('DB'); $schema->txn_do(sub { $contract->voip_contract_preferences->delete; @@ -300,7 +303,7 @@ sub peering_create :Chained('peering_list') :PathPart('create') :Args(0) { my $bprof_id = $form->params->{billing_profile}{id}; delete $form->params->{billing_profile}; $form->params->{external_id} = $form->field('external_id')->value; - $form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local; + $form->params->{create_timestamp} = $form->params->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local; my $contract = $schema->resultset('contracts')->create($form->params); my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id); my $product = $schema->resultset('products')->find({ class => 'sippeering' }); @@ -428,7 +431,7 @@ sub reseller_create :Chained('reseller_list') :PathPart('create') :Args(0) { my $bprof_id = $form->params->{billing_profile}{id}; delete $form->params->{billing_profile}; $form->params->{external_id} = $form->field('external_id')->value; - $form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local; + $form->params->{create_timestamp} = $form->params->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local; my $contract = $schema->resultset('contracts')->create($form->params); my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id); my $product = $schema->resultset('products')->find({ class => 'reseller' }); diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index 41252a3458..13d6a7a836 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -140,7 +140,7 @@ sub create :Chained('list_customer') :PathPart('create') :Args(0) { } my $bprof_id = $form->params->{billing_profile}{id}; delete $form->params->{billing_profile}; - $form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local; + $form->params->{create_timestamp} = $form->params->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local; $form->params->{external_id} = $form->field('external_id')->value; my $product_id = $form->params->{product}{id}; delete $form->params->{product}; @@ -516,7 +516,10 @@ sub terminate :Chained('base') :PathPart('terminate') :Args(0) { my $schema = $c->model('DB'); $schema->txn_do(sub { $contract->voip_contract_preferences->delete; - $contract->update({ status => 'terminated' }); + $contract->update({ + status => 'terminated', + terminate_timestamp => NGCP::Panel::Utils::DateTime::current_local, + }); # if status changed, populate it down the chain if($contract->status ne $old_status) { NGCP::Panel::Utils::Contract::recursively_lock_contract( diff --git a/lib/NGCP/Panel/Role/API/Contracts.pm b/lib/NGCP/Panel/Role/API/Contracts.pm index 7cc2e7c6d1..d7457deac4 100644 --- a/lib/NGCP/Panel/Role/API/Contracts.pm +++ b/lib/NGCP/Panel/Role/API/Contracts.pm @@ -157,6 +157,9 @@ sub update_contract { return; } } + if($resource->{status} eq "terminated") { + $resource->{terminate_timestamp} = NGCP::Panel::Utils::DateTime::current_local; + } $contract->update($resource); diff --git a/lib/NGCP/Panel/Role/API/Customers.pm b/lib/NGCP/Panel/Role/API/Customers.pm index 5424b6ef59..58a6c77f4b 100644 --- a/lib/NGCP/Panel/Role/API/Customers.pm +++ b/lib/NGCP/Panel/Role/API/Customers.pm @@ -223,6 +223,9 @@ sub update_customer { } my $old_ext_id = $customer->external_id // ''; + if($resource->{status} eq "terminated") { + $resource->{terminate_timestamp} = NGCP::Panel::Utils::DateTime::current_local; + } $customer->update($resource); diff --git a/lib/NGCP/Panel/Utils/Contract.pm b/lib/NGCP/Panel/Utils/Contract.pm index 4279e0f57b..330d42fa90 100644 --- a/lib/NGCP/Panel/Utils/Contract.pm +++ b/lib/NGCP/Panel/Utils/Contract.pm @@ -171,8 +171,11 @@ sub recursively_lock_contract { }, { join => 'contact', }); + my $data = { status => $status }; + $data->{terminate_timestamp} = NGCP::Panel::Utils::DateTime::current_local + if($status eq 'terminated'); for my $customer($customers->all) { - $customer->update({ status => $status }); + $customer->update($data); for my $subscriber($customer->voip_subscribers->all) { $subscriber->update({ status => $status }); if($status eq 'terminated') {