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