1 <& elements/search.html,
2 'title' => emt('Service search results'),
3 'name' => emt('services'),
5 'count_query' => $count_query,
7 'header' => [ emt('#'),
11 FS::UI::Web::cust_header(),
13 'fields' => [ 'svcnum',
15 #$_[0]->svc. ': '. $_[0]->label;
16 my($label, $value, $svcdb) = $_[0]->label;
17 my $id = $_[0]->agent_svcid
18 ? $_[0]->agent_svcid.': '
23 $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_pkg;
24 return '' unless $cust_pkg_cache{$_[0]->svcnum};
25 $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
28 \&FS::UI::Web::cust_fields,
34 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
35 FS::UI::Web::cust_header()
38 'align' => 'rlr'. FS::UI::Web::cust_aligns(),
43 $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_pkg;
44 return '' unless $cust_pkg_cache{$_[0]->svcnum};
45 my $c = FS::cust_pkg::statuscolors;
46 $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
48 FS::UI::Web::cust_colors(),
54 FS::UI::Web::cust_styles(),
60 unless $FS::CurrentUser::CurrentUser->access_right('List services');
66 my $orderby = 'ORDER BY cust_svc.svcnum'; #has to be ordered by something
67 #for pagination to work
69 if ( length( $cgi->param('search_svc') ) ) {
72 FS::cust_svc->smart_search_param(
73 'search' => scalar($cgi->param('search_svc'))
79 my $addl_from = ' LEFT JOIN part_svc USING ( svcpart ) '.
80 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
81 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
85 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
87 $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb";
88 push @extra_sql, "svcdb = '$1'";
89 $addl_from .= " LEFT JOIN $1 USING ( svcnum ) ";
91 push @extra_sql, 'pkgnum IS NULL'
92 if $cgi->param('magic') eq 'unlinked';
94 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
96 $orderby = "ORDER BY $sortby";
99 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
101 push @extra_sql, "svcpart = $1";
102 if (defined($cgi->param('cancelled'))) {
103 if ($cgi->param('cancelled')) {
104 push @extra_sql, "cust_pkg.cancel IS NOT NULL";
106 push @extra_sql, "cust_pkg.cancel IS NULL";
111 errorpage("No search term specified");
114 #here is the agent virtualization
115 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
116 'null_right' => 'View/link unlinked services'
119 my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
122 'select' => 'cust_svc.*, part_svc.*',
123 'table' => 'cust_svc',
124 'addl_from' => $addl_from,
126 'extra_sql' => $extra_sql,
131 # at this point the query must provide all fields from
132 # cust_svc and part_svc, and must include join_cust_main.
133 $sql_query->{'select'} = join(', ',
134 $sql_query->{'select'},
136 FS::UI::Web::cust_sql_fields(),
138 $sql_query->{'order_by'} = $orderby;
140 my $count_query = "SELECT COUNT(*) FROM cust_svc ". $sql_query->{addl_from}.
141 ' '. $sql_query->{extra_sql};
144 my $cust_svc = shift;
146 if ( $cust_svc->svcpart ) {
150 'svcdb' => $cust_svc->svcdb, #we have it from the joined search
153 } else { # bizarre unlinked service case
154 $url = $p.'view/svc_Common.html?svcdb='.$cust_svc->svcdb.';svcnum=';
159 my $link_cust = sub {
160 my $cust_svc = shift;
161 if ( $cust_svc->custnum ) {
162 [ "${p}view/cust_main.cgi?", 'custnum' ];