X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fvoip_cdr.pm;h=eb6727a3264290d9588716f97055f8b29790abb2;hb=d25c55c2273aa62676dda8d60959f11b27020935;hp=0c87581eda6806ff9143396ec3035b1887012ad0;hpb=22533581052cfbab858fff275506a3a25ace717f;p=freeside.git diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index 0c87581ed..eb6727a32 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -15,7 +15,7 @@ use FS::part_pkg::recur_Common; @ISA = qw(FS::part_pkg::recur_Common); -$DEBUG = 0; +$DEBUG = 1; 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', @@ -399,6 +399,8 @@ sub calc_usage { warn "rating call $to_or_from +$countrycode $number\n" if $DEBUG; $pretty_destnum = "+$countrycode $number"; + #asterisks here causes inserting the detail to barf, so: + $pretty_destnum =~ s/\*//g; my $rate = qsearchs('rate', { 'ratenum' => $ratenum }) or die "ratenum $ratenum not found!"; @@ -450,6 +452,7 @@ sub calc_usage { # } else { #pass upstream price through # # $charge = sprintf('%.2f', $cdr->upstream_price); +# warn "Incrementing \$charges by $charge. Now $charges\n" if $DEBUG; # $charges += $charge; # # @call_details = ( @@ -468,6 +471,7 @@ sub calc_usage { #XXX $charge = sprintf('%.2f', $cdr->upstream_price); $charge = sprintf('%.3f', $cdr->upstream_price); $charges += $charge; + warn "Incrementing \$charges by $charge. Now $charges\n" if $DEBUG; @call_details = ($cdr->downstream_csv( 'format' => $output_format, 'charge' => $charge, @@ -498,6 +502,7 @@ sub calc_usage { $charge = sprintf('%.4f', ( $self->option('min_charge') * $minutes ) + 0.0000000001 ); #so 1.00005 rounds to 1.0001 + warn "Incrementing \$charges by $charge. Now $charges\n" if $DEBUG; $charges += $charge; @call_details = ($cdr->downstream_csv( 'format' => $output_format, @@ -535,6 +540,9 @@ sub calc_usage { # length($cdr->billsec) ? $cdr->billsec : $cdr->duration; $seconds = $use_duration ? $cdr->duration : $cdr->billsec; + $seconds -= $rate_detail->conn_sec; + $seconds = 0 if $seconds < 0; + $seconds += $granularity - ( $seconds % $granularity ) if $seconds # don't granular-ize 0 billsec calls (bills them) && $granularity; # 0 is per call @@ -546,14 +554,18 @@ sub calc_usage { $included_min{$regionnum} -= $minutes; + $charge = sprintf('%.2f', $rate_detail->conn_charge); + if ( $included_min{$regionnum} < 0 ) { my $charge_min = 0 - $included_min{$regionnum}; #XXX should preserve #(display?) this $included_min{$regionnum} = 0; - $charge = sprintf('%.2f', ( $rate_detail->min_charge * $charge_min ) - + 0.00000001 ); #so 1.005 rounds to 1.01 - $charges += $charge; + $charge += sprintf('%.2f', ($rate_detail->min_charge * $charge_min) + + 0.00000001 ); #so 1.005 rounds to 1.01 + $charge = sprintf('%.2f', $charge); } + warn "Incrementing \$charges by $charge. Now $charges\n" if $DEBUG; + $charges += $charge; # this is why we need regionnum/rate_region.... warn " (rate region $rate_region)\n" if $DEBUG;