Rate CDRs immediately, RT#15839
[freeside.git] / httemplate / search / report_cdr.html
index 744038d..e3418a7 100644 (file)
@@ -1,11 +1,19 @@
 <% include('/elements/header.html', 'Call Detail Record Search' ) %>
 
+<SCRIPT type="text/javascript">
+    function clearfield(which){
+        var f = document.getElementById(which);
+        if ( f == null) return;
+        f.value = '';
+    }
+</SCRIPT>
+
 <FORM ACTION="cdr.html" METHOD="GET">
 
 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
 
   <TR>
-    <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left">
+    <TH CLASS="background" COLSPAN=2 ALIGN="left">
       <FONT SIZE="+1">Search options</FONT>
     </TH>
   </TR>
     <TD ALIGN="right">Status: </TD>
     <TD>
       <SELECT NAME="freesidestatus">
-        <OPTION VALUE="">(all)
-        <OPTION VALUE="NULL">unprocessed
-        <OPTION VALUE="done">processed
+        <OPTION VALUE="">(all)</OPTION>
+        <OPTION VALUE="NULL">unprocessed</OPTION>
+        <OPTION VALUE="rated">prerated
+        <OPTION VALUE="done">processed</OPTION>
+        <OPTION VALUE="failed">skipped</OPTION>
       </SELECT>
     </TD>
   </TR>
 %   }
 % #}
 
+  <% include('/elements/tr-select-table.html',
+            field   => 'cdrtypenum',
+            label   => 'CDR Type',
+            table   => 'cdr_type',
+            name_col    => 'cdrtypename',
+            disable_empty   => 1,
+            pre_options => [    '',     'all', 
+                                'none', 'none' ] )
+  %>
+
   <% include ( '/elements/tr-input-beginning_ending.html' ) %>
 
   <TR>
   <TR>
     <TD ALIGN="right">Charged Party #: </TD>
     <TD>
-      <INPUT TYPE="text" NAME="charged_party">
+      <INPUT TYPE="text" NAME="charged_party" VALUE="<% join(',', @charged_party) |h %>">
+    </TD>
+  </TR>
+
+  <TR>
+    <TD ALIGN="right">Charged Party or Source #: </TD>
+    <TD>
+      <INPUT TYPE="text" NAME="charged_party_or_src" VALUE="<% join(',', @charged_party_or_src ) |h %>" >
+    </TD>
+  </TR>
+
+  <TR>
+    <TD ALIGN="right">Last Application: </TD>
+    <TD>
+      <INPUT TYPE="text" NAME="lastapp" VALUE="" >
+    </TD>
+  </TR>
+
+  <TR>
+    <TD ALIGN="right">Freeside service #: </TD>
+    <TD>
+      <INPUT TYPE="text" NAME="svcnum" VALUE="<% join(',', @svcnum ) %>" >
     </TD>
   </TR>
 
             )
   %>
 
+  <TR>
+    <TD ALIGN="right">Top</TD>
+    <TD><INPUT TYPE="TEXT" id="top_dst" NAME="top_dst" SIZE="7" onfocus="clearfield('top_src');"> destinations</TD>
+  </TR>
+  
+  <TR>
+    <TD ALIGN="right">Top</TD>
+    <TD><INPUT TYPE="TEXT" id="top_src" NAME="top_src" SIZE="7" onfocus="clearfield('top_dst');"> sources</TD>
+  </TR>
+  
+  <TR>
+    <TD ALIGN="right"></TD>
+    <TD><INPUT TYPE="TEXT" NAME="longest" SIZE="7"> longest calls</TD>
+  </TR>
+  
   <% include( '/elements/tr-select-cdrbatch.html' ) %>
 
   <TR>
   </TR>
 
   <TR>
-    <TH BGCOLOR="#e8e8e8" COLSPAN=2>&nbsp;</TH>
+    <TH CLASS="background" COLSPAN=2>&nbsp;</TH>
   </TR>
 
   <TR>
-    <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
+    <TH CLASS="background" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
   </TR>
 
   <INPUT TYPE="hidden" NAME="show" VALUE="1">
@@ -145,4 +201,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
+
+}
+
 </%init>