Remove noreseller hack.

Add proper create_reseller function for creating reseller contracts.
agranig/1_0_subfix
Andreas Granig 12 years ago
parent e4f8d7d047
commit fc45e11c49

@ -78,7 +78,7 @@ sub root :Chained('contract_list') :PathPart('') :Args(0) {
}
sub create :Chained('contract_list') :PathPart('create') :Args(0) {
my ($self, $c, $no_reseller) = @_;
my ($self, $c) = @_;
my $posted = ($c->request->method eq 'POST');
my $params = {};
@ -91,15 +91,11 @@ sub create :Chained('contract_list') :PathPart('create') :Args(0) {
item => $params
);
my $suffix = '';
if($c->user->is_superuser && $no_reseller) {
$suffix = '/noreseller';
}
NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => {'contact.create' => $c->uri_for('/contact/create'.$suffix),
'billing_profile.create' => $c->uri_for('/billing/create'.$suffix)},
fields => {'contact.create' => $c->uri_for('/contact/create'),
'billing_profile.create' => $c->uri_for('/billing/create')},
back_uri => $c->req->uri,
);
if($posted && $form->validated) {
@ -266,6 +262,13 @@ sub ajax :Chained('contract_list') :PathPart('ajax') :Args(0) {
sub peering_list :Chained('contract_list') :PathPart('peering') :CaptureArgs(0) {
my ($self, $c) = @_;
my $base_rs = $c->stash->{contract_select_rs};
my $rs = $base_rs->search({
'product.class' => 'sippeering',
}, {
'join' => {'billing_mappings' => 'product'},
});
$c->stash(ajax_uri => $c->uri_for_action("/contract/peering_ajax"));
}
@ -276,13 +279,6 @@ sub peering_root :Chained('peering_list') :PathPart('') :Args(0) {
sub peering_ajax :Chained('peering_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $base_rs = $c->stash->{contract_select_rs};
my $rs = $base_rs->search({
'product.class' => 'sippeering',
}, {
'join' => {'billing_mappings' => 'product'},
});
NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{contract_dt_columns});
$c->detach( $c->view("JSON") );
}
@ -346,6 +342,13 @@ sub peering_create :Chained('peering_list') :PathPart('create') :Args(0) {
sub customer_list :Chained('contract_list') :PathPart('customer') :CaptureArgs(0) {
my ($self, $c) = @_;
my $base_rs = $c->stash->{contract_select_rs};
my $rs = $base_rs->search({
'product_id' => undef,
}, {
'join' => {'billing_mappings' => 'product'},
});
$c->stash(ajax_uri => $c->uri_for_action("/contract/customer_ajax"));
}
@ -356,18 +359,89 @@ sub customer_root :Chained('customer_list') :PathPart('') :Args(0) {
sub customer_ajax :Chained('customer_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{contract_dt_columns});
$c->detach( $c->view("JSON") );
}
sub customer_create :Chained('customer_list') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
my $posted = ($c->request->method eq 'POST');
my $params = {};
$params = $params->merge($c->session->{created_objects});
my $form = NGCP::Panel::Form::Contract->new;
$form->process(
posted => $posted,
params => $c->request->params,
item => $params
);
NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => {'contact.create' => $c->uri_for('/contact/create'),
'billing_profile.create' => $c->uri_for('/billing/create')},
back_uri => $c->req->uri,
);
if($posted && $form->validated) {
try {
my $schema = $c->model('DB');
$schema->txn_do(sub {
$form->params->{contact_id} = $form->params->{contact}{id};
delete $form->params->{contract};
my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile};
my $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);
$contract->billing_mappings->create({
billing_profile_id => $bprof_id,
});
NGCP::Panel::Utils::Contract::create_contract_balance(
c => $c,
profile => $billing_profile,
contract => $contract,
);
$c->session->{created_objects}->{contract} = { id => $contract->id };
delete $c->session->{created_objects}->{contact};
delete $c->session->{created_objects}->{billing_profile};
$c->flash(messages => [{type => 'success', text => 'Contract successfully created'}]);
});
} catch($e) {
$c->log->error("Failed to create contract: $e");
$c->flash(messages => [{type => 'error', text => 'Failed to create contract'}]);
}
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/contract'));
}
$c->stash(create_flag => 1);
$c->stash(form => $form);
}
sub reseller_list :Chained('contract_list') :PathPart('reseller') :CaptureArgs(0) {
my ($self, $c) = @_;
my $base_rs = $c->stash->{contract_select_rs};
my $rs = $base_rs->search({
'product_id' => undef,
'product.class' => 'reseller',
}, {
'join' => {'billing_mappings' => 'product'},
});
$c->stash(ajax_uri => $c->uri_for_action("/contract/reseller_ajax"));
}
sub reseller_root :Chained('reseller_list') :PathPart('') :Args(0) {
}
sub reseller_ajax :Chained('reseller_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{contract_dt_columns});
$c->detach( $c->view("JSON") );
}
sub customer_create :Chained('customer_list') :PathPart('create') :Args(0) {
sub reseller_create :Chained('reseller_list') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
my $posted = ($c->request->method eq 'POST');
@ -382,8 +456,8 @@ sub customer_create :Chained('customer_list') :PathPart('create') :Args(0) {
NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => {'contact.create' => $c->uri_for('/contact/create'),
'billing_profile.create' => $c->uri_for('/billing/create')},
fields => {'contact.create' => $c->uri_for('/contact/create/noreseller'),
'billing_profile.create' => $c->uri_for('/billing/create/noreseller')},
back_uri => $c->req->uri,
);
if($posted && $form->validated) {
@ -396,8 +470,10 @@ sub customer_create :Chained('customer_list') :PathPart('create') :Args(0) {
delete $form->params->{billing_profile};
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' });
$contract->billing_mappings->create({
billing_profile_id => $bprof_id,
product_id => $product->id,
});
NGCP::Panel::Utils::Contract::create_contract_balance(

@ -74,7 +74,7 @@ sub create :Chained('list_reseller') :PathPart('create') :Args(0) {
NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => {'contract.create' => $c->uri_for('/contract/create/noreseller') },
fields => {'contract.create' => $c->uri_for('/contract/reseller/create') },
back_uri => $c->req->uri,
);

Loading…
Cancel
Save