X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fvoip_inbound.pm;h=4714ccb28ca804f00192e041643474aaf4cf450d;hb=ecb7665dc7dadd32cdfa5a1b98be57f0850c234d;hp=ec7dad6bdca0d701ffe0bd31cf8290a6467d6350;hpb=e15d1dc33f56308e025ac9cbbf95feecadd26941;p=freeside.git diff --git a/FS/FS/part_pkg/voip_inbound.pm b/FS/FS/part_pkg/voip_inbound.pm index ec7dad6bd..4714ccb28 100644 --- a/FS/FS/part_pkg/voip_inbound.pm +++ b/FS/FS/part_pkg/voip_inbound.pm @@ -1,16 +1,15 @@ package FS::part_pkg::voip_inbound; +use base qw( FS::part_pkg::recur_Common ); use strict; -use vars qw(@ISA $DEBUG %info); +use vars qw($DEBUG %info); use Date::Format; use Tie::IxHash; +use Text::CSV_XS; use FS::Conf; use FS::Record qw(qsearchs qsearch); -use FS::part_pkg::recur_Common; use FS::cdr; -use FS::part_pkg::recur_Common; - -@ISA = qw(FS::part_pkg::recur_Common); +use FS::rate_detail; $DEBUG = 0; @@ -56,10 +55,6 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities(); 'default' => '+1', }, - 'disable_tollfree' => { 'name' => 'Disable automatic toll-free processing', - 'type' => 'checkbox', - }, - 'use_amaflags' => { 'name' => 'Only charge for CDRs where the amaflags field is set to "2" ("BILL"/"BILLING").', 'type' => 'checkbox', }, @@ -148,7 +143,6 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities(); FS::part_pkg::prorate_Mixin::fieldorder, qw( min_charge min_included sec_granularity default_prefix - disable_tollfree use_amaflags use_carrierid use_cdrtypenum ignore_cdrtypenum @@ -160,7 +154,7 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities(); bill_every_call ) ], - 'weight' => 40, + 'weight' => 42, ); sub price_info { @@ -205,25 +199,21 @@ sub calc_usage { my $spool_cdr = $cust_pkg->cust_main->spool_cdr; - my $included_min = ($self->option('min_included') - && $self->option('min_included') > 0) - ? $self->option('min_included') : 0; my $charges = 0; # my $downstream_cdr = ''; - my $disable_tollfree = $self->option('disable_tollfree'); - my $ignore_unrateable = $self->option('ignore_unrateable', 'Hush!'); - my $use_duration = $self->option('use_duration'); - - my $output_format = $self->option('output_format', 'Hush!') || 'default'; + my $included_min = $self->option('min_included', 1) || 0; + my $use_duration = $self->option('use_duration'); + my $output_format = $self->option('output_format', 1) || 'default'; + my $granularity = length($self->option('sec_granularity')) + ? $self->option('sec_granularity') + : 60; #for check_chargable, so we don't keep looking up options inside the loop my %opt_cache = (); - eval "use Text::CSV_XS;"; - die $@ if $@; my $csv = new Text::CSV_XS; foreach my $cust_svc ( @@ -232,19 +222,25 @@ sub calc_usage { my $svc_phone = $cust_svc->svc_x; foreach my $cdr ( $svc_phone->get_cdrs( - 'for_update' => 1, - 'status' => '', # unprocessed only - 'default_prefix' => $self->option('default_prefix'), 'inbound' => 1, + 'default_prefix' => $self->option('default_prefix'), + 'status' => '', # unprocessed only + 'for_update' => 1, ) ) { + + my $reason = $self->check_chargable( $cdr, + 'option_cache' => \%opt_cache, + ); + if ( $reason ) { + warn "not charging for CDR ($reason)\n" if $DEBUG; + next; + } + if ( $DEBUG > 1 ) { warn "rating inbound CDR $cdr\n". join('', map { " $_ => ". $cdr->{$_}. "\n" } keys %$cdr ); } - my $granularity = length($self->option('sec_granularity')) - ? $self->option('sec_granularity') - : 60; my $seconds = $use_duration ? $cdr->duration : $cdr->billsec; @@ -272,18 +268,22 @@ sub calc_usage { if ( $charge > 0 ) { $charges += $charge; - my @call_details = ($cdr->downstream_csv( 'format' => $output_format, - 'charge' => $charge, - 'minutes' => $minutes, - 'granularity' => $granularity, - ) - ); + my @call_details = ( + $cdr->downstream_csv( 'format' => $output_format, + 'charge' => $charge, + 'seconds' => ($use_duration + ? $cdr->duration + : $cdr->billsec + ), + 'granularity' => $granularity, + ) + ); push @$details, [ 'C', $call_details[0], $charge, $cdr->calltypenum, #classnum - $self->phonenum, + '', #phonenum, $cdr->accountcode, $cdr->startdate, $seconds, @@ -349,8 +349,7 @@ sub check_chargable { return "carrierid != $opt{'use_carrierid'}" if length($opt{'use_carrierid'}) - && $cdr->carrierid ne $opt{'use_carrierid'} #ne otherwise 0 matches '' - && ! $flags{'da_rewrote'}; + && $cdr->carrierid ne $opt{'use_carrierid'}; #ne otherwise 0 matches '' return "cdrtypenum != $opt{'use_cdrtypenum'}" if length($opt{'use_cdrtypenum'})