X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=27db89e40859f34556359e58a8c9ca1c10003924;hb=94babe5baffcfeac78d5bf770a839abc85803b6a;hp=439d5ae697538c0f47786b45041506cfc72490fa;hpb=86e1a9e1f213150b76a6a2495f7908ea155e5e95;p=freeside.git diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 439d5ae69..27db89e40 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -8,6 +8,7 @@ use Date::Parse; use Date::Format; use Time::Local; use FS::UID qw( dbh ); +use FS::Conf; use FS::Record qw( qsearch qsearchs ); use FS::cdr_type; use FS::cdr_calltype; @@ -129,6 +130,8 @@ following fields are currently supported: =item freesidestatus - NULL, done (or something) +=item cdrbatch + =back =head1 METHODS @@ -231,12 +234,24 @@ sub check { $self->calldate( $self->startdate_sql ) if !$self->calldate && $self->startdate; + my $conf = new FS::Conf; + unless ( $self->charged_party ) { - if ( $self->dst =~ /^(\+?1)?8[02-8]{2}/ ) { - $self->charged_party($self->dst); + + if ( $conf->exists('cdr-charged_party-accountcode') && $self->accountcode ){ + + $self->charged_party( $self->accountcode ); + } else { - $self->charged_party($self->src); + + if ( $self->dst =~ /^(\+?1)?8[02-8]{2}/ ) { + $self->charged_party($self->dst); + } else { + $self->charged_party($self->src); + } + } + } #check the foreign keys even? @@ -244,14 +259,16 @@ sub check { my $error = $self->ut_numbern('acctid') - #Usage = 1, S&E = 7, OC&C = 8 - || $self->ut_foreign_keyn('cdrtypenum', 'cdr_type', 'cdrtypenum' ) - - #the big list in appendix 2 - || $self->ut_foreign_keyn('calltypenum', 'cdr_calltype', 'calltypenum' ) - - # Telstra =1, Optus = 2, RSL COM = 3 - || $self->ut_foreign_keyn('carrierid', 'cdr_carrier', 'carrierid' ) + #add a config option to turn these back on if someone needs 'em + # + # #Usage = 1, S&E = 7, OC&C = 8 + # || $self->ut_foreign_keyn('cdrtypenum', 'cdr_type', 'cdrtypenum' ) + # + # #the big list in appendix 2 + # || $self->ut_foreign_keyn('calltypenum', 'cdr_calltype', 'calltypenum' ) + # + # # Telstra =1, Optus = 2, RSL COM = 3 + # || $self->ut_foreign_keyn('carrierid', 'cdr_carrier', 'carrierid' ) ; return $error if $error; @@ -399,15 +416,23 @@ sub _convergent_format { my %export_names = ( 'convergent' => {}, - 'simple' => { 'name' => 'Simple', - 'invoice_header' => - "Date,Time,Name,Destination,Duration,Price", - }, - 'simple2' => { 'name' => 'Simple with source', - 'invoice_header' => - #"Date,Time,Name,Called From,Destination,Duration,Price", - "Date,Time,Called From,Destination,Duration,Price", - }, + 'simple' => { + 'name' => 'Simple', + 'invoice_header' => "Date,Time,Name,Destination,Duration,Price", + }, + 'simple2' => { + 'name' => 'Simple with source', + 'invoice_header' => "Date,Time,Called From,Destination,Duration,Price", + #"Date,Time,Name,Called From,Destination,Duration,Price", + }, + 'default' => { + 'name' => 'Default', + 'invoice_header' => 'Date,Time,Duration,Price,Number,Destination', + }, + 'source_default' => { + 'name' => 'Default with source', + 'invoice_header' => 'Caller,Date,Time,Duration,Price,Number,Destination', + }, ); my %export_formats = ( @@ -443,7 +468,33 @@ my %export_formats = ( sub { sprintf('%.2fm', shift->billsec / 60 ) }, #DURATION sub { sprintf('%.3f', shift->upstream_price ) }, #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 + + #DURATION + sub { my($cdr, %opt) = @_; + $opt{minutes}. ( $opt{granularity} ? 'm' : ' call' ); + }, + + #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'} } ]; sub downstream_csv { my( $self, %opt ) = @_; @@ -451,13 +502,17 @@ sub downstream_csv { my $format = $opt{'format'}; # 'convergent'; return "Unknown format $format" unless exists $export_formats{$format}; + #my $conf = new FS::Conf; + #$opt{'money_char'} ||= $conf->config('money_char') || '$'; + $opt{'money_char'} ||= FS::Conf->new->config('money_char') || '$'; + eval "use Text::CSV_XS;"; die $@ if $@; my $csv = new Text::CSV_XS; my @columns = map { - ref($_) ? &{$_}($self) : $self->$_(); + ref($_) ? &{$_}($self, %opt) : $self->$_(); } @{ $export_formats{$format} }; @@ -550,7 +605,7 @@ sub import_formats { sub _cdr_min_parser_maker { my $field = shift; my @fields = ref($field) ? @$field : ($field); - @fields = qw( billsec duration ) unless scalar(@fields); + @fields = qw( billsec duration ) unless scalar(@fields) && $fields[0]; return sub { my( $cdr, $min ) = @_; my $sec = eval { _cdr_min_parse($min) }; @@ -617,6 +672,7 @@ sub batch_import { my $fh = $param->{filehandle}; my $format = $param->{format}; + my $cdrbatch = $param->{cdrbatch}; return "Unknown format $format" unless exists( $cdr_info{$format} ) @@ -630,7 +686,11 @@ sub batch_import { if ( $type eq 'csv' ) { eval "use Text::CSV_XS;"; die $@ if $@; - $parser = new Text::CSV_XS; + my %attr = (); + foreach ( grep exists($info->{$_}), qw( sep_char ) ) { + $attr{$_} = $info->{$_}; + } + $parser = new Text::CSV_XS \%attr; } elsif ( $type eq 'fixedlength' ) { eval "use Parse::FixedLength;"; die $@ if $@; @@ -699,6 +759,8 @@ sub batch_import { } @{ $info->{'import_fields'} } ; + + $cdr{cdrbatch} = $cdrbatch; my $cdr = new FS::cdr ( \%cdr ); @@ -732,7 +794,7 @@ sub batch_import { $dbh->commit or die $dbh->errstr if $oldAutoCommit; #might want to disable this if we skip records for any reason... - return "Empty file!" unless $imported; + return "Empty file!" unless $imported || $param->{empty_ok}; '';