X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=dc94bcf6230194fb4ff31c86453ff8efab6073da;hb=7d0b690f5684cdfdcd68d25568a101f6b088ad98;hp=c2a3d00ee1b55aec8d8b714a0c0467d82c7da915;hpb=1cf39475a4ba90ed0aa49ed983542077e4609c22;p=freeside.git diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index c2a3d00ee..dc94bcf62 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -436,11 +436,11 @@ my %export_names = ( }, 'default' => { 'name' => 'Default', - 'invoice_header' => 'Date,Time,Duration,Price,Number,Destination', + 'invoice_header' => 'Date,Time,Number,Destination,Duration,Price', }, 'source_default' => { 'name' => 'Default with source', - 'invoice_header' => 'Caller,Date,Time,Duration,Number,Destination,Price', + 'invoice_header' => 'Caller,Date,Time,Number,Destination,Duration,Price', }, ); @@ -466,7 +466,8 @@ my %export_formats = ( 'userfield', #USER 'dst', #NUMBER_DIALED sub { sprintf('%.2fm', shift->billsec / 60 ) }, #DURATION - sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE + #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 @@ -475,7 +476,8 @@ my %export_formats = ( 'dst', #NUMBER_DIALED 'src', #called from sub { sprintf('%.2fm', shift->billsec / 60 ) }, #DURATION - sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE + #sub { sprintf('%.3f', shift->upstream_price ) }, #PRICE + sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, #PRICE ], 'default' => [ @@ -487,6 +489,12 @@ my %export_formats = ( 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 sub { my($cdr, %opt) = @_; $opt{minutes}. ( $opt{granularity} ? 'm' : ' call' ); @@ -495,19 +503,9 @@ my %export_formats = ( #PRICE sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; }, - #DEST ("Number") - sub { my($cdr, %opt) = @_; $opt{pretty_dst} || $cdr->dst; }, - - #REGIONNAME ("Destination") - sub { my($cdr, %opt) = @_; $opt{dst_regionname}; }, - ], ); -$export_formats{'source_default'} = [ 'src', - @{ $export_formats{'default'} }[0..2], - @{ $export_formats{'default'} }[4..5], - @{ $export_formats{'default'} }[3], - ]; +$export_formats{'source_default'} = [ 'src', @{ $export_formats{'default'} }, ]; sub downstream_csv { my( $self, %opt ) = @_; @@ -634,11 +632,12 @@ sub _cdr_min_parse { sub _cdr_date_parser_maker { my $field = shift; + my @fields = ref($field) ? @$field : ($field); return sub { - my( $cdr, $date ) = @_; - #$cdr->$field( _cdr_date_parse($date) ); - eval { $cdr->$field( _cdr_date_parse($date) ); }; - die "error parsing date for $field from $date: $@\n" if $@; + my( $cdr, $datestring ) = @_; + my $unixdate = eval { _cdr_date_parse($datestring) }; + die "error parsing date for @fields from $datestring: $@\n" if $@; + $cdr->$_($unixdate) foreach @fields; }; } @@ -672,43 +671,73 @@ Imports CDR records. Available options are: =over 4 -=item filehandle +=item file + +Filename =item format +=item params + +Hash reference of preset fields, typically cdrbatch + +=item empty_ok + +Set true to prevent throwing an error on empty imports + =back =cut -sub process_batch_import { - my $job = shift; +my %import_options = ( + 'table' => 'cdr', - my $opt = { - 'table' => 'cdr', - 'params' => [ 'format', 'cdrbatch' ], + 'formats' => { map { $_ => $cdr_info{$_}->{'import_fields'}; } + keys %cdr_info + }, - 'formats' => { map { $_ => $cdr_info{$_}->{'import_fields'}; } - keys %cdr_info - }, + #drop the || 'csv' to allow auto xls for csv types? + 'format_types' => { map { $_ => ( lc($cdr_info{$_}->{'type'}) || 'csv' ); } + keys %cdr_info + }, - #drop the || 'csv' to allow auto xls for csv types? - 'format_types' => { map { $_ => ( lc($cdr_info{$_}->{'type'}) || 'csv' ); } + 'format_headers' => { map { $_ => ( $cdr_info{$_}->{'header'} || 0 ); } keys %cdr_info }, - 'format_headers' => { map { $_ => ( $cdr_info{$_}->{'header'} || 0 ); } + 'format_sep_chars' => { map { $_ => $cdr_info{$_}->{'sep_char'}; } keys %cdr_info }, - 'format_sep_chars' => { map { $_ => $cdr_info{$_}->{'sep_char'}; } - keys %cdr_info - }, + 'format_fixedlength_formats' => + { map { $_ => $cdr_info{$_}->{'fixedlength_format'}; } + keys %cdr_info + }, +); - 'format_fixedlength_formats' => - { map { $_ => $cdr_info{$_}->{'fixedlength_format'}; } - keys %cdr_info - }, - }; +sub _import_options { + \%import_options; +} + +sub batch_import { + my $opt = shift; + + my $iopt = _import_options; + $opt->{$_} = $iopt->{$_} foreach keys %$iopt; + + FS::Record::batch_import( $opt ); + +} + +=item process_batch_import + +=cut + +sub process_batch_import { + my $job = shift; + + my $opt = _import_options; + $opt->{'params'} = [ 'format', 'cdrbatch' ]; FS::Record::process_batch_import( $job, $opt, @_ );