Reverted menu-left-example.png back to original and cleaned up menu-top-example to...
[freeside.git] / FS / bin / freeside-cdr-a2billing-import
index 923f5fb..aa7fa4a 100755 (executable)
@@ -91,7 +91,7 @@ my %disposition = (
 );
 
 my @cols = (
-  'cc_call.id as id', 'cc_card.username as username',
+  "$table.id as id", 'cc_card.username as username',
   qw( sessionid
       starttime stoptime sessiontime real_sessiontime
       terminatecauseid
@@ -101,6 +101,7 @@ my @cols = (
 );
 
 my $sql = 'SELECT '.join(',', @cols). " FROM $table".
+  " LEFT JOIN cc_card ON ( $table.card_id = cc_card.id ) ".
   ' WHERE freesidestatus IS NULL' .
   ($start && " AND starttime >= '$start'") .
   ($end   && " AND starttime <  '$end'") ;
@@ -119,7 +120,13 @@ my $updates = 0;
 
 my $row;
 while ( $row = $sth->fetchrow_hashref ) {
-  $row->{calledstation} =~ s/^1//;
+  my $dst = $row->{calledstation};
+  my $dst_ip_addr = '';
+  if ($dst =~ m[^SIP/(\d+)@(.*)$] ) {
+    $dst = $1;
+    $dst_ip_addr = $2;
+  }
+  $dst =~ s/^1//;
   $row->{src} =~ s/^1//;
   my $cdr = FS::cdr->new ({
     uniqueid            => $row->{sessionid},
@@ -128,8 +135,10 @@ while ( $row = $sth->fetchrow_hashref ) {
     enddate             => time2str($row->{stoptime}),
     duration            => $row->{sessiontime},
     billsec             => $row->{real_sessiontime},
-    dst                 => $row->{calledstation},
+    dst                 => $dst,
     src                 => $row->{src},
+    dst_ip_addr         => $dst_ip_addr,
+    dstchannel          => $row->{calledstation},
     charged_party       => $row->{username},
     upstream_rateplanid => $row->{id_tariffplan},
     upstream_rateid     => $row->{id_ratecard}, # I think?