X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=2426f4191c87035d8cb4ccf3a59bd9f58dc25ad2;hb=7b125e587a4d1ee0aca692e23ea7897f671855ae;hp=34243fae98ece6b3a09ee3be497615e50783cc54;hpb=8d40a4a4e914bd2003dd6443c2056d57d0aaaeff;p=freeside.git diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 34243fae9..2426f4191 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -285,10 +285,6 @@ sub check { # ; # return $error if $error; - for my $f ( grep { $self->$_ =~ /[a-z ]/i } qw( startdate enddate ) ) { - $self->$f( str2time($self->$f) ); - } - $self->calldate( $self->startdate_sql ) if !$self->calldate && $self->startdate; @@ -324,19 +320,15 @@ sub check { $self->SUPER::check; } -=item is_tollfree [ COLUMN ] - -Returns true when the cdr represents a toll free number and false otherwise. +=item is_tollfree -By default, inspects the dst field, but an optional column name can be passed -to inspect other field. + Returns true when the cdr represents a toll free number and false otherwise. =cut sub is_tollfree { my $self = shift; - my $field = scalar(@_) ? shift : 'dst'; - ( $self->$field() =~ /^(\+?1)?8(8|([02-7])\3)/ ) ? 1 : 0; + ( $self->dst =~ /^(\+?1)?8(8|([02-7])\3)/ ) ? 1 : 0; } =item set_charged_party @@ -365,11 +357,6 @@ sub set_charged_party { if $conf->exists('cdr-charged_party-accountcode-trim_leading_0s'); $self->charged_party( $charged_party ); - } elsif ( $conf->exists('cdr-charged_party-field') ) { - - my $field = $conf->config('cdr-charged_party-field'); - $self->charged_party( $self->$field() ); - } else { if ( $self->is_tollfree ) { @@ -539,86 +526,73 @@ my %export_names = ( }, ); -my %export_formats = (); -sub export_formats { - #my $self = shift; - - return %export_formats if keys %export_formats; - - my $conf = new FS::Conf; - my $date_format = $conf->config('date_format') || '%m/%d/%Y'; - - my $duration_sub = sub { - my($cdr, %opt) = @_; - if ( $opt{minutes} ) { - $opt{minutes}. ( $opt{granularity} ? 'm' : ' call' ); - } else { - #config if anyone really wants decimal minutes back - #sprintf('%.2fm', $cdr->billsec / 60 ); - int($cdr->billsec / 60).'m '. ($cdr->billsec % 60).'s'; - } - }; - - %export_formats = ( - 'simple' => [ - sub { time2str($date_format, shift->calldate_unix ) }, #DATE - sub { time2str('%r', shift->calldate_unix ) }, #TIME - 'userfield', #USER - 'dst', #NUMBER_DIALED - $duration_sub, #DURATION - #sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE - sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, #PRICE - ], - 'simple2' => [ - sub { time2str($date_format, shift->calldate_unix ) }, #DATE - sub { time2str('%r', shift->calldate_unix ) }, #TIME - #'userfield', #USER - 'src', #called from - 'dst', #NUMBER_DIALED - $duration_sub, #DURATION - #sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE - sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, #PRICE - ], - 'default' => [ - - #DATE - sub { time2str($date_format, shift->calldate_unix ) }, - # #time2str("%Y %b %d - %r", $cdr->calldate_unix ), - - #TIME - sub { time2str('%r', shift->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 - - #DEST ("Number") - sub { my($cdr, %opt) = @_; $opt{pretty_dst} || $cdr->dst; }, - - #REGIONNAME ("Destination") - sub { my($cdr, %opt) = @_; $opt{dst_regionname}; }, - - #DURATION - $duration_sub, - - #PRICE - sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, - - ], - ); - $export_formats{'source_default'} = [ 'src', @{ $export_formats{'default'} }, ]; - $export_formats{'accountcode_default'} = - [ @{ $export_formats{'default'} }[0,1], - 'accountcode', - @{ $export_formats{'default'} }[2..5], - ]; - - %export_formats -} +my $duration_sub = sub { + my($cdr, %opt) = @_; + if ( $opt{minutes} ) { + $opt{minutes}. ( $opt{granularity} ? 'm' : ' call' ); + } else { + #config if anyone really wants decimal minutes back + #sprintf('%.2fm', $cdr->billsec / 60 ); + int($cdr->billsec / 60).'m '. ($cdr->billsec % 60).'s'; + } +}; + +my %export_formats = ( + 'simple' => [ + sub { time2str('%D', shift->calldate_unix ) }, #DATE + sub { time2str('%r', shift->calldate_unix ) }, #TIME + 'userfield', #USER + 'dst', #NUMBER_DIALED + $duration_sub, #DURATION + #sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE + sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, #PRICE + ], + 'simple2' => [ + sub { time2str('%D', shift->calldate_unix ) }, #DATE + sub { time2str('%r', shift->calldate_unix ) }, #TIME + #'userfield', #USER + 'src', #called from + 'dst', #NUMBER_DIALED + $duration_sub, #DURATION + #sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE + sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, #PRICE + ], + 'default' => [ + + #DATE + sub { time2str('%D', shift->calldate_unix ) }, + # #time2str("%Y %b %d - %r", $cdr->calldate_unix ), + + #TIME + sub { time2str('%r', shift->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 + + #DEST ("Number") + sub { my($cdr, %opt) = @_; $opt{pretty_dst} || $cdr->dst; }, + + #REGIONNAME ("Destination") + sub { my($cdr, %opt) = @_; $opt{dst_regionname}; }, + + #DURATION + $duration_sub, + + #PRICE + sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, + + ], +); +$export_formats{'source_default'} = [ 'src', @{ $export_formats{'default'} }, ]; +$export_formats{'accountcode_default'} = + [ @{ $export_formats{'default'} }[0,1], + 'accountcode', + @{ $export_formats{'default'} }[2..5], + ]; sub downstream_csv { my( $self, %opt ) = @_; my $format = $opt{'format'}; - my %formats = $self->export_formats; - return "Unknown format $format" unless exists $formats{$format}; + return "Unknown format $format" unless exists $export_formats{$format}; #my $conf = new FS::Conf; #$opt{'money_char'} ||= $conf->config('money_char') || '$'; @@ -632,7 +606,7 @@ sub downstream_csv { map { ref($_) ? &{$_}($self, %opt) : $self->$_(); } - @{ $formats{$format} }; + @{ $export_formats{$format} }; my $status = $csv->combine(@columns); die "FS::CDR: error combining ". $csv->error_input(). "into downstream CSV"