MT#4289 separate customer-/contract- create and ajax_reseller_filter

Mantis: 4289#c25035
agranig/rest
Gerhard Jungwirth 12 years ago committed by Andreas Granig
parent 21482c00ec
commit 49037844bc

@ -386,104 +386,6 @@ sub customer_list :Chained('contract_list') :PathPart('customer') :CaptureArgs(0
$c->stash(ajax_uri => $c->uri_for_action("/customer/ajax"));
}
sub customer_ajax_reseller_filter :Chained('customer_list') :PathPart('ajax/reseller') :Args(1) {
my ($self, $c, $reseller_id) = @_;
unless($reseller_id && $reseller_id->is_int) {
$c->flash(messages => [{type => 'error', text => 'Invalid reseller id detected'}]);
$c->response->redirect($c->uri_for());
return;
}
my $rs = $c->stash->{customer_rs}->search_rs({
'contact.reseller_id' => $reseller_id,
},{
join => 'contact',
});
my $reseller_customer_columns = NGCP::Panel::Utils::Datatables::set_columns($c, [
{ name => "id", search => 1, title => "#" },
{ name => "external_id", search => 1, title => "External #" },
{ name => "billing_mappings.product.name", search => 1, title => "Product" },
{ name => "contact.email", search => 1, title => "Contact Email" },
{ name => "status", search => 1, title => "Status" },
]);
NGCP::Panel::Utils::Datatables::process($c, $rs, $reseller_customer_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 $form;
my $params = {};
$params = $params->merge($c->session->{created_objects});
if($c->config->{features}->{cloudpbx}) {
$form = NGCP::Panel::Form::Contract::ProductSelect->new;
} else {
$form = NGCP::Panel::Form::Contract::Basic->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->{contact};
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;
my $product_id = $form->params->{product}{id};
delete $form->params->{product};
unless($product_id) {
$product_id = $c->model('DB')->resultset('products')->find({ class => 'sipaccount' })->id;
}
unless($form->params->{max_subscribers} && length($form->params->{max_subscribers})) {
delete $form->params->{max_subscribers};
}
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,
product_id => $product_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};
my $contract_id = $contract->id;
$c->flash(messages => [{type => 'success', text => "Customer #$contract_id successfully created"}]);
});
} catch($e) {
NGCP::Panel::Utils::Message->error(
c => $c,
error => $e,
desc => "Failed to create customer contract.",
);
}
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/contract'));
}
$c->stash(create_flag => 1);
$c->stash(form => $form);
}
sub customer_base :Chained('customer_list') :PathPart('') :CaptureArgs(1) {
my ($self, $c, $contract_id) = @_;

@ -89,6 +89,103 @@ sub ajax :Chained('list_customer') :PathPart('ajax') :Args(0) {
$c->detach( $c->view("JSON") );
}
sub ajax_reseller_filter :Chained('list_customer') :PathPart('ajax/reseller') :Args(1) {
my ($self, $c, $reseller_id) = @_;
unless($reseller_id && $reseller_id->is_int) {
$c->flash(messages => [{type => 'error', text => 'Invalid reseller id detected'}]);
$c->response->redirect($c->uri_for());
return;
}
my $rs = $c->stash->{contract_select_rs}->search_rs({
'contact.reseller_id' => $reseller_id,
},{
join => 'contact',
});
my $reseller_customer_columns = NGCP::Panel::Utils::Datatables::set_columns($c, [
{ name => "id", search => 1, title => "#" },
{ name => "external_id", search => 1, title => "External #" },
{ name => "billing_mappings.product.name", search => 1, title => "Product" },
{ name => "contact.email", search => 1, title => "Contact Email" },
{ name => "status", search => 1, title => "Status" },
]);
NGCP::Panel::Utils::Datatables::process($c, $rs, $reseller_customer_columns);
$c->detach( $c->view("JSON") );
}
sub create :Chained('list_customer') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
my $posted = ($c->request->method eq 'POST');
my $form;
my $params = {};
$params = $params->merge($c->session->{created_objects});
if($c->config->{features}->{cloudpbx}) {
$form = NGCP::Panel::Form::Contract::ProductSelect->new;
} else {
$form = NGCP::Panel::Form::Contract::Basic->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->{contact};
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;
my $product_id = $form->params->{product}{id};
delete $form->params->{product};
unless($product_id) {
$product_id = $c->model('DB')->resultset('products')->find({ class => 'sipaccount' })->id;
}
unless($form->params->{max_subscribers} && length($form->params->{max_subscribers})) {
delete $form->params->{max_subscribers};
}
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,
product_id => $product_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};
my $contract_id = $contract->id;
$c->flash(messages => [{type => 'success', text => "Customer #$contract_id successfully created"}]);
});
} catch($e) {
NGCP::Panel::Utils::Message->error(
c => $c,
error => $e,
desc => "Failed to create customer contract.",
);
}
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/contract'));
}
$c->stash(create_flag => 1);
$c->stash(form => $form);
}
sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
my ($self, $c, $contract_id) = @_;

@ -235,7 +235,7 @@ sub create :Chained('sets_list') :PathPart('create') :Args(0) {
form => $form,
fields => {
'reseller.create' => $c->uri_for('/reseller/create'),
'contract.create' => $c->uri_for_action('/contract/customer_create'),
'contract.create' => $c->uri_for_action('/customer/create'),
},
back_uri => $c->req->uri,
);

@ -132,7 +132,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) :Does(ACL) :AC
fields => {
'domain.create' => $c->uri_for('/domain/create'),
'reseller.create' => $c->uri_for('/reseller/create'),
'contract.create' => $c->uri_for('/contract/customer/create'),
'contract.create' => $c->uri_for('/customer/create'),
},
back_uri => $c->req->uri,
);

@ -1,6 +1,6 @@
[% META title = 'Customers' -%]
[%
helper.name = 'Customers';
helper.name = 'Customer';
helper.data = contracts;
helper.messages = messages;
helper.dt_columns = contract_dt_columns;
@ -19,7 +19,7 @@
{ name = 'Details', uri = "/customer/'+full.id+'/details", class = 'btn-small btn-tertiary', icon = 'icon-list' },
];
helper.top_buttons = [
{ name = 'Create Customer', uri = c.uri_for_action('/contract/customer_create'), icon = 'icon-star' },
{ name = 'Create Customer', uri = c.uri_for_action('/customer/create'), icon = 'icon-star' },
];
ELSE;
helper.dt_buttons = [

@ -195,7 +195,7 @@
helper.create_flag = create_flag;
helper.edit_flag = edit_flag;
helper.form_object = form;
helper.ajax_uri = c.uri_for_action('/contract/customer_ajax_reseller_filter', c.req.captures );
helper.ajax_uri = c.uri_for_action('/customer/ajax_reseller_filter', c.req.captures );
UNLESS c.user.read_only;
helper.dt_buttons = [

Loading…
Cancel
Save