fix fallout from: (refactor svc_phone to use elements/svc_devices.html) add dsl_devic...
[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   ;
72
73   my $number = $svc_phone->phonenum;
74   $number = $svc_phone->countrycode. $number
75     unless $svc_phone->countrycode eq '1';
76
77   #src & charged party as per voip_cdr.pm
78   #XXX handle toll free too
79
80   my $search = "charged_party_or_src=";
81
82   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
83
84   if ( $cust_pkg ) {
85
86     #XXX handle voip_inbound too
87
88     my @part_pkg = grep { $_->plan eq 'voip_cdr' }
89                         $cust_pkg->part_pkg->self_and_bill_linked;
90
91     foreach my $prefix (grep $_, map $_->option('default_prefix'), @part_pkg) {
92       $number .= ",$prefix$number";
93     }
94
95     $search = 'charged_party='
96       unless !@part_pkg || grep { ! $_->option('disable_src',1) } @part_pkg;
97
98   }
99
100   $search .= $number;
101
102   my @links = map {
103     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;$search;freesidestatus=$what{$_}">).
104     "View $_ CDRs</A>";
105   } keys(%what);
106
107   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
108                  'View incoming CDRs</A>' );
109
110   ###
111   # concatenate & return
112   ###
113
114   $e911.
115   $devices.
116   join(' | ', @links ). '<BR>'.
117   join(' | ', @ilinks). '<BR>';
118
119 };
120
121 </%init>