From caf4bbf142bc25fa583e258ac3e1724a9eee8d5b Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 2 Mar 2009 04:58:09 +0000 Subject: [PATCH] option to do charged_party rewriting in the cdrrewrited daemon, RT#4342 --- FS/FS/Conf.pm | 14 +++++++++++ FS/FS/cdr.pm | 57 ++++++++++++++++++++++++++++++--------------- FS/bin/freeside-cdrrewrited | 30 +++++++++++++++++------- 3 files changed, 74 insertions(+), 27 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 8c5b296e0..b86930255 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -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; diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 8307b287e..67c5c1c2a 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -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 diff --git a/FS/bin/freeside-cdrrewrited b/FS/bin/freeside-cdrrewrited index 198fbb5e7..0b7f6883f 100644 --- a/FS/bin/freeside-cdrrewrited +++ b/FS/bin/freeside-cdrrewrited @@ -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 -- 2.11.0