X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=FS%2FFS%2Fcdr.pm;h=ab87a6893de89f0145aa519135f83520d1d1112b;hb=a0b2c1a1ac9da3b33bc088dab0af77f6555428f7;hp=f0082279ea653302a330529142de09cdbe592804;hpb=d3c80e75b62421ea742cbe4547305227f8c10bea;p=freeside.git diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index f0082279e..ab87a6893 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -269,6 +269,17 @@ sub check { $self->SUPER::check; } +=item is_tollfree + + Returns true when the cdr represents a toll free number and false otherwise. + +=cut + +sub is_tollfree { + my $self = shift; + ( $self->dst =~ /^(\+?1)?8(8|([02-7])\3)/ ) ? 1 : 0; +} + =item set_charged_party If the charged_party field is already set, does nothing. Otherwise: @@ -284,9 +295,9 @@ or to the dst field if it is a toll free number. sub set_charged_party { my $self = shift; - unless ( $self->charged_party ) { + my $conf = new FS::Conf; - my $conf = new FS::Conf; + unless ( $self->charged_party ) { if ( $conf->exists('cdr-charged_party-accountcode') && $self->accountcode ){ @@ -294,7 +305,7 @@ sub set_charged_party { } else { - if ( $self->dst =~ /^(\+?1)?8[02-8]{2}/ ) { + if ( $self->is_tollfree ) { $self->charged_party($self->dst); } else { $self->charged_party($self->src); @@ -304,6 +315,14 @@ sub set_charged_party { } +# my $prefix = $conf->config('cdr-charged_party-truncate_prefix'); +# my $prefix_len = length($prefix); +# my $trunc_len = $conf->config('cdr-charged_party-truncate_length'); +# +# $self->charged_party( substr($self->charged_party, 0, $trunc_len) ) +# if $prefix_len && $trunc_len +# && substr($self->charged_party, 0, $prefix_len) eq $prefix; + } =item set_status_and_rated_price STATUS [ RATED_PRICE ] @@ -466,10 +485,19 @@ my %export_names = ( }, 'accountcode_default' => { 'name' => 'Default plus accountcode', - 'invoice_header' => 'Caller,Date,Time,Number,Destination,Duration,Price', + 'invoice_header' => 'Date,Time,Account,Number,Destination,Duration,Price', }, ); +my $duration_sub = sub { + my($cdr, %opt) = @_; + if ( $opt{minutes} ) { + $opt{minutes}. ( $opt{granularity} ? 'm' : ' call' ); + } else { + sprintf('%.2fm', $cdr->billsec / 60 ); + } +}; + my %export_formats = ( 'convergent' => [ 'carriername', #CARRIER @@ -491,7 +519,7 @@ my %export_formats = ( sub { time2str('%r', shift->calldate_unix ) }, #TIME 'userfield', #USER 'dst', #NUMBER_DIALED - sub { sprintf('%.2fm', shift->billsec / 60 ) }, #DURATION + $duration_sub, #DURATION #sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, #PRICE ], @@ -501,7 +529,7 @@ my %export_formats = ( #'userfield', #USER 'dst', #NUMBER_DIALED 'src', #called from - sub { sprintf('%.2fm', shift->billsec / 60 ) }, #DURATION + $duration_sub, #DURATION #sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, #PRICE ], @@ -522,9 +550,7 @@ my %export_formats = ( sub { my($cdr, %opt) = @_; $opt{dst_regionname}; }, #DURATION - sub { my($cdr, %opt) = @_; - $opt{minutes}. ( $opt{granularity} ? 'm' : ' call' ); - }, + $duration_sub, #PRICE sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, @@ -663,10 +689,11 @@ sub _cdr_min_parse { sub _cdr_date_parser_maker { my $field = shift; + my %options = @_; my @fields = ref($field) ? @$field : ($field); return sub { my( $cdr, $datestring ) = @_; - my $unixdate = eval { _cdr_date_parse($datestring) }; + my $unixdate = eval { _cdr_date_parse($datestring, %options) }; die "error parsing date for @fields from $datestring: $@\n" if $@; $cdr->$_($unixdate) foreach @fields; }; @@ -674,6 +701,7 @@ sub _cdr_date_parser_maker { sub _cdr_date_parse { my $date = shift; + my %options = @_; return '' unless length($date); #that's okay, it becomes NULL @@ -682,7 +710,7 @@ sub _cdr_date_parse { #$date =~ /^\s*(\d{4})[\-\/]\(\d{1,2})[\-\/](\d{1,2})\s+(\d{1,2}):(\d{1,2}):(\d{1,2})\s*$/ #taqua #2007-10-31 08:57:24.113000000 - if ( $date =~ /^\s*(\d{4})\D(\d{1,2})\D(\d{1,2})\s+(\d{1,2})\D(\d{1,2})\D(\d{1,2})(\D|$)/ ) { + if ( $date =~ /^\s*(\d{4})\D(\d{1,2})\D(\d{1,2})\D+(\d{1,2})\D(\d{1,2})\D(\d{1,2})(\D|$)/ ) { ($year, $mon, $day, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 ); } elsif ( $date =~ /^\s*(\d{1,2})\D(\d{1,2})\D(\d{4})\s+(\d{1,2})\D(\d{1,2})\D(\d{1,2})(\D|$)/ ) { ($mon, $day, $year, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 ); @@ -693,7 +721,11 @@ sub _cdr_date_parse { return '' if $year == 1900 && $mon == 1 && $day == 1 && $hour == 0 && $min == 0 && $sec == 0; - timelocal($sec, $min, $hour, $day, $mon-1, $year); + if ($options{gmt}) { + timegm($sec, $min, $hour, $day, $mon-1, $year); + } else { + timelocal($sec, $min, $hour, $day, $mon-1, $year); + } } =item batch_import HASHREF