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 $cust_pkg_cache{$_[0]->svcnum}->ucfirst_status
24 \&FS::UI::Web::cust_fields,
32 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
33 FS::UI::Web::cust_header($cgi->param('cust_fields'))
37 join('', map 'r', @header).
39 FS::UI::Web::cust_aligns(),
47 my $c = FS::cust_pkg::statuscolors;
48 $c->{$cust_pkg_cache{$_[0]->svcnum}->status };
50 FS::UI::Web::cust_colors(),
59 FS::UI::Web::cust_styles(),
66 unless $FS::CurrentUser::CurrentUser->access_right('List services');
70 my $conf = new FS::Conf;
73 my $orderby = 'ORDER BY svcnum';
77 my $link = [ "${p}view/svc_phone.cgi?", 'svcnum' ];
83 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
85 $search_hash{'unlinked'} = 1
86 if $cgi->param('magic') eq 'unlinked';
88 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
90 $orderby = "ORDER BY $sortby";
93 if ( $cgi->param('usage_total') ) {
95 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi, 'usage');
99 #my $and_date = " AND startdate >= $beginning AND startdate <= $ending ";
100 my $and_date = " AND enddate >= $beginning AND enddate <= $ending ";
102 my $fromwhere = " FROM cdr WHERE cdr.svcnum = svc_phone.svcnum $and_date";
104 #more efficient to join against cdr just once... this will do for now
105 push @select, map { " ( SELECT SUM($_) $fromwhere ) AS $_ " }
106 qw( billsec rated_price );
108 my $money_char = $conf->config('money_char') || '$';
110 push @header, 'Minutes', 'Billed';
112 sub { sprintf('%.3f', shift->get('billsec') / 60 ); },
113 sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
115 #XXX and termination... (this needs a config to turn on, not by default)
116 if ( 1 ) { # $conf->exists('cdr-termination_hack') { #}
119 " FROM cdr_termination LEFT JOIN cdr USING ( acctid ) ".
120 " WHERE cdr.carrierid = CAST(svc_phone.phonenum AS BIGINT) ". # XXX connectone-specific, has to match svc_external.id :/
124 " ( SELECT SUM(billsec) $f_w ) AS term_billsec ",
125 " ( SELECT SUM(cdr_termination.rated_price) $f_w ) AS term_rated_price";
127 push @header, 'Term Min', 'Term Billed';
129 sub { sprintf('%.3f', shift->get('term_billsec') / 60 ); },
130 sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
137 } elsif ( $cgi->param('magic') =~ /^advanced$/ ) {
139 for (qw( agentnum custnum cust_status balance balance_days cust_fields )) {
140 $search_hash{$_} = $cgi->param($_) if length($cgi->param($_));
143 for (qw( payby pkgpart svcpart )) {
144 $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
147 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
148 $search_hash{'svcpart'} = [ $1 ];
149 if ( defined($cgi->param('cancelled')) ) {
150 $search_hash{'cancelled'} = $cgi->param('cancelled') ? 1 : 0;
153 $cgi->param('phonenum') =~ /^([\d\- ]+)$/;
155 $phonenum =~ s/\D//g;
156 push @extra_sql, "phonenum = '$phonenum'";
159 $search_hash{'addl_select'} = \@select;
160 $search_hash{'order_by'} = $orderby;
161 $search_hash{'where'} = \@extra_sql;
163 my $sql_query = FS::svc_phone->search(\%search_hash);
164 my $count_query = delete($sql_query->{'count_query'});
166 #smaller false laziness w/svc_*.cgi here
167 my $link_cust = sub {
169 $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : '';