fixup pivot code handling in netcentrex CDR handling, RT#4081
authorivan <ivan>
Fri, 29 May 2009 23:17:24 +0000 (23:17 +0000)
committerivan <ivan>
Fri, 29 May 2009 23:17:24 +0000 (23:17 +0000)
FS/FS/Conf.pm
FS/FS/cdr.pm
FS/FS/cdr/netcentrex.pm

index b1bc97a..cf7e49f 100644 (file)
@@ -2736,19 +2736,19 @@ worry that config_items is freeside-specific and icky.
     'type'        => 'checkbox',
   },
 
-  {
-    'key'         => 'cdr-charged_party-truncate_prefix',
-    'section'     => '',
-    'description' => 'If the charged_party field has this prefix, truncate it to the length in cdr-charged_party-truncate_length.',
-    'type'        => 'text',
-  },
-
-  {
-    'key'         => 'cdr-charged_party-truncate_length',
-    'section'     => '',
-    'description' => 'If the charged_party field has the prefix in cdr-charged_party-truncate_prefix, truncate it to this length.',
-    'type'        => 'text',
-  },
+#  {
+#    'key'         => 'cdr-charged_party-truncate_prefix',
+#    'section'     => '',
+#    'description' => 'If the charged_party field has this prefix, truncate it to the length in cdr-charged_party-truncate_length.',
+#    'type'        => 'text',
+#  },
+#
+#  {
+#    'key'         => 'cdr-charged_party-truncate_length',
+#    'section'     => '',
+#    'description' => 'If the charged_party field has the prefix in cdr-charged_party-truncate_prefix, truncate it to this length.',
+#    'type'        => 'text',
+#  },
 
   {
     'key'         => 'cdr-charged_party_rewrite',
index 2a235cc..421fd2b 100644 (file)
@@ -315,13 +315,13 @@ sub set_charged_party {
 
   }
 
-  my $prefix = $conf->config('cdr-charged_party-truncate_prefix');
-  my $prefix_len = length($prefix);
-  my $trunc_len = $conf->config('cdr-charged_party-truncate_length');
-
-  $self->charged_party( substr($self->charged_party, 0, $trunc_len) )
-    if $prefix_len && $trunc_len
-    && substr($self->charged_party, 0, $prefix_len) eq $prefix;
+#  my $prefix = $conf->config('cdr-charged_party-truncate_prefix');
+#  my $prefix_len = length($prefix);
+#  my $trunc_len = $conf->config('cdr-charged_party-truncate_length');
+#
+#  $self->charged_party( substr($self->charged_party, 0, $trunc_len) )
+#    if $prefix_len && $trunc_len
+#    && substr($self->charged_party, 0, $prefix_len) eq $prefix;
 
 }
 
index 7ccc3df..0cd5c7b 100644 (file)
@@ -29,8 +29,8 @@ use FS::cdr qw(_cdr_date_parser_maker);
     _cdr_date_parser_maker('startdate'),  #05 Authorize timestamp
     _cdr_date_parser_maker('answerdate'), #06 Start timestamp
     'billsec', #'duration', #07 Duration
-    _e164_parser_maker('src'), #08 Caller
-    _e164_parser_maker('dst'), #09 Callee
+    _e164_parser_maker('src',      'charged_party'),                 #08 Caller
+    _e164_parser_maker('dcontext', 'dst', 'norewrite_pivotonly'=>1) ,#09 Callee
     'channel', #10 Source IP
     'dstchannel', #11 Destination IP
     'userfield', #12 selector Tag
@@ -80,43 +80,40 @@ use FS::cdr qw(_cdr_date_parser_maker);
 );
 
 sub _e164_parser_maker {
-  my $field = shift;
+  my( $field, $pivot_field, %opt ) = @_;
   return sub {
     my( $cdr, $e164 ) = @_;
-    eval { $cdr->$field( _e164_parse($e164) ); };
-    die "error parsing e164 for $field from $e164: $@\n" if $@;
+    my( $pivot, $number ) = _e164_parse($e164);
+    if ( $opt{'norewrite_pivotonly'} && ! $pivot ) { 
+      $cdr->$pivot_field( $number );
+    } else {
+      $cdr->$field( $number );
+      $cdr->$pivot_field( $pivot );
+    }
   };
 }
 
-my %e164_types = (
-  '000000' => '',
-  '100005' => '',
-  '100009' => '',
-  '100012' => '',
-  '100014' => '',
-  '100015' => '',
-  '100016' => '',
-  '300000' => '',
-);
-
 sub _e164_parse {
   my $e164 = shift;
 
   $e164 =~ s/^e164://;
 
-  my ($type, $number);
+  my ($pivot, $number);
   if ( $e164 =~ /^O(\d+)$/ ) {
-    $type = ''; #?
+    $pivot = ''; #?
     $number = $1;
-  } elsif ( $e164 =~ /^(\d{6})(\d+)$/ ) {
-    $type = $1;
+  } elsif ( $e164 =~ /^000000(\d+)$/ ) {
+    $pivot = '';
+    $number = $1;
+  } elsif ( $e164 =~ /^(1\d{5})(\d+)$/ ) {
+    $pivot = $1;
     $number = $2;
   } else {
-    $type = '';
+    $pivot = '';
     $number = $e164; #unparsable...
   }
-  #$type...?
-  $number;
+
+  ( $pivot, $number );
 }
 
 1;