1 <& elements/search.html,
2 'title' => "Phone number search results",
3 'name' => 'phone numbers',
5 'count_query' => $count_query,
6 'redirect' => $redirect,
12 FS::UI::Web::cust_header($cgi->param('cust_fields')),
14 'fields' => [ 'svcnum',
19 \&FS::UI::Web::cust_fields,
26 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
27 FS::UI::Web::cust_header($cgi->param('cust_fields'))
31 join('', map 'r', @header).
32 FS::UI::Web::cust_aligns(),
39 FS::UI::Web::cust_colors(),
47 FS::UI::Web::cust_styles(),
54 unless $FS::CurrentUser::CurrentUser->access_right('List services');
56 my $conf = new FS::Conf;
59 my $orderby = 'ORDER BY svcnum';
63 my $link = [ "${p}view/svc_phone.cgi?", 'svcnum' ];
69 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
71 $search_hash{'unlinked'} = 1
72 if $cgi->param('magic') eq 'unlinked';
74 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
76 $orderby = "ORDER BY $sortby";
79 if ( $cgi->param('usage_total') ) {
81 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi, 'usage');
85 #my $and_date = " AND startdate >= $beginning AND startdate <= $ending ";
86 my $and_date = " AND enddate >= $beginning AND enddate <= $ending ";
88 my $fromwhere = " FROM cdr WHERE cdr.svcnum = svc_phone.svcnum $and_date";
90 #more efficient to join against cdr just once... this will do for now
91 push @select, map { " ( SELECT SUM($_) $fromwhere ) AS $_ " }
92 qw( billsec rated_price );
94 my $money_char = $conf->config('money_char') || '$';
96 push @header, 'Minutes', 'Billed';
98 sub { sprintf('%.3f', shift->get('billsec') / 60 ); },
99 sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
101 #XXX and termination... (this needs a config to turn on, not by default)
102 if ( 1 ) { # $conf->exists('cdr-termination_hack') { #}
105 " FROM cdr_termination LEFT JOIN cdr USING ( acctid ) ".
106 " WHERE cdr.carrierid = CAST(svc_phone.phonenum AS BIGINT) ". # XXX connectone-specific, has to match svc_external.id :/
110 " ( SELECT SUM(billsec) $f_w ) AS term_billsec ",
111 " ( SELECT SUM(cdr_termination.rated_price) $f_w ) AS term_rated_price";
113 push @header, 'Term Min', 'Term Billed';
115 sub { sprintf('%.3f', shift->get('term_billsec') / 60 ); },
116 sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
123 } elsif ( $cgi->param('magic') =~ /^advanced$/ ) {
125 for (qw( agentnum custnum cust_status balance balance_days cust_fields )) {
126 $search_hash{$_} = $cgi->param($_) if length($cgi->param($_));
129 for (qw( payby pkgpart svcpart )) {
130 $search_hash{$_} = [ $cgi->param($_) ] if $cgi->param($_);
133 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
134 $search_hash{'svcpart'} = [ $1 ];
136 $cgi->param('phonenum') =~ /^([\d\- ]+)$/;
138 $phonenum =~ s/\D//g;
139 push @extra_sql, "phonenum = '$phonenum'";
142 $search_hash{'addl_select'} = \@select;
143 $search_hash{'order_by'} = $orderby;
144 $search_hash{'where'} = \@extra_sql;
146 my $sql_query = FS::svc_phone->search(\%search_hash);
147 my $count_query = delete($sql_query->{'count_query'});
149 #smaller false laziness w/svc_*.cgi here
150 my $link_cust = sub {
152 $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : '';