From: Mark Wells <mark@freeside.biz>
Date: Mon, 8 Aug 2016 20:23:25 +0000 (-0700)
Subject: option to extract destination number from userfield, #71674
X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=a238acfb85cd4bef6a99bfe3560a0999c9386dfb

option to extract destination number from userfield, #71674
---

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 587b2a26d..d09212d4a 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -5320,6 +5320,13 @@ and customer address. Include units.',
     'type'        => 'checkbox',
   },
 
+  {
+    'key'         => 'cdr-userfield_dnis_rewrite',
+    'section'     => 'telephony',
+    'description' => 'If the CDR userfield contains "DNIS=" followed by a sequence of digits, use that as the destination number for the call.',
+    'type'        => 'checkbox',
+  },
+
   {
     'key'         => 'cdr-intl_to_domestic_rewrite',
     'section'     => 'telephony',
diff --git a/FS/bin/freeside-cdrrewrited b/FS/bin/freeside-cdrrewrited
index 008759008..f9d97af91 100644
--- a/FS/bin/freeside-cdrrewrited
+++ b/FS/bin/freeside-cdrrewrited
@@ -198,6 +198,12 @@ while (1) {
 
     }
 
+    if ( $conf->exists('cdr-userfield_dnis_rewrite') and
+         $cdr->userfield =~ /DNIS=(\d+)/ ) {
+      $cdr->dst($1);
+      push @status, 'userfield_dnis';
+    }
+
     if ( $conf->exists('cdr-intl_to_domestic_rewrite') and
          $cdr->dst =~ /^(011)(\d{0,7})$/ ) {
       $cdr->dst($2);
@@ -240,6 +246,7 @@ sub _shouldrun {
   || $conf->exists('cdr-taqua-accountcode_rewrite')
   || $conf->exists('cdr-taqua-callerid_rewrite')
   || $conf->exists('cdr-intl_to_domestic_rewrite')
+  || $conf->exists('cdr-userfield_dnis_rewrite')
   || 0
   ;
 }