option to keep track of unrateable CDRs, #15502
[freeside.git] / httemplate / view / svc_phone.cgi
1 <& elements/svc_Common.html,
2               'table'     => 'svc_phone',
3               'fields'    => \@fields,
4                   'labels'    => \%labels,
5               'html_foot' => $html_foot,
6 &>
7 <%init>
8
9 my $conf = new FS::Conf;
10 my $countrydefault = $conf->config('countrydefault') || 'US';
11
12 my $fields = FS::svc_phone->table_info->{'fields'};
13 my %labels = map { $_ =>  ( ref($fields->{$_})
14                              ? $fields->{$_}{'label'}
15                              : $fields->{$_}
16                          );
17                  } keys %$fields;
18
19 my @fields = qw( countrycode phonenum );
20 push @fields, 'domain' if $conf->exists('svc_phone-domain');
21 push @fields, qw( pbx_title sip_password pin phone_name forwarddst email );
22
23 if ( $conf->exists('svc_phone-lnp') ) {
24 push @fields, 'lnp_status',
25             'lnp_reject_reason',
26             { field => 'portable', type => 'checkbox', },
27             'lrn',
28             { field => 'lnp_desired_due_date', type => 'date', },
29             { field => 'lnp_due_date', type => 'date', },
30             'lnp_other_provider',
31             'lnp_other_provider_account';
32 }
33
34 my $html_foot = sub {
35   my $svc_phone = shift;
36
37   ###
38   # E911 Info
39   ###
40
41   my $e911 = 
42     emt('E911 Information').
43     &ntable("#cccccc"). '<TR><TD>'. ntable("#cccccc",2).
44       '<TR><TD>'.emt('Location').'</TD>'.
45       '<TD BGCOLOR="#FFFFFF">'.
46         $svc_phone->location_label( 'join_string'     => '<BR>',
47                                     'double_space'    => ' &nbsp; ',
48                                     'escape_function' => \&encode_entities,
49                                     'countrydefault'  => $countrydefault,
50                                   ).
51       '</TD></TR>'.
52     '</TABLE></TD></TR></TABLE>'.
53     '<BR>'
54   ;
55
56   ###
57   # Devices
58   ###
59   my $devices = include('/view/elements/svc_devices.html',
60                           'svc_x' => $svc_phone,
61                           'table' => 'phone_device',
62                        );
63
64   ##
65   # CDR links
66   ##
67
68   tie my %what, 'Tie::IxHash',
69     'pending' => 'NULL',
70     'billed'  => 'done',
71     'skipped' => 'failed',
72   ;
73
74   my $number = $svc_phone->phonenum;
75   $number = $svc_phone->countrycode. $number
76     unless $svc_phone->countrycode eq '1';
77
78   #src & charged party as per voip_cdr.pm
79   #XXX handle toll free too
80
81   my $search = "charged_party_or_src=";
82
83   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
84
85   if ( $cust_pkg ) {
86
87     #XXX handle voip_inbound too
88
89     my @part_pkg = grep { $_->plan eq 'voip_cdr' }
90                         $cust_pkg->part_pkg->self_and_bill_linked;
91
92     foreach my $prefix (grep $_, map $_->option('default_prefix'), @part_pkg) {
93       $number .= ",$prefix$number";
94     }
95
96     $search = 'charged_party='
97       unless !@part_pkg || grep { ! $_->option('disable_src',1) } @part_pkg;
98
99   }
100
101   $search .= $number;
102
103   my @links = map {
104     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;$search;freesidestatus=$what{$_}">).
105     "View $_ CDRs</A>";
106   } keys(%what);
107
108   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
109                  'View incoming CDRs</A>' );
110
111   ###
112   # concatenate & return
113   ###
114
115   $e911.
116   $devices.
117   join(' | ', @links ). '<BR>'.
118   join(' | ', @ilinks). '<BR>';
119
120 };
121
122 </%init>