1 <% include( '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(),
14 'fields' => [ 'svcnum',
19 \&FS::UI::Web::cust_fields,
26 ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
27 FS::UI::Web::cust_header()
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;
61 my $orderby = 'ORDER BY svcnum';
65 my $link = [ "${p}view/svc_phone.cgi?", 'svcnum' ];
68 if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) {
70 push @extra_sql, 'pkgnum IS NULL'
71 if $cgi->param('magic') eq 'unlinked';
73 if ( $cgi->param('sortby') =~ /^(\w+)$/ ) {
75 $orderby = "ORDER BY $sortby";
78 if ( $cgi->param('usage_total') ) {
80 my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi, 'usage');
84 #my $and_date = " AND startdate >= $beginning AND startdate <= $ending ";
85 my $and_date = " AND enddate >= $beginning AND enddate <= $ending ";
87 my $fromwhere = " FROM cdr WHERE cdr.svcnum = svc_phone.svcnum $and_date";
89 #more efficient to join against cdr just once... this will do for now
90 push @select, map { " ( SELECT SUM($_) $fromwhere ) AS $_ " }
91 qw( billsec rated_price );
93 my $money_char = $conf->config('money_char') || '$';
95 push @header, 'Minutes', 'Billed';
97 sub { sprintf('%.3f', shift->get('billsec') / 60 ); },
98 sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
100 #XXX and termination... (this needs a config to turn on, not by default)
101 if ( 1 ) { # $conf->exists('cdr-termination_hack') { #}
104 " FROM cdr_termination LEFT JOIN cdr USING ( acctid ) ".
105 " WHERE cdr.carrierid = CAST(svc_phone.phonenum AS BIGINT) ". # XXX connectone-specific, has to match svc_external.id :/
109 " ( SELECT SUM(billsec) $f_w ) AS term_billsec ",
110 " ( SELECT SUM(cdr_termination.rated_price) $f_w ) AS term_rated_price";
112 push @header, 'Term Min', 'Term Billed';
114 sub { sprintf('%.3f', shift->get('term_billsec') / 60 ); },
115 sub { $money_char. sprintf('%.2f', shift->get('rated_price') ); };
122 } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
123 push @extra_sql, "svcpart = $1";
125 $cgi->param('phonenum') =~ /^([\d\- ]+)$/;
126 ( $svc_phone{'phonenum'} = $1 ) =~ s/\D//g;
129 my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
130 ' LEFT JOIN part_svc USING ( svcpart ) '.
131 ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
132 ' LEFT JOIN cust_main USING ( custnum ) ';
134 #here is the agent virtualization
135 push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql(
136 'null_right' => 'View/link unlinked services'
141 $extra_sql = ( keys(%svc_phone) ? ' AND ' : ' WHERE ' ).
142 join(' AND ', @extra_sql );
145 my $count_query = "SELECT COUNT(*) FROM svc_phone $addl_from ";
146 if ( keys %svc_phone ) {
147 $count_query .= ' WHERE '.
148 join(' AND ', map "$_ = ". dbh->quote($svc_phone{$_}),
152 $count_query .= $extra_sql;
155 'table' => 'svc_phone',
156 'hashref' => \%svc_phone,
157 'select' => join(', ',
162 FS::UI::Web::cust_sql_fields(),
164 'extra_sql' => $extra_sql,
165 'order_by' => $orderby,
166 'addl_from' => $addl_from,
169 #smaller false laziness w/svc_*.cgi here
170 my $link_cust = sub {
172 $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : '';