From c6abfbc7cb78b81ada25870e4bcf023990aaa64a Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Fri, 20 Sep 2013 11:30:19 +0200 Subject: [PATCH] Correctly select customers under reseller-> customers section Only show the most applicable billing_profile using the complex query from the Contract controller Mantis: 3855 --- lib/NGCP/Panel/Controller/Contract.pm | 25 +++++++++++++++++++++++++ lib/NGCP/Panel/Controller/Reseller.pm | 18 ------------------ share/templates/reseller/details.tt | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Contract.pm b/lib/NGCP/Panel/Controller/Contract.pm index ae7778bbe5..f044f93988 100644 --- a/lib/NGCP/Panel/Controller/Contract.pm +++ b/lib/NGCP/Panel/Controller/Contract.pm @@ -377,6 +377,31 @@ sub customer_ajax :Chained('customer_list') :PathPart('ajax') :Args(0) { $c->detach( $c->view("JSON") ); } +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) = @_; diff --git a/lib/NGCP/Panel/Controller/Reseller.pm b/lib/NGCP/Panel/Controller/Reseller.pm index b9baf12d8a..fa622d8289 100644 --- a/lib/NGCP/Panel/Controller/Reseller.pm +++ b/lib/NGCP/Panel/Controller/Reseller.pm @@ -185,24 +185,6 @@ sub reseller_admin :Chained('base') :PathPart('admins/ajax') :Args(0) { return; } -sub reseller_customers :Chained('base') :PathPart('customers/ajax') :Args(0) { - my ($self, $c) = @_; - - my $rs = $c->model('DB')->resultset('contracts')->search({ - 'contact.reseller_id' => $c->stash->{reseller}->first->id, - 'me.status' => { '!=' => 'terminated' }, - '-or' => [ - 'product.class' => 'sipaccount', - 'product.class' => 'pbxaccount', - ], - }, { - join => [ {'billing_mappings' => 'product' }, 'contact'], - }); - NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{customer_dt_columns}); - $c->detach($c->view('JSON')); - return; -} - sub edit :Chained('base') :PathPart('edit') :Args(0) { my ($self, $c) = @_; diff --git a/share/templates/reseller/details.tt b/share/templates/reseller/details.tt index a58cf73033..0cfe4ca9ea 100644 --- a/share/templates/reseller/details.tt +++ b/share/templates/reseller/details.tt @@ -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('/reseller/reseller_customers', c.req.captures ); + helper.ajax_uri = c.uri_for_action('/contract/customer_ajax_reseller_filter', c.req.captures ); UNLESS c.user.read_only; helper.dt_buttons = [