tie my %rating_method, 'Tie::IxHash',
'prefix' => 'Rate calls by using destination prefix to look up a region and rate according to the internal prefix and rate tables',
'upstream' => 'Rate calls based on upstream data: If the call type is "1", map the upstream rate ID directly to an internal rate (rate_detail), otherwise, pass the upstream price through directly.',
+ 'upstream_simple' => 'Simply pass through and charge the "upstream_price" amount.',
;
#tie my %cdr_location, 'Tie::IxHash',
#;
%info = (
- 'name' => 'VoIP rating by plan of CDR records in an internal (or external?) SQL table',
+ 'name' => 'VoIP rating by plan of CDR records in an internal (or external) SQL table',
+ 'shortname' => 'VoIP/telco CDR rating (standard)',
'fields' => {
'setup_fee' => { 'name' => 'Setup fee for this package',
'default' => 0,
},
- 'recur_flat' => { 'name' => 'Base recurring fee for this package',
- 'default' => 0,
- },
+ 'recur_fee' => { 'name' => 'Base recurring fee for this package',
+ 'default' => 0,
+ },
'unused_credit' => { 'name' => 'Credit the customer for the unused portion'.
' of service at cancellation',
'type' => 'checkbox',
'select_label' => 'ratename',
},
'rating_method' => { 'name' => 'Region rating method',
- 'type' => 'select',
- 'select_options' => \%rating_method,
+ 'type' => 'radio',
+ 'options' => \%rating_method,
},
'default_prefix' => { 'name' => 'Default prefix optionally prepended to customer DID numbers when searching for CDR records',
'default' => '+1',
},
- #XXX also have option for an external db??
+ 'disable_src' => { 'name' => 'Disable rating of CDR records based on the "src" field in addition to "charged_party"',
+ 'type' => 'checkbox'
+ },
+
+ 'domestic_prefix' => { 'name' => 'Destination prefix for domestic CDR records',
+ 'default' => '1',
+ },
+
+# 'domestic_prefix_required' => { 'name' => 'Require explicit destination prefix for domestic CDR records',
+# 'type' => 'checkbox',
+# },
+
+ 'international_prefix' => { 'name' => 'Destination prefix for international CDR records',
+ 'default' => '011',
+ },
+
+ #XXX also have option for an external db
# 'cdr_location' => { 'name' => 'CDR database location'
# 'type' => 'select',
# 'select_options' => \%cdr_location,
# },
},
- 'fieldorder' => [qw( setup_fee recur_flat unused_credit ratenum rating_method default_prefix )],
+ 'fieldorder' => [qw( setup_fee recur_fee unused_credit ratenum rating_method default_prefix disable_src domestic_prefix international_prefix )],
'weight' => 40,
);
# $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 =~ /^011(((\d)(\d))(\d))(\d+)$/
+ if ( $number =~ /^$intl(((\d)(\d))(\d))(\d+)$/
|| $number =~ /^\+(((\d)(\d))(\d))(\d+)$/
)
{
}
} else {
- $countrycode = '1';
- $number =~ s/^1//;# if length($number) > 10;
+ $countrycode = $self->option('domestic_prefix') || '1';
+ $number =~ s/^$countrycode//;# if length($number) > 10;
}
warn "rating call $to_or_from +$countrycode $number\n" if $DEBUG;
});
#
- die "Can't find rate for call $to_or_from +$countrycode $\numbern"
+ die "Can't find rate for call $to_or_from +$countrycode $number\n"
unless $rate_prefix;
$regionnum = $rate_prefix->regionnum;
}
+ } elsif ( $self->option('rating_method') eq 'upstream_simple' ) {
+
+ #XXX $charge = sprintf('%.2f', $cdr->upstream_price);
+ $charge = sprintf('%.3f', $cdr->upstream_price);
+ $charges += $charge;
+
+ @call_details = (
+ #time2str("%Y %b %d - %r", $cdr->calldate_unix ),
+ time2str("%c", $cdr->calldate_unix), #XXX this should probably be a config option dropdown so they can select US vs- rest of world dates or whatnot
+ sprintf('%.2f', $cdr->billsec / 60 ).'m',
+ '$'.$charge, #XXX $money_char
+ #$pretty_destnum,
+ $cdr->userfield, #$rate_region->regionname,
+ $cdr->dst,
+ );
+
} else {
die "don't know how to rate CDRs using method: ".
$self->option('rating_method'). "\n";
unless exists $included_min{$regionnum};
my $granularity = $rate_detail->sec_granularity;
- my $seconds = $cdr->billsec; # |ength($cdr->billsec) ? $cdr->billsec : $cdr->duration;
- $seconds += $granularity - ( $seconds % $granularity );
+ my $seconds = $cdr->billsec; # length($cdr->billsec) ? $cdr->billsec : $cdr->duration;
+ $seconds += $granularity - ( $seconds % $granularity )
+ if $seconds # don't granular-ize 0 billsec calls (bills them)
+ && $granularity; # 0 is per call
my $minutes = sprintf("%.1f", $seconds / 60);
$minutes =~ s/\.0$// if $granularity == 60;
+
+ # per call rather than per minute
+ $minutes = 1 unless $granularity;
$included_min{$regionnum} -= $minutes;
@call_details = (
#time2str("%Y %b %d - %r", $cdr->calldate_unix ),
time2str("%c", $cdr->calldate_unix), #XXX this should probably be a config option dropdown so they can select US vs- rest of world dates or whatnot
- $minutes.'m',
+ $granularity ? $minutes.'m' : $minutes.' call',
'$'.$charge,
$pretty_destnum,
$rate_region->regionname,
warn " adding details on charge to invoice: ".
join(' - ', @call_details )
- if $DEBUG;
+ if $DEBUG && $charge > 0;
- push @$details, join(' - ', @call_details); #\@call_details,
+ push @$details, join(' - ', @call_details) #\@call_details,
+ if $charge > 0;
# if the customer flag is on, call "downstream_csv" or something
# like it to export the call downstream!
} #if ( $spool_cdr && length($downstream_cdr) )
- $self->option('recur_flat') + $charges;
+ $self->option('recur_fee') + $charges;
}
sub base_recur {
my($self, $cust_pkg) = @_;
- $self->option('recur_flat');
+ $self->option('recur_fee');
}
1;