@svc_fields,
@svc_usage,
],
+ 'order_by_sql' => $order_by_sql,
'links' => [ #( map { $_ ne 'Cust. Status' ? $link_cust : '' }
# FS::UI::Web::cust_header() ),
$link_cust,
die "access denied" unless $curuser->access_right('List services');
my $title = 'Data Usage Report - ';
-my $agentnum;
-my @include_agents;
+my $agentnum = '';
+my @include_agents = ();
-if ( $opt{'agentnum'} ) {
+if ( $opt{'agentnum'} =~ /^(\d+)$/ ) {
$agentnum = $opt{'agentnum'};
-} elsif ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
- $agentnum = $1;
+} else {
+
+ my @agentnums = grep /^(\d+)$/, $cgi->param('agentnum');
+
+ if ( ! @agentnums ) {
+ @include_agents = qsearch({ 'table' => 'agent',
+ 'hashref' => { 'disabled'=>'' },
+ 'extra_sql' => ' AND '. $curuser->agentnums_sql,
+ });
+ } elsif ( scalar(@agentnums) == 1 ) {
+ $agentnum = $agentnums[0];
+ } else {
+ @include_agents = qsearch({ 'table' => 'agent',
+ 'hashref' => { 'disabled' => '', },
+ 'extra_sql' => 'AND agentnum IN ('.
+ join(',',@agentnums). ') '.
+ ' AND '. $curuser->agentnums_sql,
+ });
+ }
+
}
if ( $agentnum ) {
my $agent = FS::agent->by_key($agentnum);
$title = $agent->agent." $title";
-} else {
- @include_agents = qsearch('agent', {});
}
# usage query params
}
} else {
# one query, get everyone's data
- my $usage = $export->usage_sessions(\%usage_param);
+ $usage = $export->usage_sessions(\%usage_param);
}
# rearrange to be indexed by username.
}
}
-#warn Dumper(\%usage_by_username);
my @total_usage = (0, 0, 0, 0); # session time, input, output, input + output
my @svc_usage = map {
my $i = $_;
$_[0] ? sprintf('%.3f', $_[0] / (1024*1024*1024.0)) : '';
}
-warn Dumper \%usage_by_username;
+my $conf = new FS::Conf;
+my $order_by_sql = {
+ 'name' => "CASE WHEN cust_main.company IS NOT NULL
+ AND cust_main.company != ''
+ THEN CONCAT(cust_main.company,' (',cust_main.last,', ',cust_main.first,')')
+ ELSE CONCAT(cust_main.last,', ',cust_main.first)
+ END",
+ 'display_custnum' => $conf->exists('cust_main-default_agent_custid')
+ ? "CASE WHEN cust_main.agent_custid IS NOT NULL
+ AND cust_main.agent_custid != ''
+ AND cust_main.agent_custid ". regexp_sql. " '^[0-9]+\$'
+ THEN CAST(cust_main.agent_custid AS BIGINT)
+ ELSE cust_main.custnum
+ END"
+ : "custnum",
+};
+
+#warn Dumper \%usage_by_username;
</%init>