X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=bddd1bf510bf904f6d4c89d7f1279f48c17704f1;hb=1748e50c012a65ecb729f15e09169f5d8122a3b1;hp=5eb0cf3939d1a18ea40970b0a35a5b4643fd57b6;hpb=f2dd532f7c009a653864b23d8858fe9e6c8c3985;p=freeside.git diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 5eb0cf393..bddd1bf51 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -4,6 +4,7 @@ use strict; use vars qw( @ISA ); use Date::Parse; use Date::Format; +use Time::Local; use FS::UID qw( dbh ); use FS::Record qw( qsearch qsearchs ); use FS::cdr_type; @@ -83,8 +84,6 @@ following fields are currently supported: #billing: Mark the entry for billing #documentation: Mark the entry for documentation. -=back - =item accountcode - CDR account number to use: account =item uniqueid - Unique channel identifier (Unitel/RSLCOM Event ID) @@ -224,6 +223,17 @@ sub check { # ; # return $error if $error; + $self->calldate( $self->startdate_sql ) + if !$self->calldate && $self->startdate; + + unless ( $self->charged_party ) { + if ( $self->dst =~ /^(\+?1)?8[02-8]{2}/ ) { + $self->charged_party($self->dst); + } else { + $self->charged_party($self->src); + } + } + #check the foreign keys even? #do we want to outright *reject* the CDR? my $error = @@ -252,7 +262,7 @@ error, otherwise returns false. sub set_status_and_rated_price { my($self, $status, $rated_price) = @_; - $self->status($status); + $self->freesidestatus($status); $self->rated_price($rated_price); $self->replace(); } @@ -267,6 +277,20 @@ sub calldate_unix { str2time(shift->calldate); } +=item startdate_sql + +Parses the startdate in UNIX timestamp format and returns a string in SQL +format. + +=cut + +sub startdate_sql { + my($sec,$min,$hour,$mday,$mon,$year) = localtime(shift->startdate); + $mon++; + $year += 1900; + "$year-$mon-$mday $hour:$min:$sec"; +} + =item cdr_carrier Returns the FS::cdr_carrier object associated with this CDR, or false if no @@ -420,6 +444,8 @@ sub downstream_csv { =cut +my($tmp_mday, $tmp_mon, $tmp_year); + my %import_formats = ( 'asterisk' => [ 'accountcode', @@ -465,7 +491,42 @@ my %import_formats = ( 'quantity', 'carrierid', 'upstream_rateid', - ] + ], + 'ams' => [ + + # Date + sub { my($cdr, $date) = @_; + $date =~ /^(\d{1,2})\/(\d{1,2})\/(\d\d(\d\d)?)$/ + or die "unparsable date: $date"; #maybe we shouldn't die... + #$cdr->startdate( timelocal(0, 0, 0 ,$2, $1-1, $3) ); + ($tmp_mday, $tmp_mon, $tmp_year) = ( $2, $1-1, $3 ); + }, + + # Time + sub { my($cdr, $time) = @_; + #my($sec, $min, $hour, $mday, $mon, $year)= localtime($cdr->startdate); + $time =~ /^(\d{1,2}):(\d{1,2}):(\d{1,2})$/ + or die "unparsable time: $time"; #maybe we shouldn't die... + #$cdr->startdate( timelocal($3, $2, $1 ,$mday, $mon, $year) ); + $cdr->startdate( + timelocal($3, $2, $1 ,$tmp_mday, $tmp_mon, $tmp_year) + ); + }, + + # Source_Number + 'src', + + # Terminating_Number + 'dst', + + # Duration + sub { my($cdr, $min) = @_; + my $sec = sprintf('%.0f', $min * 60 ); + $cdr->billsec( $sec ); + $cdr->duration( $sec ); + }, + + ], ); sub batch_import { @@ -494,10 +555,20 @@ sub batch_import { my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; - + + if ( $format eq 'ams' ) { # and other formats with a header too? + + } + + my $body = 0; my $line; while ( defined($line=<$fh>) ) { + #skip header... + if ( ! $body++ && $format eq 'ams' && $line =~ /^[\w\, ]+$/ ) { + next; + } + $csv->parse($line) or do { $dbh->rollback if $oldAutoCommit; return "can't parse: ". $csv->error_input(); @@ -506,6 +577,10 @@ sub batch_import { my @columns = $csv->fields(); #warn join('-',@columns); + if ( $format eq 'ams' ) { + @columns = map { s/^ +//; $_; } @columns; + } + my @later = (); my %cdr = map {