SMSC CDRs (Kannel) and cdrtypenum option on cdr sftp import script, RT10991
[freeside.git] / FS / FS / cdr.pm
index 3157b6b..36721a8 100644 (file)
@@ -560,11 +560,11 @@ sub export_formats {
   my $duration_sub = sub {
     my($cdr, %opt) = @_;
     my $sec = $opt{seconds} || $cdr->billsec;
-    if ( length($opt{granularity}) && 
+    if ( defined $opt{granularity} && 
          $opt{granularity} == 0 ) { #per call
       return '1 call';
     }
-    elsif ( $opt{granularity} == 60 ) {#full minutes
+    elsif ( defined $opt{granularity} && $opt{granularity} == 60 ) {#full minutes
       my $min = int($sec/60);
       $min++ if $sec%60;
       return $min.'m';
@@ -620,7 +620,10 @@ sub export_formats {
       $duration_sub,
 
       #PRICE
-      sub { my($cdr, %opt) = @_; $opt{money_char}. $opt{charge}; },
+      sub { my($cdr, %opt) = @_; 
+        $opt{charge} = '0.00' unless defined $opt{charge};
+        $opt{money_char}.$opt{charge}; 
+      },
 
     ],
   );
@@ -660,6 +663,8 @@ sub downstream_csv {
         }
     @{ $formats{$format} };
 
+  return @columns if defined $opt{'keeparray'};
+
   my $status = $csv->combine(@columns);
   die "FS::CDR: error combining ". $csv->error_input(). "into downstream CSV"
     unless $status;
@@ -906,7 +911,7 @@ my %import_options = (
                },
 
                           #drop the || 'csv' to allow auto xls for csv types?
-  'format_types' => { map { $_ => ( lc($cdr_info{$_}->{'type'}) || 'csv' ); }
+  'format_types' => { map { $_ => lc($cdr_info{$_}->{'type'} || 'csv'); }
                           keys %cdr_info
                     },
 
@@ -943,6 +948,14 @@ sub batch_import {
   my $iopt = _import_options;
   $opt->{$_} = $iopt->{$_} foreach keys %$iopt;
 
+  if ( defined $opt->{'cdrtypenum'} ) {
+        $opt->{'preinsert_callback'} = sub {
+                my($record,$param) = (shift,shift);
+                $record->cdrtypenum($opt->{'cdrtypenum'});
+                '';
+        };
+  }
+
   FS::Record::batch_import( $opt );
 
 }