X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcdr.pm;h=b16cb8648caa07d28907fbbbc8c723b35d1a5744;hb=e19de946a48c91ed05a9267b4425ff5dd98da1e5;hp=9a31144429e4eb78faf253ed867393d2cd841804;hpb=c6782ab85ea83e0c78d85b8975985aac9d467f9d;p=freeside.git diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index 9a3114442..b16cb8648 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -92,6 +92,8 @@ following fields are currently supported: =item dst_ip_addr - Destination IP address (same) +=item dst_term - Terminating destination number (if different from dst) + =item startdate - Start of call (UNIX-style integer timestamp) =item answerdate - Answer time of call (UNIX-style integer timestamp) @@ -194,6 +196,7 @@ sub table_info { #'lastdata' => '', 'src_ip_addr' => 'Source IP', 'dst_ip_addr' => 'Dest. IP', + 'dst_term' => 'Termination dest.', 'startdate' => 'Start date', 'answerdate' => 'Answer date', 'enddate' => 'End date', @@ -644,7 +647,34 @@ sub rate_prefix { ); } + if ( $part_pkg->option_cacheable('skip_same_customer') + and ! $self->is_tollfree ) { + my ($dst_countrycode, $dst_number) = $self->parse_number( + column => 'dst', + international_prefix => $part_pkg->option_cacheable('international_prefix'), + domestic_prefix => $part_pkg->option_cacheable('domestic_prefix'), + ); + my $dst_same_cust = FS::Record->scalar_sql( + 'SELECT COUNT(svc_phone.svcnum) AS count '. + 'FROM cust_pkg ' . + 'JOIN cust_svc USING (pkgnum) ' . + 'JOIN svc_phone USING (svcnum) ' . + 'WHERE svc_phone.countrycode = ' . dbh->quote($dst_countrycode) . + ' AND svc_phone.phonenum = ' . dbh->quote($dst_number) . + ' AND cust_pkg.custnum = ' . $cust_pkg->custnum, + ); + if ( $dst_same_cust > 0 ) { + warn "not charging for CDR (same source and destination customer)\n" if $DEBUG; + return $self->set_status_and_rated_price( 'skipped', + 0, + $opt{'svcnum'}, + ); + } + } + + + ### # look up rate details based on called station id # (or calling station id for toll free calls) @@ -905,8 +935,12 @@ sub rate_prefix { } #should preserve (display?) this - my $charge_min = ( $charge_sec - $conn_seconds ) / 60; - $charge += ($rate_detail->min_charge * $charge_min) if $charge_min > 0; #still not rounded + if ( $granularity == 0 ) { # per call rate + $charge += $rate_detail->min_charge; + } else { + my $charge_min = ( $charge_sec - $conn_seconds ) / 60; + $charge += ($rate_detail->min_charge * $charge_min) if $charge_min > 0; #still not rounded + } } @@ -924,9 +958,15 @@ sub rate_prefix { # this is why we need regionnum/rate_region.... warn " (rate region $rate_region)\n" if $DEBUG; + # NOW round it. + my $rounding = $part_pkg->option_cacheable('rounding') || 2; + my $sprintformat = '%.'. $rounding. 'f'; + my $roundup = 10**(-3-$rounding); + my $price = sprintf($sprintformat, $charge + $roundup); + $self->set_status_and_rated_price( 'rated', - sprintf('%.2f', $charge + 0.000001), # NOW round it. + $price, $opt{'svcnum'}, 'rated_pretty_dst' => $pretty_dst, 'rated_regionname' => $rate_region->regionname,