+ my $date = str2time($row->{'time'});
+ if ( $row->{'method'} eq 'INVITE' ) {
+ $cdr->startdate($date);
+ $cdr->src($src);
+ $cdr->dst($dst);
+ }
+ elsif ( $row->{'method'} eq 'ACK' ) {
+ $cdr->answerdate($date);
+ next if !check_cdr($cdr, $src, $dst);
+ }
+ elsif ( $row->{'method'} eq 'BYE' ) {
+ $cdr->enddate($date);
+ next if !check_cdr($cdr, $src, $dst);
+ }
+ if ( $cdr->startdate and $cdr->answerdate and $cdr->enddate ) {
+ $cdr->duration($cdr->enddate - $cdr->startdate);
+ $cdr->billsec($cdr->enddate - $cdr->answerdate);
+ my $error = $cdr->insert;
+ if($error) {
+ print "failed import: $error\n";