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="rated">prerated
28 <OPTION VALUE="done">processed</OPTION>
29 <OPTION VALUE="failed">skipped</OPTION>
34 % #if ( ) { # disable for everyone not using termination billing...
35 % foreach my $termpart ( 1..1 ) { #qsearch('part_termination
38 <TD ALIGN="right">Termination Status: </TD>
40 <SELECT NAME="termpart<%$termpart%>status">
41 <OPTION VALUE="">(all)
42 <OPTION VALUE="NULL">unprocessed
43 <OPTION VALUE="done">processed
51 <% include('/elements/tr-select-table.html',
52 field => 'cdrtypenum',
55 name_col => 'cdrtypename',
57 pre_options => [ '', 'all',
61 <% include ( '/elements/tr-input-beginning_ending.html' ) %>
64 <TD ALIGN="right">Source #: </TD>
66 <INPUT TYPE="text" NAME="src">
71 <TD ALIGN="right">Destination #: </TD>
73 <INPUT TYPE="text" NAME="dst">
78 <TD ALIGN="right">Destination Context: </TD>
80 <INPUT TYPE="text" NAME="dcontext">
86 <TD ALIGN="right">Charged Party #: </TD>
88 <INPUT TYPE="text" NAME="charged_party" VALUE="<% join(',', @charged_party) |h %>">
93 <TD ALIGN="right">Charged Party or Source #: </TD>
95 <INPUT TYPE="text" NAME="charged_party_or_src" VALUE="<% join(',', @charged_party_or_src ) |h %>" >
100 <TD ALIGN="right">Last Application: </TD>
102 <INPUT TYPE="text" NAME="lastapp" VALUE="" >
107 <TD ALIGN="right">Freeside service #: </TD>
109 <INPUT TYPE="text" NAME="svcnum" VALUE="<% join(',', @svcnum ) %>" >
113 <% include( '/elements/tr-input-lessthan_greaterthan.html',
114 'label' => 'Duration (sec)',
115 'field' => 'duration',
119 <% include( '/elements/tr-input-lessthan_greaterthan.html',
120 'label' => 'Billable duration (sec)',
121 'field' => 'billsec',
126 <TD ALIGN="right">Top</TD>
127 <TD><INPUT TYPE="TEXT" id="top_dst" NAME="top_dst" SIZE="7" onfocus="clearfield('top_src');"> destinations</TD>
131 <TD ALIGN="right">Top</TD>
132 <TD><INPUT TYPE="TEXT" id="top_src" NAME="top_src" SIZE="7" onfocus="clearfield('top_dst');"> sources</TD>
136 <TD ALIGN="right"></TD>
137 <TD><INPUT TYPE="TEXT" NAME="longest" SIZE="7"> longest calls</TD>
140 <% include( '/elements/tr-select-cdrbatch.html' ) %>
143 <TD ALIGN="right">Acct ID (one per-line):</TD>
144 <TD><TEXTAREA NAME="acctid"></TEXTAREA></TD>
148 <TH CLASS="background" COLSPAN=2> </TH>
152 <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
155 <INPUT TYPE="hidden" NAME="show" VALUE="1">
159 <% include('/elements/checkboxes.html',
160 'names_list' => $names_list,
161 'element_name_prefix' => 'show_',
162 'checked_callback' => sub { $show_default{$_[1]} },
163 # my($cgi, $name) = @_;
172 <INPUT TYPE="submit" VALUE="Search Call Detail Records">
176 <% include('/elements/footer.html') %>
180 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
182 my @fields = fields('cdr');
183 my $labels = FS::cdr->table_info->{'fields'};
186 my @show_default = qw(
187 calldate clid src dst dcontext charged_party
188 startdate answerdate enddate duration billsec
189 disposition amaflags accountcode userfield
190 rated_price upstream_price carrierid
191 svcnum freesidestatus freesiderewritestatus
193 my %show_default = map { $_=>1 } @show_default;
195 my $names_list = [ map {
197 'label' => 'Show '. ( $labels->{$_} || $_ )
204 my @charged_party = ();
205 my @charged_party_or_src = ();
207 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
210 my $cust_main = qsearchs( {
211 'table' => 'cust_main',
212 'hashref' => { 'custnum' => $custnum },
213 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
215 die "Customer not found!" unless $cust_main;
218 foreach my $cust_pkg ( $cust_main->ncancelled_pkgs ) {
221 grep { $_->plan eq 'voip_cdr' } $cust_pkg->part_pkg->self_and_bill_linked;
222 if ( scalar(@voip_pkgs) > 1 ) {
223 die "multiple voip_cdr packages bundled\n";
224 } elsif ( !@voip_pkgs ) {
227 my $voip_pkg = @voip_pkgs[0];
229 my $cdr_svc_method = $voip_pkg->option('cdr_svc_method')
230 || 'svc_phone.phonenum';
232 my @cust_svc = $cust_pkg->cust_svc; #historical?
234 if ( $cdr_svc_method eq 'svc_phone.phonenum' ) {
236 my @svc_phone = map $_->svc_x,
237 grep { $_->part_svc->svcdb eq 'svc_phone' } @cust_svc;
240 my $number = $_->phonenum;
241 $number = $_->countrycode. $number
242 unless $_->countrycode eq '1';
247 if ( $voip_pkg->option('disable_src') ) {
248 push @charged_party, @numbers;
250 push @charged_party_or_src, @numbers;
253 } elsif ( $cdr_svc_method eq 'svc_pbx.title' ) {
254 my @svc_pbx = map $_->svc_x,
255 grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc;
256 push @charged_party, map $_->title, @svc_pbx;
257 } elsif ( $cdr_svc_method eq 'svc_pbx.svcnum' ) {
258 my @cust_svc_pbx = grep { $_->part_svc->svcdb eq 'svc_pbx' } @cust_svc;
259 push @svcnum, map $_->svcnum, @cust_svc_pbx;
264 die "No CDR packages for customer $custnum\n"
265 unless @charged_party || @charged_party_or_src || @svcnum;
267 #die "Multiple matching metods for customer $custnum\n"
268 # if #there's more than one