svc_cable, RT#22009
[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 sim_imsi );
20 push @fields, 'domain' if $conf->exists('svc_phone-domain');
21 push @fields, qw( pbx_title );
22
23 if ( $conf->exists('showpasswords') ) {
24   push @fields, qw( sip_password );
25 } else {
26   push @fields, { 'field' => 'sip_password', #'_HIDDEN_sip_password',
27                   'type'  => 'fixed',
28                   'value' => '<I>('. mt('hidden') .')</I>',
29                 };
30 }
31
32 push @fields, qw( pin phone_name forwarddst email );
33
34 if ( $conf->exists('svc_phone-lnp') ) {
35 push @fields, 'lnp_status',
36             'lnp_reject_reason',
37             { field => 'portable', type => 'checkbox', },
38             'lrn',
39             { field => 'lnp_desired_due_date', type => 'date', },
40             { field => 'lnp_due_date', type => 'date', },
41             'lnp_other_provider',
42             'lnp_other_provider_account';
43 }
44
45 my $html_foot = sub {
46   my $svc_phone = shift;
47
48   ###
49   # E911 Info
50   ###
51
52   my $e911 = 
53     emt('E911 Information').
54     &ntable("#cccccc"). '<TR><TD>'. ntable("#cccccc",2).
55       '<TR><TD>'.emt('Location').'</TD>'.
56       '<TD BGCOLOR="#FFFFFF">'.
57         $svc_phone->location_label( 'join_string'     => '<BR>',
58                                     'double_space'    => ' &nbsp; ',
59                                     'escape_function' => \&encode_entities,
60                                     'countrydefault'  => $countrydefault,
61                                   ).
62       '</TD></TR>'.
63     '</TABLE></TD></TR></TABLE>'.
64     '<BR>'
65   ;
66
67   ###
68   # Devices
69   ###
70   #remove this when svc_phone isa device_Common, as elements/svc_Common will display it
71   my $devices = include('/view/elements/svc_devices.html',
72                           'svc_x' => $svc_phone,
73                           'table' => 'phone_device',
74                        );
75
76   ##
77   # CDR links
78   ##
79
80   tie my %what, 'Tie::IxHash',
81     'pending' => 'NULL',
82     'billed'  => 'done',
83     'skipped' => 'failed',
84   ;
85
86   my $number = $svc_phone->phonenum;
87   $number = $svc_phone->countrycode. $number
88     unless $svc_phone->countrycode eq '1';
89
90   #src & charged party as per voip_cdr.pm
91   #XXX handle toll free too
92
93   my $search = "charged_party_or_src=";
94
95   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
96
97   if ( $cust_pkg ) {
98
99     #XXX handle voip_inbound too
100
101     my @part_pkg = grep { $_->plan eq 'voip_cdr' }
102                         $cust_pkg->part_pkg->self_and_bill_linked;
103
104     foreach my $prefix (grep $_, map $_->option('default_prefix'), @part_pkg) {
105       $number .= ",$prefix$number";
106     }
107
108     $search = 'charged_party='
109       unless !@part_pkg || grep { ! $_->option('disable_src',1) } @part_pkg;
110
111   }
112
113   $search .= $number;
114
115   my @links = map {
116     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;$search;freesidestatus=$what{$_}">).
117     "View $_ CDRs</A>";
118   } keys(%what);
119
120   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
121                  'View incoming CDRs</A>' );
122
123   ###
124   # concatenate & return
125   ###
126
127   $e911.
128   $devices.
129   join(' | ', @links ). '<BR>'.
130   join(' | ', @ilinks). '<BR>';
131
132 };
133
134 </%init>