1 <& elements/svc_Common.html,
2 'title' => "Phone number search results",
3 'name' => 'phone numbers',
5 'count_query' => $count_query,
6 'redirect' => $redirect,
13 FS::UI::Web::cust_header($cgi->param('cust_fields')),
15 'fields' => [ 'svcnum',
21 $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
22 return '' unless $cust_pkg_cache{$_[0]->svcnum};
23 $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
25 \&FS::UI::Web::cust_fields,
33 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
34 FS::UI::Web::cust_header($cgi->param('cust_fields'))
38 join('', map 'r', @header).
40 FS::UI::Web::cust_aligns(),
48 $cust_pkg_cache{$_[0]->svcnum} ||= $_[0]->cust_svc->cust_pkg;
49 return '' unless $cust_pkg_cache{$_[0]->svcnum};
50 my $c = FS::cust_pkg::statuscolors;
51 $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
53 FS::UI::Web::cust_colors(),
62 FS::UI::Web::cust_styles(),
69 unless $FS::CurrentUser::CurrentUser->access_right('List services');
73 my $conf = new FS::Conf;
76 my $orderby = 'ORDER BY svcnum';
80 my $link = [ "${p}view/svc_phone.cgi?", 'svcnum' ];
86 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
88 $search_hash{'unlinked'} = 1
89 if $cgi->param('magic') eq 'unlinked';
91 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
93 $orderby = "ORDER BY $sortby";
96 if ( $cgi->param('usage_total') ) {
98 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi, 'usage');
102 #my $and_date = " AND startdate >= $beginning AND startdate <= $ending ";
103 my $and_date = " AND enddate >= $beginning AND enddate <= $ending ";
105 my $fromwhere = " FROM cdr WHERE cdr.svcnum = svc_phone.svcnum $and_date";
107 #more efficient to join against cdr just once... this will do for now
108 push @select, map { " ( SELECT SUM($_) $fromwhere ) AS $_ " }
109 qw( billsec rated_price );
111 my $money_char = $conf->config('money_char') || '$';
113 push @header, 'Minutes', 'Billed';
115 sub { sprintf('%.3f', shift->get('billsec') / 60 ); },
116 sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
118 #XXX and termination... (this needs a config to turn on, not by default)
119 if ( 1 ) { # $conf->exists('cdr-termination_hack') { #}
122 " FROM cdr_termination LEFT JOIN cdr USING ( acctid ) ".
123 " WHERE cdr.carrierid = CAST(svc_phone.phonenum AS BIGINT) ". # XXX connectone-specific, has to match svc_external.id :/
127 " ( SELECT SUM(billsec) $f_w ) AS term_billsec ",
128 " ( SELECT SUM(cdr_termination.rated_price) $f_w ) AS term_rated_price";
130 push @header, 'Term Min', 'Term Billed';
132 sub { sprintf('%.3f', shift->get('term_billsec') / 60 ); },
133 sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
140 } elsif ( $cgi->param('magic') =~ /^advanced$/ ) {
142 for (qw( agentnum custnum cust_status balance balance_days cust_fields )) {
143 $search_hash{$_} = $cgi->param($_) if length($cgi->param($_));
146 for (qw( payby pkgpart svcpart )) {
147 $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
150 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
151 $search_hash{'svcpart'} = [ $1 ];
152 if ( defined($cgi->param('cancelled')) ) {
153 $search_hash{'cancelled'} = $cgi->param('cancelled') ? 1 : 0;
156 $cgi->param('phonenum') =~ /^([\d\- ]+)$/;
158 $phonenum =~ s/\D//g;
159 push @extra_sql, "phonenum = '$phonenum'";
162 $search_hash{'addl_select'} = \@select;
163 $search_hash{'order_by'} = $orderby;
164 $search_hash{'where'} = \@extra_sql;
166 my $sql_query = FS::svc_phone->search(\%search_hash);
167 my $count_query = delete($sql_query->{'count_query'});
169 #smaller false laziness w/svc_*.cgi here
170 my $link_cust = sub {
172 $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : '';