X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fsearch%2Fsqlradius_usage.html;h=494a275912ab0e09229618bb06408911c6c82ef1;hp=b5551ade637ea23b11a47d1821eaaabbeb8aa761;hb=ae2ce7f3fc2a0fe00f05145ce64e8b6b8c034631;hpb=4e2e2afe2b9d54e971f433350f215df156e64f60 diff --git a/httemplate/search/sqlradius_usage.html b/httemplate/search/sqlradius_usage.html index b5551ade6..494a27591 100644 --- a/httemplate/search/sqlradius_usage.html +++ b/httemplate/search/sqlradius_usage.html @@ -39,6 +39,7 @@ @svc_fields, @svc_usage, ], + 'order_by_sql' => $order_by_sql, 'links' => [ #( map { $_ ne 'Cust. Status' ? $link_cust : '' } # FS::UI::Web::cust_header() ), $link_cust, @@ -63,20 +64,36 @@ my $curuser = $FS::CurrentUser::CurrentUser; 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 @@ -161,7 +178,7 @@ if ( exists($opt{usage_by_username}) ) { } } 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. @@ -257,7 +274,23 @@ sub bytes_to_gb { $_[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;