- ###
- # find the price and add detail to the invoice
- ###
-
- # if $rate_detail is not found, skip this CDR... i.e.
- # don't add it to invoice, don't set its status to NULL,
- # don't call downstream_csv or something on it...
- # but DO emit a warning...
- #if ( ! $rate_detail && ! scalar(@call_details) ) {}
- if ( ! $rate_detail && $charge eq '' ) {
-
- warn "no rate_detail found for CDR.acctid: ". $cdr->acctid.
- "; skipping\n"
-
- } else { # there *is* a rate_detail (or call_details), proceed...
-
- unless ( @call_details || ( $charge ne '' && $charge == 0 ) ) {
-
- $included_min{$regionnum} = $rate_detail->min_included
- unless exists $included_min{$regionnum};
-
- my $granularity = $rate_detail->sec_granularity;
-
- # length($cdr->billsec) ? $cdr->billsec : $cdr->duration;
- my $seconds = $self->option('use_duration')
- ? $cdr->duration
- : $cdr->billsec;
-
- $seconds += $granularity - ( $seconds % $granularity )
- if $seconds # don't granular-ize 0 billsec calls (bills them)
- && $granularity; # 0 is per call
- my $minutes = sprintf("%.1f", $seconds / 60);
- $minutes =~ s/\.0$// if $granularity == 60;
-
- # per call rather than per minute
- $minutes = 1 unless $granularity;
-
- $included_min{$regionnum} -= $minutes;
-
- if ( $included_min{$regionnum} < 0 ) {
- my $charge_min = 0 - $included_min{$regionnum};
- $included_min{$regionnum} = 0;
- $charge = sprintf('%.2f', $rate_detail->min_charge * $charge_min );
- $charges += $charge;
- }
-
- # this is why we need regionnum/rate_region....
- warn " (rate region $rate_region)\n" if $DEBUG;
-
- @call_details = (
- #time2str("%Y %b %d - %r", $cdr->calldate_unix ),
- time2str("%c", $cdr->calldate_unix), #XXX this should probably be a config option dropdown so they can select US vs- rest of world dates or whatnot
- $granularity ? $minutes.'m' : $minutes.' call',
- '$'.$charge,
- $pretty_destnum,
- $rate_region->regionname,
- );
-
- $classnum = $rate_detail->classnum;
-
- }
-
- if ( $charge > 0 ) {
- #just use FS::cust_bill_pkg_detail objects?
- my $call_details;
- if ( $self->option('rating_method') eq 'upstream_simple' ) {
- $call_details = [ 'C', $call_details[0], $charge, $classnum ];
- }else{
- $csv->combine(@call_details);
- $call_details = [ 'C', $csv->string, $charge, $classnum ];
- }
- warn " adding details on charge to invoice: [ ".
- join(', ', @{$call_details} ). " ]"
- if ( $DEBUG && ref($call_details) );
- push @$details, $call_details; #\@call_details,
- }
-
- # if the customer flag is on, call "downstream_csv" or something
- # like it to export the call downstream!
- # XXX price plan option to pick format, or something...
- $downstream_cdr .= $cdr->downstream_csv( 'format' => 'convergent' )
- if $spool_cdr;
-
- my $error = $cdr->set_status_and_rated_price('done', $charge);
- die $error if $error;