normal ext_desc shouldn't shove the second+ columns of CDRs out
[freeside.git] / FS / FS / cdr.pm
index 5848f9b..ba3e492 100644 (file)
@@ -233,12 +233,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?
@@ -554,7 +566,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) };
@@ -635,7 +647,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 $@;