},
{
+ '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.',
'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;
$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?
$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
$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();
#--
) {
$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
)
{
$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 ) {
#--
sub _shouldrun {
- $conf->exists('cdr-asterisk_forward_rewrite');
+ $conf->exists('cdr-asterisk_forward_rewrite')
+ || $conf->exists('cdr-charged_party_rewrite');
}
sub usage {
=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