optimize CDR rating after timed rate perf regression, RT#15739
[freeside.git] / httemplate / view / svc_pbx.cgi
1 <% include('elements/svc_Common.html',
2              'table'     => 'svc_pbx',
3              'edit_url'  => $p."edit/svc_Common.html?svcdb=svc_pbx;svcnum=",
4              'labels'    => \%labels,
5              'html_foot' => $html_foot,
6           )
7 %>
8 <%init>
9
10 my $fields = FS::svc_pbx->table_info->{'fields'};
11 my %labels = map { $_ =>  ( ref($fields->{$_})
12                              ? $fields->{$_}{'label'}
13                              : $fields->{$_}
14                          );
15                  }
16              keys %$fields;
17
18 my $html_foot = sub {
19   my $svc_pbx = shift;
20
21   ##
22   # CDR links
23   ##
24
25   tie my %what, 'Tie::IxHash',
26     'pending' => 'NULL',
27     'billed'  => 'done',
28   ;
29
30   #matching as per package def cdr_svc_method
31   my $cust_pkg = $svc_pbx->cust_svc->cust_pkg;
32   return '' unless $cust_pkg;
33
34   my @voip_pkgs =
35     grep { $_->plan eq 'voip_cdr' } $cust_pkg->part_pkg->self_and_bill_linked;
36   if ( scalar(@voip_pkgs) > 1 ) { 
37     warn "multiple voip_cdr packages bundled\n";
38     return '';
39   } elsif ( !@voip_pkgs ) {
40     warn "no voip_cdr packages\n";
41   }
42   my $voip_pkg = @voip_pkgs[0];
43
44   my $cdr_svc_method = $voip_pkg->option('cdr_svc_method')
45                        || 'svc_phone.phonenum';
46   return '' unless $cdr_svc_method =~ /^svc_pbx\.(\w+)$/;
47   my $field = $1;
48
49   my $search;
50   if ( $field eq 'title' ) {
51     $search = 'charged_party='. uri_escape($svc_pbx->title);
52   } elsif ( $field eq 'svcnum' ) {
53     $search = 'svcnum='. $svc_pbx->svcnum;
54   } else {
55     warn "unknown cdr_svc_method svc_pbx.$field";
56     return '';
57   }
58
59   my @links = map {
60     qq(<A HREF="${p}search/cdr.html?cdrbatchnum=__ALL__;$search;freesidestatus=$what{$_}">).
61     "View $_ CDRs</A>";
62   } keys(%what);
63
64   ###
65   # concatenate & return
66   ###
67
68   join(' | ', @links ). '<BR>';
69
70 };
71
72 </%init>