Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / search / report_sqlradius_usage-custnum.html
1 <& /elements/header-popup.html, mt($title) &>
2
3 <FORM ACTION="sqlradius_usage.html" METHOD="GET" TARGET="_top">
4
5 <& /elements/hidden.html,
6   'field' => 'custnum',
7   'value' => $custnum,
8 &>
9 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
10
11 % if ( scalar(@exports) == 1 ) {
12 <tr><td>
13 <& /elements/hidden.html,
14   'field'         => 'exportnum',
15   'value'         => $exports[0]->exportnum,
16 &>
17 </td></tr>
18 % } else {
19 <& /elements/tr-select-table.html,
20   'label'         => 'Export', # kind of non-indicative...
21   'table'         => 'part_export',
22   'name_col'      => 'label',
23   'value_col'     => 'exportnum',
24   'records'       => \@exports,
25   'multiple'      => 1,
26 &>
27 % }
28
29 <& /elements/tr-input-beginning_ending.html &>
30
31 <& /elements/tr-radio.html,
32   'field'         => 'combine_svcs',
33   'options'       => [ 0, 1 ],
34   'curr_value'    => 0,
35   'labels'        => { 0 => 'Per service',
36                        1 => 'Per package',
37                      },
38 &>
39
40 </TABLE>
41
42 <BR>
43 <INPUT TYPE="submit" VALUE="<% mt('Get Report') |h %>">
44
45 </FORM>
46
47 <& /elements/footer.html &>
48 <%init>
49
50 my $curuser = $FS::CurrentUser::CurrentUser;
51 die "access denied"
52   unless $curuser->access_right('Usage: RADIUS sessions');
53   # yes?
54
55 my $title = 'Data Usage Report';
56 my $custnum;
57 if ($cgi->keywords) {
58   ($custnum) = $cgi->keywords;
59 } else {
60   $custnum = $cgi->param('custnum');
61 }
62 $custnum =~ /^(\d+)$/
63   or die "illegal custnum $custnum";
64 my $cust_main = qsearchs( {
65   'table'     => 'cust_main',
66   'hashref'   => { 'custnum' => $custnum },
67   'extra_sql' => ' AND '. $curuser->agentnums_sql,
68 });
69 # get all exports that apply to this customer's services--should be fast, as
70 # everything here is indexed
71 my @exports = qsearch({
72   'table'     => 'part_export',
73   'select'    => 'DISTINCT part_export.*',
74   'addl_from' => ' JOIN export_svc USING (exportnum)
75                    JOIN cust_svc USING (svcpart)
76                    JOIN cust_pkg USING (pkgnum) ',
77   'extra_sql' => ' WHERE cust_pkg.custnum = '.$custnum,
78 });
79 @exports = grep { $_->can('usage_sessions') } @exports;
80
81 </%init>