From 020029a07fdc007573bc50f2573c08ffc1ed2748 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 17 Jul 2009 00:35:53 +0000 Subject: [PATCH] add single_price option so you can do one per-minute price without rate tables, RT#5495 --- FS/FS/part_pkg/voip_cdr.pm | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index 929a2d725..744c45192 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -21,7 +21,7 @@ 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.', - 'flat' => 'A single price per minute for all calls.', + 'single_price' => 'A single price per minute for all calls.', ; tie my %recur_method, 'Tie::IxHash', @@ -75,7 +75,7 @@ tie my %temporalities, 'Tie::IxHash', 'select_options' => \%recur_method, }, - 'rating_method' => { 'name' => 'Region rating method', + 'rating_method' => { 'name' => 'Rating method', 'type' => 'radio', 'options' => \%rating_method, }, @@ -87,6 +87,10 @@ tie my %temporalities, 'Tie::IxHash', 'select_label' => 'ratename', }, + 'min_charge' => { 'name' => 'Charge per minute when using "single price per minute" rating method', + 'type' => 'money', + }, + 'ignore_unrateable' => { 'name' => 'Ignore calls without a rate in the rate tables. By default, the system will throw a fatal error upon encountering unrateable calls.', 'type' => 'checkbox', }, @@ -440,6 +444,32 @@ sub calc_recur { ); $classnum = $cdr->calltypenum; + } elsif ( $rating_method eq 'single_price' ) { + + # a little false laziness w/below + + my $granularity = 60; + + # length($cdr->billsec) ? $cdr->billsec : $cdr->duration; + my $seconds = $use_duration ? $cdr->duration : $cdr->billsec; + + $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; + + $charge = sprintf('%.2f', ( $self->option('min_charge') * $minutes ) + + 0.00000001 ); #so 1.005 rounds to 1.01 + + $charge = + $charges += $charge; + + @call_details = ($cdr->downstream_csv( 'format' => $output_format, + 'charge' => $charge, + ) + ); + } else { die "don't know how to rate CDRs using method: $rating_method\n"; } -- 2.11.0