Merge branch 'patch-19' of https://github.com/gjones2/Freeside
[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   my $devices = include('/view/elements/svc_devices.html',
71                           'svc_x' => $svc_phone,
72                           'table' => 'phone_device',
73                        );
74
75   ##
76   # CDR links
77   ##
78
79   tie my %what, 'Tie::IxHash',
80     'pending' => 'NULL',
81     'billed'  => 'done',
82     'skipped' => 'failed',
83   ;
84
85   my $number = $svc_phone->phonenum;
86   $number = $svc_phone->countrycode. $number
87     unless $svc_phone->countrycode eq '1';
88
89   #src & charged party as per voip_cdr.pm
90   #XXX handle toll free too
91
92   my $search = "charged_party_or_src=";
93
94   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
95
96   if ( $cust_pkg ) {
97
98     #XXX handle voip_inbound too
99
100     my @part_pkg = grep { $_->plan eq 'voip_cdr' }
101                         $cust_pkg->part_pkg->self_and_bill_linked;
102
103     foreach my $prefix (grep $_, map $_->option('default_prefix'), @part_pkg) {
104       $number .= ",$prefix$number";
105     }
106
107     $search = 'charged_party='
108       unless !@part_pkg || grep { ! $_->option('disable_src',1) } @part_pkg;
109
110   }
111
112   $search .= $number;
113
114   my @links = map {
115     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;$search;freesidestatus=$what{$_}">).
116     "View $_ CDRs</A>";
117   } keys(%what);
118
119   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
120                  'View incoming CDRs</A>' );
121
122   ###
123   # concatenate & return
124   ###
125
126   $e911.
127   $devices.
128   join(' | ', @links ). '<BR>'.
129   join(' | ', @ilinks). '<BR>';
130
131 };
132
133 </%init>