stray closing /TABLE in the no-ticket case
[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
22 $labels{forward_svcnum} = mt('Route to service');
23 push @fields, { field => 'forward_svcnum',
24                 link => [ $p.'view/cust_svc.cgi?', 'forward_svcnum' ],
25                 value_callback => sub {
26                   my $self = shift;
27                   if ($self->forward_svcnum) {
28                     my $cust_svc = FS::cust_svc->by_key($self->forward_svcnum);
29                     if ( $cust_svc ) {
30                       return $cust_svc->svc_x->label;
31                     }
32                   }
33                   '';
34                 },
35               };
36
37
38 push @fields, qw( pbx_title );
39 $labels{pbx_title} = 'PBX';
40
41 if ( $conf->exists('showpasswords') ) {
42   push @fields, qw( sip_password );
43 } else {
44   push @fields, { 'field' => 'sip_password', #'_HIDDEN_sip_password',
45                   'type'  => 'fixed',
46                   'value' => '<I>('. mt('hidden') .')</I>',
47                 };
48 }
49
50 push @fields, qw( pin phone_name forwarddst email );
51
52 push @fields, { field => 'sms_carrierid', 
53                 #type=>'cdr_carrier',
54                 value_callback => sub {
55                   $_[0]->sms_carriername,
56                 },
57               },
58               'sms_account',
59               'max_simultaneous',
60 ;
61
62 if ( $conf->exists('svc_phone-lnp') ) {
63   push @fields, 'lnp_status',
64                 'lnp_reject_reason',
65                 { field => 'portable', type => 'checkbox', },
66                 'lrn',
67                 { field => 'lnp_desired_due_date', type => 'date', },
68                 { field => 'lnp_due_date', type => 'date', },
69                 'lnp_other_provider',
70                 'lnp_other_provider_account',
71   ;
72 }
73
74 $labels{circuit_label} = mt('Circuit');
75 push @fields, { field => 'circuit_label',
76                 link => [ $p.'view/svc_circuit.cgi?', 'circuit_svcnum' ]
77               };
78
79 push @fields, 'sip_server';
80
81 my $html_foot = sub {
82   my $svc_phone = shift;
83
84   ###
85   # E911 Info
86   ###
87
88   my $e911 = 
89     emt('E911 Information').
90     &ntable("#cccccc"). '<TR><TD>'. ntable("#cccccc",2).
91       '<TR><TD>'.emt('Location').'</TD>'.
92       '<TD BGCOLOR="#FFFFFF">'.
93         $svc_phone->location_label( 'join_string'     => '<BR>',
94                                     'double_space'    => ' &nbsp; ',
95                                     'escape_function' => \&encode_entities,
96                                     'countrydefault'  => $countrydefault,
97                                   ).
98       '</TD></TR>'.
99     '</TABLE></TD></TR></TABLE>'.
100     '<BR>'
101   ;
102
103   ###
104   # Devices
105   ###
106   #remove this when svc_phone isa device_Common, as elements/svc_Common will display it
107   my $devices = include('/view/elements/svc_devices.html',
108                           'svc_x' => $svc_phone,
109                           'table' => 'phone_device',
110                        );
111
112   my $status = include('/view/elements/svc_export_status.html', $svc_phone );
113
114   ##
115   # CDR links
116   ##
117
118   tie my %what, 'Tie::IxHash',
119     'pending' => 'NULL',
120     'billed'  => 'done',
121     'skipped' => 'failed',
122   ;
123
124   my $number = $svc_phone->phonenum;
125   $number = $svc_phone->countrycode. $number
126     unless $svc_phone->countrycode eq '1';
127
128   #src & charged party as per voip_cdr.pm
129   #XXX handle toll free too
130
131   my $search = "charged_party_or_src=";
132
133   my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
134
135   if ( $cust_pkg ) {
136
137     #XXX handle voip_inbound too
138
139     my @part_pkg = grep { $_->plan eq 'voip_cdr' }
140                         $cust_pkg->part_pkg->self_and_bill_linked;
141
142     foreach my $prefix (grep $_, map $_->option('default_prefix'), @part_pkg) {
143       $number .= ",$prefix$number";
144     }
145
146     $search = 'charged_party='
147       unless !@part_pkg || grep { ! $_->option('disable_src',1) } @part_pkg;
148
149   }
150
151   $search .= $number;
152
153   my @links = map {
154     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;$search;freesidestatus=$what{$_}">).
155     "View $_ CDRs</A>";
156   } keys(%what);
157
158   my @ilinks = ( qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;dst=$number">).
159                  'View incoming CDRs</A>' );
160
161   ###
162   # concatenate & return
163   ###
164
165   $e911.
166   #$devices.
167   $status.
168   join(' | ', @links ). '<BR>'.
169   join(' | ', @ilinks). '<BR>';
170
171 };
172
173 </%init>