X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=ff07a59ee11d7af1595adae0c6c7e9cb875a55ba;hb=e81fcc3454632f6a60173a139cb6be268658c4ea;hp=0fc16587fa1c329589c2e5d99e577b3359758df4;hpb=5b73387992a96f7b80e40b5ecb2fedabd8a78d6b;p=freeside.git diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 0fc16587f..ff07a59ee 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -1,12 +1,16 @@ package FS::cdr; use strict; -use vars qw( @ISA @EXPORT_OK $DEBUG $me ); +use vars qw( @ISA @EXPORT_OK $DEBUG $me + $conf $cdr_prerate %cdr_prerate_cdrtypenums + ); use Exporter; +use List::Util qw(first min); use Tie::IxHash; use Date::Parse; use Date::Format; use Time::Local; +use List::Util qw( first min ); use FS::UID qw( dbh ); use FS::Conf; use FS::Record qw( qsearch qsearchs ); @@ -25,6 +29,17 @@ use FS::rate_detail; $DEBUG = 0; $me = '[FS::cdr]'; +#ask FS::UID to run this stuff for us later +FS::UID->install_callback( sub { + $conf = new FS::Conf; + + my @cdr_prerate_cdrtypenums; + $cdr_prerate = $conf->exists('cdr-prerate'); + @cdr_prerate_cdrtypenums = $conf->config('cdr-prerate-cdrtypenums') + if $cdr_prerate; + %cdr_prerate_cdrtypenums = map { $_=>1 } @cdr_prerate_cdrtypenums; +}); + =head1 NAME FS::cdr - Object methods for cdr records @@ -412,7 +427,9 @@ sub set_status { Sets the status and rated price. -Available options are: inbound, rated_seconds, rated_minutes, rated_classnum, rated_ratename +Available options are: inbound, rated_pretty_dst, rated_regionname, +rated_seconds, rated_minutes, rated_granularity, rated_ratedetailnum, +rated_classnum, rated_ratename. If there is an error, returns the error, otherwise returns false. @@ -675,8 +692,11 @@ sub rate_prefix { if ( !exists($interval_cache{$regionnum}) ) { my @intervals = ( sort { $a->stime <=> $b->stime } - map { my $r = $_->rate_time; $r ? $r->intervals : () } - $rate->rate_detail + map { $_->rate_time->intervals } + qsearch({ 'table' => 'rate_detail', + 'hashref' => { 'ratenum' => $rate->ratenum }, + 'extra_sql' => 'AND ratetimenum IS NOT NULL', + }) ); $interval_cache{$regionnum} = \@intervals; warn " cached ".scalar(@intervals)." interval(s)\n" @@ -819,10 +839,12 @@ sub rate_prefix { sub rate_upstream_simple { my( $self, %opt ) = @_; - $self->set_status_and_rated_price( 'rated', - sprintf('%.3f', $self->upstream_price), - $opt{'svcnum'}, - ); + $self->set_status_and_rated_price( + 'rated', + sprintf('%.3f', $self->upstream_price), + $opt{'svcnum'}, + 'rated_classnum' => $self->calltypenum, + ); } sub rate_single_price { @@ -860,10 +882,13 @@ sub rate_single_price { sprintf('%.4f', ( $part_pkg->option_cacheable('min_charge') * $charge_min ) + 0.0000000001 ); #so 1.00005 rounds to 1.0001 - $self->set_status_and_rated_price( 'rated', - $charge, - $opt{'svcnum'}, - ); + $self->set_status_and_rated_price( + 'rated', + $charge, + $opt{'svcnum'}, + 'rated_granularity' => $granularity, + 'rated_seconds' => $seconds, + ); } @@ -1007,13 +1032,17 @@ my %export_names = ( 'invoice_header' => 'Caller,Date,Time,Number,Destination,Duration,Price', }, 'sum_duration' => { - 'name' => 'Summary (one line per service, with duration)', + 'name' => 'Summary, one line per service', 'invoice_header' => 'Caller,Rate,Calls,Minutes,Price', }, 'sum_count' => { - 'name' => 'Summary (one line per service, with count)', + 'name' => 'Number of calls, one line per service', 'invoice_header' => 'Caller,Rate,Messages,Price', }, + 'sum_duration_prefix' => { + 'name' => 'Summary, one line per destination prefix', + 'invoice_header' => 'Caller,Rate,Calls,Minutes,Price', + }, ); my %export_formats = (); @@ -1202,6 +1231,8 @@ as keys (for use with part_pkg::voip_cdr) and "pretty" format names as values. =cut +# in the future, load this dynamically from detail_format classes + sub invoice_formats { map { ($_ => $export_names{$_}->{'name'}) } grep { $export_names{$_}->{'invoice_header'} } @@ -1228,6 +1259,7 @@ CDR reprocessing. sub clear_status { my $self = shift; + my %opt = @_; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -1240,7 +1272,17 @@ sub clear_status { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - $self->freesidestatus(''); + if ( $cdr_prerate && $cdr_prerate_cdrtypenums{$self->cdrtypenum} + && $self->rated_ratedetailnum #avoid putting old CDRs back in "rated" + && $self->freesidestatus eq 'done' + && ! $opt{'rerate'} + ) + { #special case + $self->freesidestatus('rated'); + } else { + $self->freesidestatus(''); + } + my $error = $self->replace; if ( $error ) { $dbh->rollback if $oldAutoCommit;