- next if !$charge;
- $charges += $charge;
- my @call_details = ($cdr->downstream_csv( 'format' => $output_format,
- 'charge' => $charge,
- 'minutes' => $minutes,
- 'granularity' => $granularity,
- )
- );
- push @$details,
- [ 'C',
- $call_details[0],
- $charge,
- $cdr->calltypenum, #classnum
- $self->phonenum,
- $seconds,
- '', #regionname, not set for inbound calls
- ];
-
- my $error = $cdr->set_status_and_rated_price( 'done',
- $charge,
- $cust_svc->svcnum,
- 'inbound' => 1 );
- die $error if $error;
+
+ if ( $charge > 0 ) {
+ $charges += $charge;
+ my @call_details = (
+ $cdr->downstream_csv( 'format' => $output_format,
+ 'charge' => $charge,
+ 'seconds' => ($use_duration
+ ? $cdr->duration
+ : $cdr->billsec
+ ),
+ 'granularity' => $granularity,
+ )
+ );
+# push @$details,
+# { format => 'C',
+# detail => $call_details[0],
+# amount => $charge,
+# classnum => $cdr->calltypenum, #classnum
+# #phonenum => $self->phonenum,
+# accountcode => $cdr->accountcode,
+# startdate => $cdr->startdate,
+# duration => $seconds,
+# # regionname?? => '', #regionname, not set for inbound calls
+# };
+ }
+
+ # eventually use FS::cdr::rate for this
+ my $error = $cdr->set_status_and_rated_price(
+ 'done',
+ $charge,
+ $cust_svc->svcnum,
+ 'rated_seconds' => $use_duration ? $cdr->duration : $cdr->billsec,
+ 'rated_granularity' => $granularity,
+ 'rated_classnum' => $cdr->calltypenum,
+ 'inbound' => 1,
+ );
+ die $error if $error;
+ $formatter->append($cdr);
+
+ $cdr_search->adjust(1) if $cdr->freesidestatus eq '';