multi-select for agent on RADIUS usage report, RT#73050
[freeside.git] / httemplate / search / svc_dish.cgi
1 <& elements/svc_Common.html,
2                  'title'       => 'Dish Network Search Results',
3                  'name'        => 'services',
4                  'query'       => $sql_query,
5                  'count_query' => $count_query,
6                  'redirect'    => $link,
7                  'header'      => [ '#',
8                                     'Service',
9                                     'Account #',
10                                     emt('Pkg. Status'),
11                                     FS::UI::Web::cust_header(),
12                                   ],
13                  'fields'      => [ 'svcnum',
14                                     'svc',
15                                     'acctnum',
16                                     sub {
17                                       $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
18                                       return '' unless $cust_pkg_cache{$_[0]->svcnum};
19                                       $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
20                                     },
21                                     \&FS::UI::Web::cust_fields,
22                                   ],
23                  'links'       => [ $link,
24                                     $link,
25                                     $link,
26                                     '', # pkg status
27                                     ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
28                                           FS::UI::Web::cust_header()
29                                     ),
30                                   ],
31                  'align' => 'rllr'. FS::UI::Web::cust_aligns(),
32                  'color' => [ 
33                               '',
34                               '',
35                               '',
36                               sub {
37                                 $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
38                                 return '' unless $cust_pkg_cache{$_[0]->svcnum};
39                                 my $c = FS::cust_pkg::statuscolors;
40                                 $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
41                               }, # pkg status
42                               FS::UI::Web::cust_colors(),
43                             ],
44                  'style' => [ 
45                               '',
46                               '',
47                               '',
48                               'b',
49                               FS::UI::Web::cust_styles(),
50                             ],
51              
52 &>
53 <%init>
54
55 die "access denied"
56   unless $FS::CurrentUser::CurrentUser->access_right('List services');
57
58 my %cust_pkg_cache;
59
60 #my $conf = new FS::Conf;
61
62 my $orderby = 'ORDER BY svcnum';
63 my @extra_sql = ();
64 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
65
66   push @extra_sql, 'pkgnum IS NULL'
67     if $cgi->param('magic') eq 'unlinked';
68
69   if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
70     my $sortby = $1;
71     $orderby = "ORDER BY $sortby";
72   }
73 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
74   push @extra_sql, "svcpart = $1";
75   if (defined($cgi->param('cancelled'))) {
76     if ($cgi->param('cancelled')) {
77       push @extra_sql, "cust_pkg.cancel IS NOT NULL";
78     } else {
79       push @extra_sql, "cust_pkg.cancel IS NULL";
80     }
81   }
82 }
83
84 my $addl_from = ' LEFT JOIN cust_svc  USING ( svcnum  ) '.
85                 ' LEFT JOIN part_svc  USING ( svcpart ) '.
86                 ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
87                 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
88
89 #here is the agent virtualization
90 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
91                    'null_right' => 'View/link unlinked services'
92                  );
93
94 my $extra_sql = 
95   scalar(@extra_sql)
96     ? ' WHERE '. join(' AND ', @extra_sql )
97     : '';
98
99
100 my $count_query = "SELECT COUNT(*) FROM svc_dish $addl_from $extra_sql";
101 my $sql_query = {
102   'table'     => 'svc_dish',
103   'hashref'   => {},
104   'select'    => join(', ',
105                    'svc_dish.*',
106                    'part_svc.svc',
107                    'cust_main.custnum',
108                    FS::UI::Web::cust_sql_fields(),
109                  ),
110   'extra_sql' => $extra_sql,
111   'order_by'  => $orderby,
112   'addl_from' => $addl_from,
113 };
114
115 my $link  = [ "${p}view/svc_dish.cgi?", 'svcnum', ];
116
117 my $link_cust = sub {
118   my $svc_x = shift;
119   $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : '';
120 };
121
122 </%init>