From 35776406a9d3bdff6e96c1777dc52bfb45769891 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Thu, 6 Jun 2013 10:03:05 +0200 Subject: [PATCH] Correct management of billing_mappings * When session->{create_peering_contract} is set, set the corresponding product (sippeering). * When changing the billing_profile create a new billing_mapping with the start_date of now. * Preselect the correct billing_mapping on the edit modal-dialog. --- lib/NGCP/Panel/Controller/Contract.pm | 30 +++++++++++++++++++++------ lib/NGCP/Panel/Controller/Peering.pm | 14 +++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Contract.pm b/lib/NGCP/Panel/Controller/Contract.pm index 3a5c01c73b..b21efede71 100644 --- a/lib/NGCP/Panel/Controller/Contract.pm +++ b/lib/NGCP/Panel/Controller/Contract.pm @@ -47,13 +47,20 @@ sub root :Chained('contract_list') :PathPart('') :Args(0) { sub create :Chained('contract_list') :PathPart('create') :Args(0) { my ($self, $c) = @_; + + my $item = $c->model('billing')->resultset('billing_mappings')->new_result({}); + if($c->session->{create_peering_contract}){ + $item->product( + $c->model('billing')->resultset('products')->find({class => 'sippeering'}) + ); + } my $form = NGCP::Panel::Form::Contract->new; $form->process( posted => ($c->request->method eq 'POST'), params => $c->request->params, action => $c->uri_for('create'), - item => $c->model('billing')->resultset('billing_mappings')->new_result({}), + item => $item, ); return if NGCP::Panel::Utils::check_form_buttons( c => $c, form => $form, fields => [qw/contact.create/], @@ -61,6 +68,7 @@ sub create :Chained('contract_list') :PathPart('create') :Args(0) { ); if($form->validated) { $c->flash(messages => [{type => 'success', text => 'Contract successfully created!'}]); + $c->session(create_peering_contract => 0); if($c->stash->{close_target}) { $c->response->redirect($c->stash->{close_target}); @@ -84,11 +92,10 @@ sub base :Chained('contract_list') :PathPart('') :CaptureArgs(1) { return; } - my $res = $c->model('billing')->resultset('contracts') + my $res = $c->stash->{contract_select_rs} ->search(undef, { - 'join' => 'billing_mappings', - '+select' => 'billing_mappings.billing_profile_id', - '+as' => 'billing_profile', + '+select' => 'billing_mappings.id', + '+as' => 'bmid', }) ->find($contract_id); @@ -108,11 +115,22 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) { my ($self, $c) = @_; my $posted = ($c->request->method eq 'POST'); + + my $contr = $c->stash->{contract_result}; + my $item = $contr->billing_mappings->find($contr->get_column('bmid')); + if ($posted) { + if($item->billing_profile_id != $c->req->params->{'billing_profile.id'}) { + $item = $c->stash->{contract_result}->billing_mappings->new_result({}); + $item->start_date(time); + } + } else { + } + my $form = NGCP::Panel::Form::Contract->new; $form->process( posted => $posted, params => $c->req->params, - item => $c->stash->{contract_result}->billing_mappings->first, + item => $item, action => $c->uri_for($c->stash->{contract}->{id}, 'edit'), ); return if NGCP::Panel::Utils::check_form_buttons( diff --git a/lib/NGCP/Panel/Controller/Peering.pm b/lib/NGCP/Panel/Controller/Peering.pm index d5e9d995d3..bf20f53911 100644 --- a/lib/NGCP/Panel/Controller/Peering.pm +++ b/lib/NGCP/Panel/Controller/Peering.pm @@ -67,10 +67,13 @@ sub edit :Chained('base') :PathPart('edit') { params => $posted ? $c->request->params : $c->stash->{group}, action => $c->uri_for_action('/peering/edit', [$c->req->captures->[0]]) ); - return if NGCP::Panel::Utils::check_form_buttons( + if (NGCP::Panel::Utils::check_form_buttons( c => $c, form => $form, fields => [qw/contract.create/], back_uri => $c->req->uri, - ); + )) { + $c->session(create_peering_contract => 1); + return; + } if($posted && $form->validated) { try { $c->stash->{group_result}->update($form->custom_get_values); @@ -109,10 +112,13 @@ sub create :Chained('group_list') :PathPart('create') :Args(0) { params => $c->request->params, action => $c->uri_for('create'), ); - return if NGCP::Panel::Utils::check_form_buttons( + if (NGCP::Panel::Utils::check_form_buttons( c => $c, form => $form, fields => [qw/contract.create/], back_uri => $c->req->uri, - ); + )) { + $c->session(create_peering_contract => 1); + return; + } if($form->validated) { my $formdata = $form->custom_get_values; try {