X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fvoip_sqlradacct.pm;h=299d5c1d02560404ddeed2f83ab1667bbb7c281a;hp=3f044eb6b4cb084502f4f6e688c3e6600c821c54;hb=f072dc42c97981167acae2e987a4e4e6a6a4d403;hpb=3b6e45a965df08e1ccd6989b000d24913513b764 diff --git a/FS/FS/part_pkg/voip_sqlradacct.pm b/FS/FS/part_pkg/voip_sqlradacct.pm index 3f044eb6b..299d5c1d0 100644 --- a/FS/FS/part_pkg/voip_sqlradacct.pm +++ b/FS/FS/part_pkg/voip_sqlradacct.pm @@ -2,43 +2,43 @@ package FS::part_pkg::voip_sqlradacct; use strict; use vars qw(@ISA $DEBUG %info); +use Date::Format; use FS::Record qw(qsearchs qsearch); -use FS::part_pkg; +use FS::part_pkg::flat; #use FS::rate; use FS::rate_prefix; -@ISA = qw(FS::part_pkg); +@ISA = qw(FS::part_pkg::flat); $DEBUG = 1; %info = ( - 'name' => 'VoIP rating by plan of CDR records in an SQL RADIUS radacct table', - 'fields' => { - 'setup_fee' => { 'name' => 'Setup fee for this package', - 'default' => 0, - }, - 'recur_flat' => { 'name' => 'Base monthly charge for this package', - 'default' => 0, - }, - 'ratenum' => { 'name' => 'Rate plan', - 'type' => 'select', - 'select_table' => 'rate', - 'select_key' => 'ratenum', - 'select_label' => 'ratename', - }, - 'ignore_unrateable' => { 'name' => 'Ignore calls for which not rate prefix can be found (otherwise they are fatal)', - 'type' => 'checkbox', - }, - }, - 'fieldorder' => [qw( setup_fee recur_flat ratenum ignore_unrateable )], - 'weight' => 40, + 'disabled' => 1, #they're sucked into our CDR table now instead + 'name' => 'VoIP rating by plan of CDR records in an SQL RADIUS radacct table', + 'shortname' => 'VoIP/telco CDR rating (external RADIUS)', + 'inherit_fields' => [ 'global_Mixin' ], + 'fields' => { + 'ratenum' => { 'name' => 'Rate plan', + 'type' => 'select-rate', + }, + }, + 'fieldorder' => [qw( ratenum ignore_unrateable )], + 'weight' => 40, ); +sub price_info { + my $self = shift; + my $str = $self->SUPER::price_info(@_); + $str .= " plus usage" if $str; + $str; +} + sub calc_setup { my($self, $cust_pkg ) = @_; $self->option('setup_fee'); } +#false laziness w/voip_cdr... resolve it if this one ever gets used again sub calc_recur { my($self, $cust_pkg, $sdate, $details ) = @_; @@ -57,7 +57,10 @@ sub calc_recur { foreach my $session ( $cust_svc->get_session_history( $last_bill, $$sdate ) ) { - warn "rating session $session" if $DEBUG; + if ( $DEBUG > 1 ) { + warn "rating session $session\n". + join('', map { " $_ => ". $session->{$_}. "\n" } keys %$session ); + } ### # look up rate details based on called station id @@ -69,18 +72,21 @@ sub calc_recur { $dest =~ s/\s//g; my $proto = ''; $dest =~ s/^(\w+):// and $proto = $1; #sip: - my $ip = ''; - $dest =~ s/\@((\d{1,3}\.){3}\d{1,3})$// and $ip = $1; # @10.54.32.1 + my $siphost = ''; + $dest =~ s/\@(.*)$// and $siphost = $1; # @10.54.32.1, @sip.example.com #determine the country code my $countrycode; - if ( $dest =~ /^011((\d\d)(\d))(\d+)$/ ) { - - my( $three, $two, $unknown, $rest ) = ( $1, $2, $3, $4 ); - #first look for 2 digit country code - if ( qsearch('rate_prefix', { 'countrycode' => $two } ) ) { + if ( $dest =~ /^011(((\d)(\d))(\d))(\d+)$/ ) { + + my( $three, $two, $one, $u1, $u2, $rest ) = ( $1, $2, $3, $4, $5, $6 ); + #first look for 1 digit country code + if ( qsearch('rate_prefix', { 'countrycode' => $one } ) ) { + $countrycode = $one; + $dest = $u1.$u2.$rest; + } elsif ( qsearch('rate_prefix', { 'countrycode' => $two } ) ) { #or 2 $countrycode = $two; - $dest = $unknown.$rest; + $dest = $u2.$rest; } else { #3 digit country code $countrycode = $three; $dest = $rest; @@ -88,17 +94,19 @@ sub calc_recur { } else { $countrycode = '1'; + $dest =~ s/^1//;# if length($dest) > 10; } - warn "rating call to +$countrycode $dest" if $DEBUG; + warn "rating call to +$countrycode $dest\n" if $DEBUG; #find a rate prefix, first look at most specific (4 digits) then 3, etc., # finally trying the country code only my $rate_prefix = ''; - for my $len ( reverse(1..4) ) { + for my $len ( reverse(1..6) ) { $rate_prefix = qsearchs('rate_prefix', { 'countrycode' => $countrycode, - 'npa' => { op=> 'LIKE', value=> substr($dest, 0, $len) } + #'npa' => { op=> 'LIKE', value=> substr($dest, 0, $len) } + 'npa' => substr($dest, 0, $len), } ) and last; } $rate_prefix ||= qsearchs('rate_prefix', { @@ -106,31 +114,25 @@ sub calc_recur { 'npa' => '', }); - unless ( $rate_prefix ) { - if ( $self->option('ignore_unrateable') ) { - warn " skipping unrateable call to +$countrycode $dest"; - next; - } else { - die "Can't find rate for call to +$countrycode $dest\n" - } - } + die "Can't find rate for call to +$countrycode $dest\n" + unless $rate_prefix; my $regionnum = $rate_prefix->regionnum; - my $rate_detail = qsearchs('rate_detail', { 'ratenum' => $ratenum, 'dest_regionnum' => $regionnum, } ); warn " found rate for regionnum $regionnum ". - "and rate detail $rate_detail" + "and rate detail $rate_detail\n" if $DEBUG; ### # find the price and add detail to the invoice ### - $included_min{$regionnum} = $rate_detail->min_included + $included_min{$regionnum} = + ($rate_detail->min_included * $cust_pkg->quantity || 1) unless exists $included_min{$regionnum}; my $granularity = $rate_detail->sec_granularity; @@ -149,36 +151,39 @@ sub calc_recur { $charges += $charge; } + my $rate_region = $rate_prefix->rate_region; + warn " (rate region $rate_region)\n" if $DEBUG; + + my @call_details = ( + #time2str("%Y %b %d - %r", $session->{'acctstarttime'}), + time2str("%c", $session->{'acctstarttime'}), + $minutes.'m', + '$'.$charge, + "+$countrycode $dest", + $rate_region->regionname, + ); + warn " adding details on charge to invoice: ". - join(' - ', - "+$countrycode $dest", - $rate_prefix->rate_region->regionname, - $minutes.'m', - '$'.$charge, - ) + join(' - ', @call_details ) if $DEBUG; - push @$details, - #[ - join(' - ', - "+$countrycode $dest", - $rate_prefix->rate_region->regionname, - $minutes.'m', - '$'.$charge, - #] - ) - ; + push @$details, join(' - ', @call_details); #\@call_details, } # $session } # $cust_svc - $self->option('recur_flat') + $charges; + $self->option('recur_fee') + $charges; } -sub is_free { - 0; +sub can_discount { 0; } + +sub is_free { 0; } + +sub base_recur { + my($self, $cust_pkg) = @_; + $self->option('recur_fee'); } 1;