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 $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
27 \&FS::UI::Web::cust_fields,
33 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
34 FS::UI::Web::cust_header()
37 'align' => 'rlr'. FS::UI::Web::cust_aligns(),
42 my $c = FS::cust_pkg::statuscolors;
43 $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
45 FS::UI::Web::cust_colors(),
51 FS::UI::Web::cust_styles(),
57 unless $FS::CurrentUser::CurrentUser->access_right('List services');
63 my $orderby = 'ORDER BY cust_svc.svcnum'; #has to be ordered by something
64 #for pagination to work
66 if ( length( $cgi->param('search_svc') ) ) {
69 FS::cust_svc->smart_search_param(
70 'search' => scalar($cgi->param('search_svc'))
76 my $addl_from = ' LEFT JOIN part_svc USING ( svcpart ) '.
77 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
78 FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');
82 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
84 $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb";
85 push @extra_sql, "svcdb = '$1'";
86 $addl_from .= " LEFT JOIN $1 USING ( svcnum ) ";
88 push @extra_sql, 'pkgnum IS NULL'
89 if $cgi->param('magic') eq 'unlinked';
91 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
93 $orderby = "ORDER BY $sortby";
96 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
98 push @extra_sql, "svcpart = $1";
99 if (defined($cgi->param('cancelled'))) {
100 if ($cgi->param('cancelled')) {
101 push @extra_sql, "cust_pkg.cancel IS NOT NULL";
103 push @extra_sql, "cust_pkg.cancel IS NULL";
108 errorpage("No search term specified");
111 #here is the agent virtualization
112 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
113 'null_right' => 'View/link unlinked services'
116 my $extra_sql = ' WHERE '. join(' AND ', @extra_sql );
119 'select' => 'cust_svc.*, part_svc.*',
120 'table' => 'cust_svc',
121 'addl_from' => $addl_from,
123 'extra_sql' => $extra_sql,
128 # at this point the query must provide all fields from
129 # cust_svc and part_svc, and must include join_cust_main.
130 $sql_query->{'select'} = join(', ',
131 $sql_query->{'select'},
133 FS::UI::Web::cust_sql_fields(),
135 $sql_query->{'order_by'} = $orderby;
137 my $count_query = "SELECT COUNT(*) FROM cust_svc ". $sql_query->{addl_from}.
138 ' '. $sql_query->{extra_sql};
141 my $cust_svc = shift;
143 if ( $cust_svc->svcpart ) {
147 'svcdb' => $cust_svc->svcdb, #we have it from the joined search
150 } else { # bizarre unlinked service case
151 $url = $p.'view/svc_Common.html?svcdb='.$cust_svc->svcdb.';svcnum=';
156 my $link_cust = sub {
157 my $cust_svc = shift;
158 if ( $cust_svc->custnum ) {
159 [ "${p}view/cust_main.cgi?", 'custnum' ];