You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcp-panel/lib/NGCP/Panel/Widget/Dashboard/AdminResellerOverview.pm

90 lines
2.1 KiB

package NGCP::Panel::Widget::Dashboard::AdminResellerOverview;
use warnings;
use strict;
use NGCP::Panel::Utils::DateTime qw();
sub template {
return 'widgets/admin_reseller_overview.tt';
}
sub filter {
my ($self, $c) = @_;
return 1 if(
$c->user->roles eq 'admin'
);
return;
}
sub _prepare_resellers_count {
my ($self, $c) = @_;
$c->stash(
resellers => $c->model('DB')->resultset('resellers')->search_rs({
status => { '!=' => 'terminated' },
}),
);
}
sub _prepare_domains_count {
my ($self, $c) = @_;
$c->stash(
domains => $c->model('DB')->resultset('domain_resellers')->search_rs({}),
);
}
sub _prepare_customers_count {
my ($self, $c) = @_;
my $now = NGCP::Panel::Utils::DateTime::current_local;
my $dtf = $c->model('DB')->storage->datetime_parser;
$c->stash(
customers => $c->model('DB')->resultset('contracts')->search({
'me.status' => { '!=' => 'terminated' },
'contact.reseller_id' => { '-not' => undef },
'-or' => [
'product.class' => 'sipaccount',
'product.class' => 'pbxaccount',
],
},{
bind => [ ( $dtf->format_datetime($now) ) x 2, undef, undef ],
'join' => [ 'contact', { 'billing_mappings_actual' => { 'billing_mappings' => 'product'}} ],
}),
);
}
sub _prepare_subscribers_count {
my ($self, $c) = @_;
$c->stash(
subscribers => $c->model('DB')->resultset('voip_subscribers')->search_rs({
status => { '!=' => 'terminated' },
}),
);
}
sub resellers_count {
my ($self, $c) = @_;
$self->_prepare_resellers_count($c);
return $c->stash->{resellers}->count;
}
sub domains_count {
my ($self, $c) = @_;
$self->_prepare_domains_count($c);
return $c->stash->{domains}->count;
}
sub customers_count {
my ($self, $c) = @_;
$self->_prepare_customers_count($c);
return $c->stash->{customers}->count;
}
sub subscribers_count {
my ($self, $c) = @_;
$self->_prepare_subscribers_count($c);
return $c->stash->{subscribers}->count;
}
1;
# vim: set tabstop=4 expandtab: