From 140b381af1008dad929b4d3b87aa1e54747d534f Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 25 Oct 2010 00:28:41 +0000 Subject: [PATCH] svc_pbx and whole-customer links to CDRs, RT#10315 --- httemplate/search/cdr.html | 33 +++++++------ httemplate/search/report_cdr.html | 84 ++++++++++++++++++++++++++++++++- httemplate/view/cust_main/packages.html | 4 +- httemplate/view/svc_pbx.cgi | 72 ++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 16 deletions(-) create mode 100644 httemplate/view/svc_pbx.cgi diff --git a/httemplate/search/cdr.html b/httemplate/search/cdr.html index 702dc1bcc..5544ff58c 100644 --- a/httemplate/search/cdr.html +++ b/httemplate/search/cdr.html @@ -147,7 +147,7 @@ foreach my $param ( grep /^termpart\d+status$/, $cgi->param ) { } ### -# src/dest/charged_party +# src/dest/charged_party/svcnum ### my $phonenum = qr/^\s*([\d\-\+\ ]+)\s*$/; @@ -175,27 +175,32 @@ if ( $cgi->param('dcontext') =~ /^\s*(.+)\s*$/ ) { push @search, "dcontext = '$dcontext'"; } -if ( $cgi->param('charged_party') =~ $phonenum ) { - ( my $charged_party = $1 ) =~ s/$x//g; - #$hashref->{'charged_party'} = $charged_party; - #push @search, "charged_party = '$charged_party'"; - #XXX countrycode +if ( $cgi->param('charged_party') ) { - my $search = " ( charged_party IN ('$charged_party', '1$charged_party') )"; + my @cp = map { $_, "1$_" } + split(/\s*,\s*/, $cgi->param('charged_party') ); + + my $search = 'charged_party IN ('. join(',', map dbh->quote($_), @cp). ')'; push @search, $search; push @qsearch, $search; } -if ( $cgi->param('charged_party_or_src') =~ $phonenum ) { - ( my $charged_party = $1 ) =~ s/$x//g; - #$hashref->{'charged_party'} = $charged_party; - #push @search, "charged_party = '$charged_party'"; - #XXX countrycode +if ( $cgi->param('charged_party_or_src') ) { - my $search = " ( charged_party IN ('$charged_party', '1$charged_party') - OR src IN ('$charged_party', '1$charged_party') )"; + my @cp = map { $_, "1$_" } + split(/\s*,\s*/, $cgi->param('charged_party_or_src') ); + my $in = join(',', map dbh->quote($_), @cp); + my $search = "( charged_party IN ($in) OR src IN ($in) )"; + + push @search, $search; + push @qsearch, $search; +} + +if ( $cgi->param('svcnum') =~ /^([\d, ]+)$/ ) { + my $svcnum = $1; + my $search = "svcnum IN ($svcnum)"; push @search, $search; push @qsearch, $search; } diff --git a/httemplate/search/report_cdr.html b/httemplate/search/report_cdr.html index a50e4db4c..866606cc1 100644 --- a/httemplate/search/report_cdr.html +++ b/httemplate/search/report_cdr.html @@ -65,7 +65,21 @@ Charged Party #: - + + + + + + Charged Party or Source #: + + + + + + + Freeside service #: + + @@ -145,4 +159,72 @@ my $names_list = [ map { @fields ]; +my @charged_party = (); +my @charged_party_or_src = (); +my @svcnum = (); +if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { + my $custnum = $1; + + my $cust_main = qsearchs( { + 'table' => 'cust_main', + 'hashref' => { 'custnum' => $custnum }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql, + }); + die "Customer not found!" unless $cust_main; + + #historical? + foreach my $cust_pkg ( $cust_main->ncancelled_pkgs ) { + + my @voip_pkgs = + grep { $_->plan eq 'voip_cdr' } $cust_pkg->part_pkg->self_and_bill_linked; + if ( scalar(@voip_pkgs) > 1 ) { + die "multiple voip_cdr packages bundled\n"; + } elsif ( !@voip_pkgs ) { + next; + } + my $voip_pkg = @voip_pkgs[0]; + + my $cdr_svc_method = $voip_pkg->option('cdr_svc_method') + || 'svc_phone.phonenum'; + + my @cust_svc = $cust_pkg->cust_svc; #historical? + + if ( $cdr_svc_method eq 'svc_phone.phonenum' ) { + + my @svc_phone = map $_->svc_x, + grep { $_->part_svc->svcdb eq 'svc_phone' } @cust_svc; + + my @numbers = map { + my $number = $_->phonenum; + $number = $_->countrycode. $number + unless $_->countrycode eq '1'; + $number; + } + @svc_phone; + + if ( $voip_pkg->option('disable_src') ) { + push @charged_party, @numbers; + } else { + push @charged_party_or_src, @numbers; + } + + } elsif ( $cdr_svc_method eq 'svc_pbx.title' ) { + my @svc_pbx = map $_->svc_x, + grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc; + push @charged_party, map $_->title, @svc_pbx; + } elsif ( $cdr_svc_method eq 'svc_pbx.svcnum' ) { + my @cust_svc_pbx = grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc; + push @svcnum, map $_->svcnum, @cust_svc_pbx; + } + + } + + die "No CDR packages for customer $custnum\n" + unless @charged_party || @charged_party_or_src || @svcnum; + + #die "Multiple matching metods for customer $custnum\n" + # if #there's more than one + +} + diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html index 811ac3c98..f0f156bf8 100755 --- a/httemplate/view/cust_main/packages.html +++ b/httemplate/view/cust_main/packages.html @@ -57,7 +57,9 @@ Current packages Package reports
Service reports: - accounts + accounts
+ Usage reports: + CDRs diff --git a/httemplate/view/svc_pbx.cgi b/httemplate/view/svc_pbx.cgi new file mode 100644 index 000000000..79cafed4d --- /dev/null +++ b/httemplate/view/svc_pbx.cgi @@ -0,0 +1,72 @@ +<% include('elements/svc_Common.html', + 'table' => 'svc_pbx', + 'edit_url' => $p."edit/svc_Common.html?svcdb=svc_pbx;svcnum=", + 'labels' => \%labels, + 'html_foot' => $html_foot, + ) +%> +<%init> + +my $fields = FS::svc_pbx->table_info->{'fields'}; +my %labels = map { $_ => ( ref($fields->{$_}) + ? $fields->{$_}{'label'} + : $fields->{$_} + ); + } + keys %$fields; + +my $html_foot = sub { + my $svc_pbx = shift; + + ## + # CDR links + ## + + tie my %what, 'Tie::IxHash', + 'pending' => 'NULL', + 'billed' => 'done', + ; + + #matching as per package def cdr_svc_method + my $cust_pkg = $svc_pbx->cust_svc->cust_pkg; + return '' unless $cust_pkg; + + my @voip_pkgs = + grep { $_->plan eq 'voip_cdr' } $cust_pkg->part_pkg->self_and_bill_linked; + if ( scalar(@voip_pkgs) > 1 ) { + warn "multiple voip_cdr packages bundled\n"; + return ''; + } elsif ( !@voip_pkgs ) { + warn "no voip_cdr packages\n"; + } + my $voip_pkg = @voip_pkgs[0]; + + my $cdr_svc_method = $voip_pkg->option('cdr_svc_method') + || 'svc_phone.phonenum'; + return '' unless $cdr_svc_method =~ /^svc_pbx\.(\w+)$/; + my $field = $1; + + my $search; + if ( $field eq 'title' ) { + $search = 'charged_party='. uri_escape($svc_pbx->title); + } elsif ( $field eq 'svcnum' ) { + $search = 'svcnum='. $svc_pbx->svcnum; + } else { + warn "unknown cdr_svc_method svc_pbx.$field"; + return ''; + } + + my @links = map { + qq(). + "View $_ CDRs"; + } keys(%what); + + ### + # concatenate & return + ### + + join(' | ', @links ). '
'; + +}; + + -- 2.11.0