36503 Scalability issues with amcom CDRs
[freeside.git] / FS / FS / cdr / amcom.pm
index 5967d7b..697a682 100644 (file)
@@ -2,8 +2,10 @@ package FS::cdr::amcom;
 
 use strict;
 use base qw( FS::cdr );
-use vars qw( %info );
+use vars qw( %info %cdrtypes);
 use DateTime;
+use FS::Record qw( qsearch );
+use FS::cdr_type;
 
 my ($tmp_mday, $tmp_mon, $tmp_year);
 
@@ -14,6 +16,12 @@ my ($tmp_mday, $tmp_mon, $tmp_year);
   'type'          => 'csv',
   'sep_char'      => ',',
   'disabled'      => 0,
+  'header_buffer' => sub {
+
+       %cdrtypes = ( map { $_->cdrtypename => $_->cdrtypenum }
+                             qsearch('cdr_type', {})
+            );
+    },
 
   #listref of what to do with each field from the CDR, in order
   'import_fields' => [
@@ -22,15 +30,27 @@ my ($tmp_mday, $tmp_mon, $tmp_year);
       my ($cdr, $field, $conf, $hashref) = @_;
       $hashref->{skiprow} = 1 unless $field eq 'DCR';
     },
-    '',           # 2. BWGroupID (centrex group)
-    '',           # 3. BWGroupNumber
+    'accountcode',# 2. BWGroupID (centrex group)
+    sub {         # 3. BWGroupNumber
+      my ($cdr, $field) = @_; #, $conf, $hashref) = @_;
+
+        if ($cdr->accountcode eq '' && $field =~ /^(1800|1300)/){
+       $cdr->charged_party($field);
+       $cdr->accountcode($field);
+       }
+    },
     'uniqueid',   # 4. Record ID
-    'dcontext',   # 5. Call Category (LOCAL, NATIONAL, FREECALL, MOBILE)
+    sub {         # 5. Call Category (LOCAL, NATIONAL, FREECALL, MOBILE)
+      my ($cdr, $data) = @_;
+      $data ||= 'none';
+      $cdr->cdrtypenum($cdrtypes{$data} || '');
+      $cdr->set('dcontext', $data);  
+    },
     sub {         # 6. Start Date (DDMMYYYY
       my ($cdr, $date) = @_;
       $date =~ /^(\d{2})(\d{2})(\d{4})$/
         or die "unparseable date: $date";
-      ($tmp_mday, $tmp_mon, $tmp_year) = ($1, $2-1, $3);
+      ($tmp_mday, $tmp_mon, $tmp_year) = ($1, $2, $3);
     },
     sub {         # 7. Start Time (HHMMSS)
       my ($cdr, $time) = @_;
@@ -43,6 +63,7 @@ my ($tmp_mday, $tmp_mon, $tmp_year);
         hour    => $1,
         minute  => $2,
         second  => $3,
+       time_zone => 'local',
       );
       $cdr->set('startdate', $dt->epoch);
     },