From 761aab32203845bacc0a60079d3171a5e2cb0dd9 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Thu, 4 Jul 2013 12:16:25 +0200 Subject: [PATCH] Implement reseller and billing widget for admins. --- lib/NGCP/Panel/Controller/Contact.pm | 8 ++--- lib/NGCP/Panel/Controller/Contract.pm | 4 +-- lib/NGCP/Panel/Field/Contract.pm | 2 +- .../Widget/Plugin/AdminBillingOverview.pm | 33 ++++++++++++++++++- .../Widget/Plugin/AdminResellerOverview.pm | 11 ++++++- share/templates/contract/list.tt | 2 +- share/templates/peering/list.tt | 1 - share/templates/reseller/details.tt | 1 + .../widgets/admin_billing_overview.tt | 7 ++-- .../widgets/admin_reseller_overview.tt | 8 ++--- 10 files changed, 59 insertions(+), 18 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Contact.pm b/lib/NGCP/Panel/Controller/Contact.pm index 8e14f86a23..0b0b7a6f84 100644 --- a/lib/NGCP/Panel/Controller/Contact.pm +++ b/lib/NGCP/Panel/Controller/Contact.pm @@ -125,11 +125,11 @@ sub ajax :Chained('list') :PathPart('ajax') :Args(0) { #TODO: when user is not logged in, this gets forwarded to login page - my $contacts = $c->stash->{contacts}; + my $contacts = $c->model('billing')->resultset('contacts')->search_rs({}); - $c->forward( "/ajax_process", [$contacts, - ["id","firstname","lastname","email"], - [1,2,3]]); + $c->forward( "/ajax_process_resultset", [$contacts, + ["id", "firstname", "lastname", "email"], + ["firstname", "lastname", "email"]]); $c->detach( $c->view("JSON") ); } diff --git a/lib/NGCP/Panel/Controller/Contract.pm b/lib/NGCP/Panel/Controller/Contract.pm index c8ac36ca0c..5db74d0247 100644 --- a/lib/NGCP/Panel/Controller/Contract.pm +++ b/lib/NGCP/Panel/Controller/Contract.pm @@ -227,7 +227,7 @@ sub peering_ajax :Chained('peering_list') :PathPart('ajax') :Args(0) { }); $c->forward( "/ajax_process_resultset", [$rs, - ["id","contact_id","billing_profile_name","status"], + ["id","contact_id","billing_profile_id", "billing_profile_name","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_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/Field/Contract.pm b/lib/NGCP/Panel/Field/Contract.pm index 7789843a36..9dd7d15ce1 100644 --- a/lib/NGCP/Panel/Field/Contract.pm +++ b/lib/NGCP/Panel/Field/Contract.pm @@ -11,7 +11,7 @@ has_field 'id' => ( template => 'share/templates/helpers/datatables_field.tt', ajax_src => '/contract/peering/ajax', table_titles => ['#', 'Contact #', 'Billing Profile #', 'Status'], - table_fields => ['id', 'contact_id', 'billing_profile', 'status'], + table_fields => ['id', 'contact_id', 'billing_profile_id', 'status'], ); has_field 'create' => ( diff --git a/lib/NGCP/Panel/Widget/Plugin/AdminBillingOverview.pm b/lib/NGCP/Panel/Widget/Plugin/AdminBillingOverview.pm index 08b020e1a3..b5b2527163 100644 --- a/lib/NGCP/Panel/Widget/Plugin/AdminBillingOverview.pm +++ b/lib/NGCP/Panel/Widget/Plugin/AdminBillingOverview.pm @@ -21,8 +21,39 @@ has 'priority' => ( around handle => sub { my ($foo, $self, $c) = @_; + my $stime = DateTime->now->truncate(to => 'month'); + my $etime = $stime->clone->add(months => 1); - $c->log->debug("AdminBillingOverview::handle"); + $c->stash( + profiles => $c->model('billing')->resultset('billing_profiles')->search_rs({}), + peering_sum => $c->model('billing')->resultset('contract_balances')->search_rs({ + 'start' => { '>=' => $stime }, + 'end' => { '<' => $etime}, + 'product.class' => 'sippeering', + }, { + join => { + 'contract' => { 'billing_mappings' => 'product' }, + }, + })->get_column('cash_balance_interval')->sum, + reseller_sum => $c->model('billing')->resultset('contract_balances')->search_rs({ + 'start' => { '>=' => $stime }, + 'end' => { '<' => $etime}, + 'product.class' => 'reseller', + }, { + join => { + 'contract' => { 'billing_mappings' => 'product' }, + }, + })->get_column('cash_balance_interval')->sum, + customer_sum => $c->model('billing')->resultset('contract_balances')->search_rs({ + 'start' => { '>=' => $stime }, + 'end' => { '<' => $etime}, + 'billing_mappings.product_id' => undef, + }, { + join => { + 'contract' => 'billing_mappings', + }, + })->get_column('cash_balance_interval')->sum, + ); return; }; diff --git a/lib/NGCP/Panel/Widget/Plugin/AdminResellerOverview.pm b/lib/NGCP/Panel/Widget/Plugin/AdminResellerOverview.pm index 8e14541b50..9a168127c4 100644 --- a/lib/NGCP/Panel/Widget/Plugin/AdminResellerOverview.pm +++ b/lib/NGCP/Panel/Widget/Plugin/AdminResellerOverview.pm @@ -22,7 +22,16 @@ has 'priority' => ( around handle => sub { my ($foo, $self, $c) = @_; - $c->log->debug("AdminResellerOverview::handle"); + $c->stash( + resellers => $c->model('billing')->resultset('resellers')->search_rs({}), + domains => $c->model('billing')->resultset('resellers')->search_rs({}), + customers => $c->model('billing')->resultset('contracts')->search_rs({ + product_id => undef, + }, { + join => 'billing_mappings', + }), + subscribers => $c->model('provisioning')->resultset('voip_subscribers')->search_rs({}), + ); return; }; diff --git a/share/templates/contract/list.tt b/share/templates/contract/list.tt index d58a2eed36..021257c369 100644 --- a/share/templates/contract/list.tt +++ b/share/templates/contract/list.tt @@ -5,7 +5,7 @@ helper.data = contracts; helper.messages = messages; helper.column_titles = [ '#', 'Contact #', 'Billing Profile #', 'Status' ]; - helper.column_fields = [ 'id', 'contact_id', 'billing_profile', 'status' ]; + helper.column_fields = [ 'id', 'contact_id', 'billing_profile_id', 'status' ]; helper.close_target = close_target; helper.create_flag = create_flag; diff --git a/share/templates/peering/list.tt b/share/templates/peering/list.tt index 2a6e236561..8838d6bd14 100644 --- a/share/templates/peering/list.tt +++ b/share/templates/peering/list.tt @@ -1,7 +1,6 @@ [% META title = 'SIP Peering Groups' -%] [% helper.name = 'SIP Peering Groups'; - helper.show_create_button = 1; helper.messages = messages; helper.column_titles = [ '#', 'Name', 'Priority', 'Description', 'Contract #' ]; helper.column_fields = [ 'id', 'name', 'priority', 'description', 'peering_contract_id' ]; diff --git a/share/templates/reseller/details.tt b/share/templates/reseller/details.tt index 1578ff551d..8f40894d56 100644 --- a/share/templates/reseller/details.tt +++ b/share/templates/reseller/details.tt @@ -11,6 +11,7 @@ [% FOREACH m IN messages -%]
[% m.text %]
[% END -%] +[% messages = [] -%]
diff --git a/share/templates/widgets/admin_billing_overview.tt b/share/templates/widgets/admin_billing_overview.tt index 0b1f6753e8..4910acae82 100644 --- a/share/templates/widgets/admin_billing_overview.tt +++ b/share/templates/widgets/admin_billing_overview.tt @@ -3,14 +3,15 @@
Billing
- 28 + [% profiles.count %] Billing Profiles
    -
  • €2000 Peering Costs
  • -
  • €5000 Reseller Revenue
  • +
  • [% FILTER format("%.02f") %][% peering_sum / 100.0 %][% END %] Peering Costs
  • +
  • [% FILTER format("%.02f") %][% reseller_sum / 100.0 %][% END %] Reseller Revenue
  • +
  • [% FILTER format("%.02f") %][% customer_sum / 100.0 %][% END %] Customer Revenue
diff --git a/share/templates/widgets/admin_reseller_overview.tt b/share/templates/widgets/admin_reseller_overview.tt index 7f40f3cbc7..e6d284241b 100644 --- a/share/templates/widgets/admin_reseller_overview.tt +++ b/share/templates/widgets/admin_reseller_overview.tt @@ -3,15 +3,15 @@
Resellers
- 4 + [% resellers.count %] Resellers
    -
  • 13 Domains
  • -
  • 22745 Accounts
  • -
  • 49355 Subscribers
  • +
  • [% domains.count %] Domains
  • +
  • [% customers.count %] Customers
  • +
  • [% subscribers.count %] Subscribers