MT#9167 Fix setting contract timestamps

changes/94/294/1
Andreas Granig 11 years ago
parent 51e7c5fb93
commit d156577873

@ -209,7 +209,10 @@ sub terminate :Chained('base') :PathPart('terminate') :Args(0) {
try { try {
my $old_status = $contract->status; 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'); my $schema = $c->model('DB');
$schema->txn_do(sub { $schema->txn_do(sub {
$contract->voip_contract_preferences->delete; $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}; my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile}; delete $form->params->{billing_profile};
$form->params->{external_id} = $form->field('external_id')->value; $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 $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id); my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);
my $product = $schema->resultset('products')->find({ class => 'sippeering' }); 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}; my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile}; delete $form->params->{billing_profile};
$form->params->{external_id} = $form->field('external_id')->value; $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 $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id); my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);
my $product = $schema->resultset('products')->find({ class => 'reseller' }); my $product = $schema->resultset('products')->find({ class => 'reseller' });

@ -140,7 +140,7 @@ sub create :Chained('list_customer') :PathPart('create') :Args(0) {
} }
my $bprof_id = $form->params->{billing_profile}{id}; my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile}; 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; $form->params->{external_id} = $form->field('external_id')->value;
my $product_id = $form->params->{product}{id}; my $product_id = $form->params->{product}{id};
delete $form->params->{product}; delete $form->params->{product};
@ -516,7 +516,10 @@ sub terminate :Chained('base') :PathPart('terminate') :Args(0) {
my $schema = $c->model('DB'); my $schema = $c->model('DB');
$schema->txn_do(sub { $schema->txn_do(sub {
$contract->voip_contract_preferences->delete; $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 status changed, populate it down the chain
if($contract->status ne $old_status) { if($contract->status ne $old_status) {
NGCP::Panel::Utils::Contract::recursively_lock_contract( NGCP::Panel::Utils::Contract::recursively_lock_contract(

@ -157,6 +157,9 @@ sub update_contract {
return; return;
} }
} }
if($resource->{status} eq "terminated") {
$resource->{terminate_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
}
$contract->update($resource); $contract->update($resource);

@ -223,6 +223,9 @@ sub update_customer {
} }
my $old_ext_id = $customer->external_id // ''; my $old_ext_id = $customer->external_id // '';
if($resource->{status} eq "terminated") {
$resource->{terminate_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
}
$customer->update($resource); $customer->update($resource);

@ -171,8 +171,11 @@ sub recursively_lock_contract {
}, { }, {
join => 'contact', join => 'contact',
}); });
my $data = { status => $status };
$data->{terminate_timestamp} = NGCP::Panel::Utils::DateTime::current_local
if($status eq 'terminated');
for my $customer($customers->all) { for my $customer($customers->all) {
$customer->update({ status => $status }); $customer->update($data);
for my $subscriber($customer->voip_subscribers->all) { for my $subscriber($customer->voip_subscribers->all) {
$subscriber->update({ status => $status }); $subscriber->update({ status => $status });
if($status eq 'terminated') { if($status eq 'terminated') {

Loading…
Cancel
Save