- my $rate_detail;
- my( $rate_region, $regionnum );
- my $pretty_destnum;
- my $charge = '';
- my $classnum = '';
- my @call_details = ();
- if ( $self->option('rating_method') eq 'prefix'
- || ! $self->option('rating_method')
- )
- {
-
- #should have some better way of checking these options than a long
- #if-else tree...
- my $notchg = "not charging for CDR";
-
- if ( $self->option('use_amaflags') && $cdr->amaflags != 2 ) {
-
- warn "$notchg (amaflags != 2)\n" if $DEBUG;
- $charge = 0;
-
- } elsif ( $self->option('use_disposition')
- && $cdr->disposition ne 'ANSWERED' ) {
-
- warn "$notchg (disposition != ANSWERED)\n" if $DEBUG;
- $charge = 0;
-
- } elsif ( $self->option('use_disposition_taqua')
- && $cdr->disposition != 100 ) {
-
- warn "$notchg (disposition != 100)\n" if $DEBUG;
- $charge = 0;
-
- } elsif ( $self->option('use_carrierid')
- && $cdr->carrierid != $self->option('use_carrierid') ) {
-
- warn "$notchg (carrierid != ". $self->option('use_carrierid'). ")\n"
- if $DEBUG;
- $charge = 0;
-
- } elsif ( $self->option('use_cdrtypenum')
- && $cdr->cdrtypenum != $self->option('use_cdrtypenum') ) {
-
- warn "$notchg (cdrtypenum != ". $self->option('use_cdrtypenum'). ")\n"
- if $DEBUG;
- $charge = 0;
-
- } else {
-
- ###
- # look up rate details based on called station id
- # (or calling station id for toll free calls)
- ###
-
- if ( $self->option('411_rewrite') ) {
- my @dirass = split(/\s*,\s*/, $self->option('411_rewrite'));
- $cdr->dst('411') if grep $cdr->dst eq $_, @dirass;
- }
-
- my( $to_or_from, $number );
- if ( $cdr->dst =~ /^(\+?1)?8([02-8])\1/
- && ! $self->option('disable_tollfree')
- )
- { #tollfree call
- $to_or_from = 'from';
- $number = $cdr->src;
- } else { #regular call
- $to_or_from = 'to';
- $number = $cdr->dst;
- }
-
- warn "parsing call $to_or_from $number\n" if $DEBUG;
-
- #remove non-phone# stuff and whitespace
- $number =~ s/\s//g;
-# my $proto = '';
-# $dest =~ s/^(\w+):// and $proto = $1; #sip:
-# my $siphost = '';
-# $dest =~ s/\@(.*)$// and $siphost = $1; # @10.54.32.1, @sip.example.com
-
- my $intl = $self->option('international_prefix') || '011';
-
- #determine the country code
- my $countrycode;
- if ( $number =~ /^$intl(((\d)(\d))(\d))(\d+)$/
- || $number =~ /^\+(((\d)(\d))(\d))(\d+)$/
- )
- {
-
- my( $three, $two, $one, $u1, $u2, $rest ) = ( $1,$2,$3,$4,$5,$6 );
- #first look for 1 digit country code
- if ( qsearch('rate_prefix', { 'countrycode' => $one } ) ) {
- $countrycode = $one;
- $number = $u1.$u2.$rest;
- } elsif ( qsearch('rate_prefix', { 'countrycode' => $two } ) ) { #or 2
- $countrycode = $two;
- $number = $u2.$rest;
- } else { #3 digit country code
- $countrycode = $three;
- $number = $rest;
- }
-
- } else {
- $countrycode = $self->option('domestic_prefix') || '1';
- $number =~ s/^$countrycode//;# if length($number) > 10;
- }
-
- warn "rating call $to_or_from +$countrycode $number\n" if $DEBUG;
- $pretty_destnum = "+$countrycode $number";
-
- my $rate = qsearchs('rate', { 'ratenum' => $ratenum })
- or die "ratenum $ratenum not found!";
-
- $rate_detail = $rate->dest_detail({ 'countrycode' => $countrycode,
- 'phonenum' => $number,
- });
-
- $rate_region = $rate_detail->dest_region;
- $regionnum = $rate_region->regionnum;
-
- warn " found rate for regionnum $regionnum ".
- "and rate detail $rate_detail\n"
- if $DEBUG;