Implement reseller dashboard widgets.

agranig/1_0_subfix
Andreas Granig 12 years ago
parent 7db9c09b13
commit 0b596b7c85

@ -26,6 +26,7 @@ around handle => sub {
resellers => $c->model('DB')->resultset('resellers')->search_rs({}),
domains => $c->model('DB')->resultset('domain_resellers')->search_rs({}),
customers => $c->model('DB')->resultset('contracts')->search_rs({
status => { '!=' => 'terminated' },
product_id => undef,
}, {
join => 'billing_mappings',

@ -0,0 +1,65 @@
package NGCP::Panel::Widget::Plugin::ResellerBillingOverview;
use Moose::Role;
has 'template' => (
is => 'ro',
isa => 'Str',
default => 'widgets/reseller_billing_overview.tt',
);
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'dashboard_widgets',
);
has 'priority' => (
is => 'ro',
isa => 'Int',
default => 11,
);
around handle => sub {
my ($foo, $self, $c) = @_;
my $stime = DateTime->now->truncate(to => 'month');
my $etime = $stime->clone->add(months => 1);
my $reseller = $c->model('DB')->resultset('resellers')->find($c->user->reseller_id);
my $reseller_balance = $reseller->contract->contract_balances->search({
'start' => { '>=' => $stime },
'end' => { '<' => $etime},
})->first;
my $reseller_sum = 0;
if($reseller_balance) {
$reseller_sum = $reseller_balance->cash_balance_interval;
}
$c->stash(
profiles => $reseller->billing_profiles,
reseller_sum => $reseller_sum,
customer_sum => $c->model('DB')->resultset('contract_balances')->search_rs({
'start' => { '>=' => $stime },
'end' => { '<' => $etime},
'contact.reseller_id' => $c->user->reseller_id,
}, {
join => {
'contract' => 'contact',
},
})->get_column('cash_balance_interval')->sum,
);
return;
};
sub filter {
my ($self, $c, $type) = @_;
return $self if(
$type eq $self->type &&
$c->user_in_realm('reseller') &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
);
return;
}
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,59 @@
package NGCP::Panel::Widget::Plugin::ResellerCustomerOverview;
use Moose::Role;
has 'template' => (
is => 'ro',
isa => 'Str',
default => 'widgets/reseller_customer_overview.tt'
);
has 'type' => (
is => 'ro',
isa => 'Str',
default => 'dashboard_widgets',
);
has 'priority' => (
is => 'ro',
isa => 'Int',
default => 10,
);
around handle => sub {
my ($foo, $self, $c) = @_;
my $reseller = $c->model('DB')->resultset('resellers')->find($c->user->reseller_id);
$c->stash(
customers => $c->model('DB')->resultset('contracts')->search({
'me.status' => { '!=' => 'terminated' },
'contact.reseller_id' => $c->user->reseller_id,
},{
join => 'contact',
}),
subscribers => $c->model('DB')->resultset('voip_subscribers')->search({
'contact.reseller_id' => $c->user->reseller_id,
'me.status' => { '!=' => 'terminated' },
},{
join => { 'contract' => 'contact'},
}),
contacts => $c->model('DB')->resultset('contacts')->search({
reseller_id => $c->user->reseller_id,
}),
);
return;
};
sub filter {
my ($self, $c, $type) = @_;
return $self if(
$type eq $self->type &&
$c->user_in_realm('reseller') &&
ref $c->controller eq 'NGCP::Panel::Controller::Dashboard'
);
return;
}
1;
# vim: set tabstop=4 expandtab:

@ -16,13 +16,19 @@ has 'type' => (
has 'priority' => (
is => 'ro',
isa => 'Int',
default => 100,
default => 10,
);
around handle => sub {
my ($foo, $self, $c) = @_;
$c->log->debug("ResellerDomainOverview::handle");
my $reseller = $c->model('DB')->resultset('resellers')->find($c->user->reseller_id);
$c->stash(
domains => $reseller->domain_resellers,
rwr_sets => $reseller->voip_rewrite_rule_sets,
sound_sets => $reseller->voip_sound_sets,
);
return;
};

@ -4,7 +4,7 @@
<div class="plan-title">Billing</div>
<div class="plan-price">
<span>[% profiles.count %]</span>
<span class="term">Billing Profiles</span>
<span class="term">Billing Profile[% profiles.count == 1 ? "" : "s" %]</span>
</div>
</div>
<div class="plan-features">

@ -0,0 +1,21 @@
<div class="plan-container">
<div class="plan">
<div class="plan-header">
<div class="plan-title">Billing</div>
<div class="plan-price">
<span>[% profiles.count %]</span>
<span class="term">Billing Profile[% profiles.count == 1 ? "" : "s" %]</span>
</div>
</div>
<div class="plan-features">
<ul>
<li><strong>[% FILTER format("%.02f") %][% reseller_sum / 100.0 %][% END %]</strong> Reseller Cost</li>
<li><strong>[% FILTER format("%.02f") %][% customer_sum / 100.0 %][% END %]</strong> Customer Revenue</li>
</ul>
</div>
<div class="plan-actions">
<a href="[% c.uri_for('/billing') %]" class="btn">Configure</a>
</div>
</div>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -0,0 +1,21 @@
<div class="plan-container">
<div class="plan">
<div class="plan-header">
<div class="plan-title">Customers</div>
<div class="plan-price">
<span>[% customers.count %]</span>
<span class="term">Customer[% customers.count == 1 ? "" : "s" %]</span>
</div>
</div>
<div class="plan-features">
<ul>
<li><strong>[% contacts.count %]</strong> Contact[% contacts.count == 1 ? "" : "s" %]</li>
<li><strong>[% subscribers.count %]</strong> Subscriber[% subscribers.count == 1 ? "" : "s" %]</li>
</ul>
</div>
<div class="plan-actions">
<a href="[% c.uri_for('/customer') %]" class="btn">Configure</a>
</div>
</div>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -3,18 +3,18 @@
<div class="plan-header">
<div class="plan-title">Domains</div>
<div class="plan-price">
<span>7</span>
<span class="term">Domains</span>
<span>[% domains.count %]</span>
<span class="term">Domain[% domains.count == 1 ? "" : "s" %]</span>
</div>
</div>
<div class="plan-features">
<ul>
<li><strong>4674</strong> Accounts</li>
<li><strong>12456</strong> Subscribers</li>
<li><strong>[% rwr_sets.count %]</strong> Rewrite Rule Set[% rwr_sets.count == 1 ? "" : "s" %]</li>
<li><strong>[% sound_sets.count %]</strong> Sound Set[% sound_sets.count == 1 ? "" : "s" %]</li>
</ul>
</div>
<div class="plan-actions">
<a href="/domain" class="btn">Configure</a>
<a href="[% c.uri_for('/domain') %]" class="btn">Configure</a>
</div>
</div>
</div>

Loading…
Cancel
Save