1 <% include('/elements/header.html', 'Call Detail Record Search' ) %>
3 <SCRIPT type="text/javascript">
4 function clearfield(which){
5 var f = document.getElementById(which);
6 if ( f == null) return;
11 <FORM ACTION="cdr.html" METHOD="GET">
13 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
16 <TH CLASS="background" COLSPAN=2 ALIGN="left">
17 <FONT SIZE="+1">Search options</FONT>
22 <TD ALIGN="right">Status: </TD>
24 <SELECT NAME="freesidestatus">
25 <OPTION VALUE="">(all)</OPTION>
26 <OPTION VALUE="NULL">unprocessed</OPTION>
27 <OPTION VALUE="done">processed</OPTION>
28 <OPTION VALUE="failed">skipped</OPTION>
33 % #if ( ) { # disable for everyone not using termination billing...
34 % foreach my $termpart ( 1..1 ) { #qsearch('part_termination
37 <TD ALIGN="right">Termination Status: </TD>
39 <SELECT NAME="termpart<%$termpart%>status">
40 <OPTION VALUE="">(all)
41 <OPTION VALUE="NULL">unprocessed
42 <OPTION VALUE="done">processed
50 <% include('/elements/tr-select-table.html',
51 field => 'cdrtypenum',
54 name_col => 'cdrtypename',
56 pre_options => [ '', 'all',
60 <% include ( '/elements/tr-input-beginning_ending.html' ) %>
63 <TD ALIGN="right">Source #: </TD>
65 <INPUT TYPE="text" NAME="src">
70 <TD ALIGN="right">Destination #: </TD>
72 <INPUT TYPE="text" NAME="dst">
77 <TD ALIGN="right">Destination Context: </TD>
79 <INPUT TYPE="text" NAME="dcontext">
85 <TD ALIGN="right">Charged Party #: </TD>
87 <INPUT TYPE="text" NAME="charged_party" VALUE="<% join(',', @charged_party) |h %>">
92 <TD ALIGN="right">Charged Party or Source #: </TD>
94 <INPUT TYPE="text" NAME="charged_party_or_src" VALUE="<% join(',', @charged_party_or_src ) |h %>" >
99 <TD ALIGN="right">Last Application: </TD>
101 <INPUT TYPE="text" NAME="lastapp" VALUE="" >
106 <TD ALIGN="right">Freeside service #: </TD>
108 <INPUT TYPE="text" NAME="svcnum" VALUE="<% join(',', @svcnum ) %>" >
112 <% include( '/elements/tr-input-lessthan_greaterthan.html',
113 'label' => 'Duration (sec)',
114 'field' => 'duration',
118 <% include( '/elements/tr-input-lessthan_greaterthan.html',
119 'label' => 'Billable duration (sec)',
120 'field' => 'billsec',
125 <TD ALIGN="right">Top</TD>
126 <TD><INPUT TYPE="TEXT" id="top_dst" NAME="top_dst" SIZE="7" onfocus="clearfield('top_src');"> destinations</TD>
130 <TD ALIGN="right">Top</TD>
131 <TD><INPUT TYPE="TEXT" id="top_src" NAME="top_src" SIZE="7" onfocus="clearfield('top_dst');"> sources</TD>
135 <TD ALIGN="right"></TD>
136 <TD><INPUT TYPE="TEXT" NAME="longest" SIZE="7"> longest calls</TD>
139 <% include( '/elements/tr-select-cdrbatch.html' ) %>
142 <TD ALIGN="right">Acct ID (one per-line):</TD>
143 <TD><TEXTAREA NAME="acctid"></TEXTAREA></TD>
147 <TH CLASS="background" COLSPAN=2> </TH>
151 <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
154 <INPUT TYPE="hidden" NAME="show" VALUE="1">
158 <% include('/elements/checkboxes.html',
159 'names_list' => $names_list,
160 'element_name_prefix' => 'show_',
161 'checked_callback' => sub { $show_default{$_[1]} },
162 # my($cgi, $name) = @_;
171 <INPUT TYPE="submit" VALUE="Search Call Detail Records">
175 <% include('/elements/footer.html') %>
179 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
181 my @fields = fields('cdr');
182 my $labels = FS::cdr->table_info->{'fields'};
185 my @show_default = qw(
186 calldate clid src dst dcontext charged_party
187 startdate answerdate enddate duration billsec
188 disposition amaflags accountcode userfield
189 rated_price upstream_price carrierid
190 svcnum freesidestatus freesiderewritestatus
192 my %show_default = map { $_=>1 } @show_default;
194 my $names_list = [ map {
196 'label' => 'Show '. ( $labels->{$_} || $_ )
203 my @charged_party = ();
204 my @charged_party_or_src = ();
206 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
209 my $cust_main = qsearchs( {
210 'table' => 'cust_main',
211 'hashref' => { 'custnum' => $custnum },
212 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
214 die "Customer not found!" unless $cust_main;
217 foreach my $cust_pkg ( $cust_main->ncancelled_pkgs ) {
220 grep { $_->plan eq 'voip_cdr' } $cust_pkg->part_pkg->self_and_bill_linked;
221 if ( scalar(@voip_pkgs) > 1 ) {
222 die "multiple voip_cdr packages bundled\n";
223 } elsif ( !@voip_pkgs ) {
226 my $voip_pkg = @voip_pkgs[0];
228 my $cdr_svc_method = $voip_pkg->option('cdr_svc_method')
229 || 'svc_phone.phonenum';
231 my @cust_svc = $cust_pkg->cust_svc; #historical?
233 if ( $cdr_svc_method eq 'svc_phone.phonenum' ) {
235 my @svc_phone = map $_->svc_x,
236 grep { $_->part_svc->svcdb eq 'svc_phone' } @cust_svc;
239 my $number = $_->phonenum;
240 $number = $_->countrycode. $number
241 unless $_->countrycode eq '1';
246 if ( $voip_pkg->option('disable_src') ) {
247 push @charged_party, @numbers;
249 push @charged_party_or_src, @numbers;
252 } elsif ( $cdr_svc_method eq 'svc_pbx.title' ) {
253 my @svc_pbx = map $_->svc_x,
254 grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc;
255 push @charged_party, map $_->title, @svc_pbx;
256 } elsif ( $cdr_svc_method eq 'svc_pbx.svcnum' ) {
257 my @cust_svc_pbx = grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc;
258 push @svcnum, map $_->svcnum, @cust_svc_pbx;
263 die "No CDR packages for customer $custnum\n"
264 unless @charged_party || @charged_party_or_src || @svcnum;
266 #die "Multiple matching metods for customer $custnum\n"
267 # if #there's more than one