From 74ae3d91d3d7b42925fbd8ff319527a77016de2b Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Fri, 5 Jul 2013 15:36:47 +0200 Subject: [PATCH] Add customer list to reseller details. --- lib/NGCP/Panel/Controller/Contract.pm | 4 ++-- lib/NGCP/Panel/Controller/Customer.pm | 21 +++++++++++-------- lib/NGCP/Panel/Controller/Reseller.pm | 16 ++++++++++++++ share/templates/contract/list.tt | 4 ++-- share/templates/customer/details.tt | 20 +++++------------- share/templates/reseller/details.tt | 30 +++++++++++++++++++++++++++ 6 files changed, 67 insertions(+), 28 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Contract.pm b/lib/NGCP/Panel/Controller/Contract.pm index 5db74d0247..4196a8cbcd 100644 --- a/lib/NGCP/Panel/Controller/Contract.pm +++ b/lib/NGCP/Panel/Controller/Contract.pm @@ -200,7 +200,7 @@ sub ajax :Chained('contract_list') :PathPart('ajax') :Args(0) { my $rs = $c->stash->{contract_select_rs}; $c->forward( "/ajax_process_resultset", [$rs, - ["id","contact_id","billing_profile_name","status"], + ["id", "contact_id", "billing_profile_name", "billing_profile_id", "status"], ["billing_profile.name", "status"]]); $c->detach( $c->view("JSON") ); @@ -311,7 +311,7 @@ sub customer_ajax :Chained('customer_list') :PathPart('ajax') :Args(0) { }); $c->forward( "/ajax_process_resultset", [$rs, - ["id","contact_id","billing_profile_id", "billing_profile_name","status"], + ["id","contact_id", "billing_profile_id", "billing_profile_name","status"], ["billing_profile.name", "status"]]); $c->detach( $c->view("JSON") ); diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index b61da5744a..6d13b4487b 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -8,8 +8,6 @@ use NGCP::Panel::Form::CustomerDailyFraud; use NGCP::Panel::Form::CustomerBalance; use NGCP::Panel::Utils; -use Data::Printer; - =head1 NAME NGCP::Panel::Controller::Customer - Catalyst Controller @@ -51,11 +49,11 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) { } my $contract = $c->model('billing')->resultset('contracts') - ->find($contract_id); + ->search_rs(id => $contract_id); my $stime = DateTime->now->truncate(to => 'month'); my $etime = $stime->clone->add(months => 1); - my $balance = $contract->contract_balances + my $balance = $contract->first->contract_balances ->find({ start => { '>=' => $stime }, end => { '<' => $etime }, @@ -64,7 +62,7 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) { try { NGCP::Panel::Utils::Contract::create_contract_balance( c => $c, - profile => $contract->billing_mappings->search({ + profile => $contract->first->billing_mappings->search({ -and => [ -or => [ start_date => undef, @@ -79,7 +77,7 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) { { order_by => { -desc => 'start_time', -desc => 'id' } })->first->billing_profile, - contract => $contract, + contract => $contract->first, ); } catch($e) { $c->log->error("Failed to create contract balance: $e"); @@ -87,7 +85,7 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) { $c->response->redirect($c->uri_for()); return; } - $balance = $contract->contract_balances + $balance = $contract->first->contract_balances ->find({ start => { '>=' => $stime }, end => { '<' => $etime }, @@ -95,13 +93,18 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) { } $c->stash(balance => $balance); - $c->stash(fraud => $contract->contract_fraud_preference); + $c->stash(fraud => $contract->first->contract_fraud_preference); $c->stash(template => 'customer/details.tt'); - $c->stash(contract => $contract); + $c->stash(contract => $contract->first); + $c->stash(contract_rs => $contract); } sub details :Chained('base') :PathPart('details') :Args(0) { my ($self, $c) = @_; + + $c->stash( + subscribers => $c->stash->{contract}->voip_subscribers, + ); } sub edit_fraud :Chained('base') :PathPart('fraud/edit') :Args(1) { diff --git a/lib/NGCP/Panel/Controller/Reseller.pm b/lib/NGCP/Panel/Controller/Reseller.pm index 682bde2892..4dac2b9b7d 100644 --- a/lib/NGCP/Panel/Controller/Reseller.pm +++ b/lib/NGCP/Panel/Controller/Reseller.pm @@ -150,6 +150,22 @@ sub reseller_admin :Chained('base') :PathPart('admins') :Args(0) { return; } +sub reseller_customers :Chained('base') :PathPart('customers') :Args(0) +{ + my ($self, $c) = @_; + + $c->forward( + '/ajax_process_resultset', [ + $c->stash->{reseller}->first->search_related_rs('contracts'), + # TODO: also external_id (same in Customer list) + [qw(id contact_id status)], + [ "contact_id", "status" ] + ] + ); + $c->detach($c->view('JSON')); + return; +} + sub edit :Chained('base') :PathPart('edit') :Args(0) { my ($self, $c) = @_; diff --git a/share/templates/contract/list.tt b/share/templates/contract/list.tt index 021257c369..58f3f93ed3 100644 --- a/share/templates/contract/list.tt +++ b/share/templates/contract/list.tt @@ -4,8 +4,8 @@ helper.show_create_button = 1; helper.data = contracts; helper.messages = messages; - helper.column_titles = [ '#', 'Contact #', 'Billing Profile #', 'Status' ]; - helper.column_fields = [ 'id', 'contact_id', 'billing_profile_id', 'status' ]; + helper.column_titles = [ '#', 'Contact #', 'Billing Profile', 'Status' ]; + helper.column_fields = [ 'id', 'contact_id', 'billing_profile_name', 'status' ]; helper.close_target = close_target; helper.create_flag = create_flag; diff --git a/share/templates/customer/details.tt b/share/templates/customer/details.tt index 0eed5cd1dd..3357bef3b3 100644 --- a/share/templates/customer/details.tt +++ b/share/templates/customer/details.tt @@ -40,24 +40,14 @@ + [% FOR subscriber IN subscribers -%] - testuser1@example.org - 4312345 - Fooagent 1/0 something very long in version 20130702 foooooooooo - - - - testuser2@example.org - 4312346 - Fooagent 1/0 something very long in version 20130702 foooooooooo - - - - testuser1@example.org - 4312345 - Baragent + [% subscriber.username %]@[% subscriber.domain.domain %] + [% subscriber.primary_number.cc %] [% subscriber.primary_number.ac %] [% subscriber.primary_number.sn %] + TODO[% # subscriber.provisioning_voip_subscriber.password %] + [% END -%] diff --git a/share/templates/reseller/details.tt b/share/templates/reseller/details.tt index 8f40894d56..da3670ba3d 100644 --- a/share/templates/reseller/details.tt +++ b/share/templates/reseller/details.tt @@ -110,6 +110,36 @@ helper.ajax_uri = c.uri_for_action('/reseller/reseller_admin', c.req.captures ); helper.base_uri = c.uri_for_action('/administrator/root'); + PROCESS 'helpers/datatables.tt'; +-%] + + + +
+
+ Customers +
+
+
+[% + helper.name = 'Customer'; + helper.messages = messages; + helper.column_titles = [ '#', 'Contact #', 'Status' ]; + helper.column_fields = [ 'id', 'contact_id', 'status' ]; + helper.paginate = 'true'; + helper.filter = 'true'; + helper.close_target = close_target; + 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.dt_buttons = [ + { name = 'Edit', uri = "/contract/'+full[\"id\"]+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' }, + { name = 'Delete', uri = "/contract/'+full[\"id\"]+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' }, + { name = 'Details', uri = "/customer/'+full[\"id\"]+'/details", class = 'btn-small btn-tertiary', icon = 'icon-list' }, + ]; + PROCESS 'helpers/datatables.tt'; -%]