X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=FS%2FFS%2Fdetail_format%2Fsum_duration_prefix.pm;h=3c33dc163fdddc67d0caefd80c6ae2300dd11dfb;hb=bb7e827141c9ed68f30765c9ca2ddcd1d760ad2d;hp=275aa57a552375a61803e1202b9b559e82c7496a;hpb=0d16979c948a691c95ef92f4ac7a2921a9e8c998;p=freeside.git diff --git a/FS/FS/detail_format/sum_duration_prefix.pm b/FS/FS/detail_format/sum_duration_prefix.pm index 275aa57a5..3c33dc163 100644 --- a/FS/FS/detail_format/sum_duration_prefix.pm +++ b/FS/FS/detail_format/sum_duration_prefix.pm @@ -2,7 +2,7 @@ package FS::detail_format::sum_duration_prefix; use strict; use vars qw( $DEBUG ); -use parent qw(FS::detail_format); +use base qw(FS::detail_format); use List::Util qw(sum); $DEBUG = 0; @@ -24,8 +24,12 @@ my $prefix_length = 6; sub append { my $self = shift; my $prefixes = ($self->{prefixes} ||= {}); + my $acctids = ($self->{acctids} ||= []); foreach my $cdr (@_) { - my $phonenum = $self->{inbound} ? $cdr->src : $cdr->dst; + my (undef, $phonenum) = $cdr->parse_number( + column => ( $self->{inbound} ? 'src' : 'dst' ), + ); + $phonenum =~ /^(\d{$prefix_length})/; my $prefix = $1 || 'other'; warn "$me appending ".$cdr->dst." to $prefix\n" if $DEBUG; @@ -41,11 +45,16 @@ sub append { # but interstate-ness should be symmetric, yes? if A places an # interstate call to B, then B receives an interstate call from A. my $subtotal = $prefixes->{$prefix}{$cdr->rated_ratename} - or die "unknown rated_ratename '" .$cdr->rated_ratename. - "' in CDR #".$cdr->acctid."\n"; + or next; + # silently skip calls that are neither interstate nor intrastate + #or die "unknown rated_ratename '" .$cdr->rated_ratename. + # "' in CDR #".$cdr->acctid."\n"; $subtotal->{count}++; $subtotal->{duration} += $object->rated_seconds; - $subtotal->{amount} += $object->rated_price; + $subtotal->{amount} += $object->rated_price + if $object->freesidestatus ne 'no-charge'; + + push @$acctids, $cdr->acctid; } } @@ -62,11 +71,13 @@ sub finish { my $total_duration = sum( map { $_->{'duration'} } @subtotals ); $prefix =~ s/(...)(...)/$1 - $2/; + next if $total_amount < 0.01; + $self->csv->combine( $prefix, map({ - ($_->{count} || ''), - ($_->{duration} ? int($_->{duration}/60) . ' min' : '') + $_->{count}, + sprintf('%.01f min', $_->{duration}/60), } @subtotals ), $self->money_char . sprintf('%.02f',$total_amount), ); @@ -83,6 +94,7 @@ sub finish { startdate => '', #could use the earliest startdate in the bunch? regionname => '', #no, we're using prefix instead detail => $self->csv->string, + acctid => $self->{acctids}, }); } #foreach $prefix }