1 <% include( 'elements/search.html',
2 'title' => 'Account Search Results',
5 'count_query' => $count_query,
17 #false laziness w/ClientAPI/MyAccount.pm
20 (($support < 0) ? '-' : '' ). int(abs($support)/3600)."h".sprintf("%02d",(abs($support)%3600)/60)."m";
27 unless $FS::CurrentUser::CurrentUser->access_right('List services');
29 my $link = [ "${p}view/svc_acct.cgi?", 'svcnum' ];
32 if ( $svc_acct->custnum ) {
33 [ "${p}view/cust_main.cgi?", 'custnum' ];
41 my @header = ( '#', 'Service', 'Account', 'UID' );
42 my @fields = ( 'svcnum', 'svc', 'email', 'uid' );
43 my @links = ( $link, $link, $link, $link );
45 my @color = ( '', '', '', '' );
46 my @style = ( '', '', '', '' );
48 if ( $cgi->param('domain') ) {
50 qsearchs('svc_domain', { 'domain' => $cgi->param('domain') } );
51 unless ( $svc_domain ) {
52 #it would be nice if this looked more like the other "not found"
53 #errors, but this will do for now.
54 eidiot "Domain ". $cgi->param('domain'). " not found at all";
56 push @extra_sql, 'domsvc = '. $svc_domain->svcnum;
60 my $orderby = 'ORDER BY svcnum';
61 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
63 push @extra_sql, 'pkgnum IS NULL'
64 if $cgi->param('magic') eq 'unlinked';
67 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
69 $sortby = "LOWER($sortby)"
70 if $sortby eq 'username';
71 push @extra_sql, "$sortby IS NOT NULL"
72 if $sortby eq 'uid' || $sortby eq 'seconds';
73 $orderby = "ORDER BY $sortby";
76 if ( $sortby eq 'seconds' ) {
77 #push @header, 'Time remaining';
79 push @fields, sub { my $svc_acct = shift; format_time($svc_acct->seconds) };
85 my $conf = new FS::Conf;
86 if ( $conf->exists('svc_acct-display_paid_time_remaining') ) {
87 push @header, 'Paid time';
90 my $seconds = $svc_acct->seconds;
91 my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
92 my $part_pkg = $cust_pkg->part_pkg;
93 my $timepermonth = $part_pkg->option('seconds');
94 return format_time($seconds) unless $timepermonth;
95 #my $recur = $part_pkg->calc_recur($cust_pkg);
96 my $recur = $part_pkg->base_recur($cust_pkg);
97 my $balance = $cust_pkg->cust_main->balance;
98 my $months_unpaid = $balance / $recur;
99 my $time_unpaid = $months_unpaid * $timepermonth;
100 format_time($seconds-$time_unpaid);
110 } elsif ( $cgi->param('popnum') =~ /^(\d+)$/ ) {
111 push @extra_sql, "popnum = $1";
112 $orderby = "ORDER BY LOWER(username)";
113 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
114 push @extra_sql, "svcpart = $1";
115 $orderby = "ORDER BY uid";
116 #$orderby = "ORDER BY svcnum";
118 $orderby = "ORDER BY uid";
123 foreach ( $cgi->param('username_type') ) {
124 $username_type{$_}++;
127 $cgi->param('username') =~ /^([\w\-\.\&]+)$/; #untaint username_text
130 push @username_sql, "username ILIKE '$username'"
131 if $username_type{'Exact'}
132 || $username_type{'Fuzzy'};
134 push @username_sql, "username ILIKE '\%$username\%'"
135 if $username_type{'Substring'}
136 || $username_type{'All'};
138 if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
139 &FS::svc_acct::check_and_rebuild_fuzzyfiles;
140 my $all_username = &FS::svc_acct::all_username;
143 if ( $username_type{'Fuzzy'} || $username_type{'All'} ) {
144 foreach ( amatch($username, [ qw(i) ], @$all_username) ) {
149 #if ($username_type{'Sound-alike'}) {
152 push @username_sql, "username = '$_'"
153 foreach (keys %username);
157 push @extra_sql, '( '. join( ' OR ', @username_sql). ' )';
161 push @header, FS::UI::Web::cust_header();
162 push @fields, \&FS::UI::Web::cust_fields,
163 push @links, map { $_ ne 'Cust. Status' ? $link_cust : '' }
164 FS::UI::Web::cust_header();
165 $align .= FS::UI::Web::cust_aligns();
166 push @color, FS::UI::Web::cust_colors();
167 push @style, FS::UI::Web::cust_styles();
169 my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
170 ' LEFT JOIN part_svc USING ( svcpart ) '.
171 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
172 ' LEFT JOIN cust_main USING ( custnum ) ';
174 #here is the agent virtualization
175 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
176 'null_right' => 'View/link unlinked services'
181 ? ' WHERE '. join(' AND ', @extra_sql )
184 my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
185 #if ( keys %svc_acct ) {
186 # $count_query .= ' WHERE '.
187 # join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}),
193 'table' => 'svc_acct',
194 'hashref' => {}, # \%svc_acct,
195 'select' => join(', ',
199 FS::UI::Web::cust_sql_fields(),
201 'extra_sql' => "$extra_sql $orderby",
202 'addl_from' => $addl_from,