option to do charged_party rewriting in the cdrrewrited daemon, RT#4342
authorivan <ivan>
Mon, 2 Mar 2009 04:58:09 +0000 (04:58 +0000)
committerivan <ivan>
Mon, 2 Mar 2009 04:58:09 +0000 (04:58 +0000)
FS/FS/Conf.pm
FS/FS/cdr.pm
FS/bin/freeside-cdrrewrited

index 8c5b296..b869302 100644 (file)
@@ -2647,6 +2647,13 @@ worry that config_items is freeside-specific and icky.
   },
 
   {
+    'key'         => 'cdr-charged_party_rewrite',
+    'section'     => '',
+    'description' => 'Do charged party rewriting in the freeside-cdrrewrited daemon; useful if CDRs are being dropped off directly in the database and require special charged_party processing such as cdr-charged_party-accountcode.',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'cdr-taqua-da_rewrite',
     'section'     => '',
     'description' => 'For the Taqua CDR format, a comma-separated list of directory assistance 800 numbers.  Any CDRs with these numbers as "BilledNumber" will be rewritten to the "CallingPartyNumber" (and CallType "12") on import.',
@@ -2660,6 +2667,13 @@ worry that config_items is freeside-specific and icky.
     'type'       => 'checkbox',
   },
 
+  {
+    'key'         => 'cdr-asterisk_forward_rewrite',
+    'section'     => '',
+    'description' => 'Enable special processing for CDRs representing forwarded calls: For CDRs that have a dcontext that starts with "Local/" but does not match dst, set charged_party to dst, parse a new dst from dstchannel, and set amaflags to "2" ("BILL"/"BILLING").',
+    'type'        => 'checkbox',
+  },
+
 );
 
 1;
index 8307b28..67c5c1c 100644 (file)
@@ -246,25 +246,7 @@ sub check {
     $self->billsec(  $self->enddate - $self->answerdate );
   } 
 
-  my $conf = new FS::Conf;
-
-  unless ( $self->charged_party ) {
-
-    if ( $conf->exists('cdr-charged_party-accountcode') && $self->accountcode ){
-
-      $self->charged_party( $self->accountcode );
-
-    } else {
-
-      if ( $self->dst =~ /^(\+?1)?8[02-8]{2}/ ) {
-        $self->charged_party($self->dst);
-      } else {
-        $self->charged_party($self->src);
-      }
-
-    }
-
-  }
+  $self->set_charged_party;
 
   #check the foreign keys even?
   #do we want to outright *reject* the CDR?
@@ -287,6 +269,43 @@ sub check {
   $self->SUPER::check;
 }
 
+=item set_charged_party
+
+If the charged_party field is already set, does nothing.  Otherwise:
+
+If the cdr-charged_party-accountcode config option is enabled, sets the
+charged_party to the accountcode.
+
+Otherwise sets the charged_party normally: to the src field in most cases,
+or to the dst field if it is a toll free number.
+
+=cut
+
+sub set_charged_party {
+  my $self = shift;
+
+  unless ( $self->charged_party ) {
+
+    my $conf = new FS::Conf;
+
+    if ( $conf->exists('cdr-charged_party-accountcode') && $self->accountcode ){
+
+      $self->charged_party( $self->accountcode );
+
+    } else {
+
+      if ( $self->dst =~ /^(\+?1)?8[02-8]{2}/ ) {
+        $self->charged_party($self->dst);
+      } else {
+        $self->charged_party($self->src);
+      }
+
+    }
+
+  }
+
+}
+
 =item set_status_and_rated_price STATUS [ RATED_PRICE ]
 
 Sets the status to the provided string.  If there is an error, returns the
index 198fbb5..0b7f688 100644 (file)
@@ -24,7 +24,8 @@ daemonize2();
 
 $conf = new FS::Conf;
 
-die "not running; cdr-asterisk_forward_rewrite conf is off\n"
+die "not running; cdr-asterisk_forward_rewrite and cdr-charged_party_rewrite ".
+    " conf options are both off\n"
   unless _shouldrun();
 
 #--
@@ -49,8 +50,10 @@ while (1) {
   ) {
 
     $found = 1;
+    my @status = ();
 
-    if ( $cdr->dstchannel =~ /^Local\/(\d+)/i && $1 ne $cdr->dst
+    if ( $conf->exists('cdr-asterisk_forward_rewrite')
+         && $cdr->dstchannel =~ /^Local\/(\d+)/i && $1 ne $cdr->dst
        )
     {
 
@@ -63,12 +66,21 @@ while (1) {
       $cdr->dst($dst);
       $cdr->amaflags(2);
 
-      $cdr->freesiderewritestatus('asterisk_forward');
+      push @status, 'asterisk_forward';
 
-    } else {
-      $cdr->freesiderewritestatus('skipped')
     }
 
+    if ( $conf->exists('cdr-charged_party_rewrite') && ! $cdr->charged_party ) {
+
+      $cdr->set_charged_party;
+      push @status, 'charged_party';
+
+    }
+
+    $cdr->freesiderewritestatus(
+      scalar(@status) ? join('/', @status) : 'skipped'
+    );
+
     my $error = $cdr->replace;
 
     if ( $error ) {
@@ -88,7 +100,8 @@ while (1) {
 #--
 
 sub _shouldrun {
-  $conf->exists('cdr-asterisk_forward_rewrite');
+     $conf->exists('cdr-asterisk_forward_rewrite')
+  || $conf->exists('cdr-charged_party_rewrite');
 }
 
 sub usage { 
@@ -105,8 +118,9 @@ freeside-cdrrewrited - Real-time daemon for CDR rewriting
 
 =head1 DESCRIPTION
 
-Runs continuously, searches for CDRs and does forwarded-call rewriting if
-the "cdr-asterisk_forward_rewrite" option is enabled.
+Runs continuously, searches for CDRs and does forwarded-call rewriting if the
+"cdr-asterisk_forward_rewrite" or "cdr-charged_party_rewrite" config option is
+enabled.
 
 =head1 SEE ALSO