X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_pkg%2Fvoip_cdr.pm;h=155d8e78caa7962d88ab95d9663991f5e47eaf48;hb=8e21a8c2ce7617a64ec962b3933c77a868682b94;hp=7cf17797253b1e4607a9a1f4bf0e727cc4ac0816;hpb=117b59b69ddc3dab173ec531762686d8c49ad08f;p=freeside.git diff --git a/FS/FS/part_pkg/voip_cdr.pm b/FS/FS/part_pkg/voip_cdr.pm index 7cf177972..155d8e78c 100644 --- a/FS/FS/part_pkg/voip_cdr.pm +++ b/FS/FS/part_pkg/voip_cdr.pm @@ -17,6 +17,7 @@ $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', 'upstream' => 'Rate calls based on upstream data: If the call type is "1", map the upstream rate ID directly to an internal rate (rate_detail), otherwise, pass the upstream price through directly.', + 'upstream_simple' => 'Simply pass through and charge the "upstream_price" amount.', ; #tie my %cdr_location, 'Tie::IxHash', @@ -26,14 +27,15 @@ tie my %rating_method, 'Tie::IxHash', #; %info = ( - 'name' => 'VoIP rating by plan of CDR records in an internal (or external?) SQL table', + 'name' => 'VoIP rating by plan of CDR records in an internal (or external) SQL table', + 'shortname' => 'VoIP/telco CDR rating (standard)', 'fields' => { 'setup_fee' => { 'name' => 'Setup fee for this package', 'default' => 0, }, - 'recur_flat' => { 'name' => 'Base recurring fee for this package', - 'default' => 0, - }, + 'recur_fee' => { 'name' => 'Base recurring fee for this package', + 'default' => 0, + }, 'unused_credit' => { 'name' => 'Credit the customer for the unused portion'. ' of service at cancellation', 'type' => 'checkbox', @@ -45,15 +47,31 @@ tie my %rating_method, 'Tie::IxHash', 'select_label' => 'ratename', }, 'rating_method' => { 'name' => 'Region rating method', - 'type' => 'select', - 'select_options' => \%rating_method, + 'type' => 'radio', + 'options' => \%rating_method, }, 'default_prefix' => { 'name' => 'Default prefix optionally prepended to customer DID numbers when searching for CDR records', 'default' => '+1', }, - #XXX also have option for an external db?? + 'disable_src' => { 'name' => 'Disable rating of CDR records based on the "src" field in addition to "charged_party"', + 'type' => 'checkbox' + }, + + 'domestic_prefix' => { 'name' => 'Destination prefix for domestic CDR records', + 'default' => '1', + }, + +# 'domestic_prefix_required' => { 'name' => 'Require explicit destination prefix for domestic CDR records', +# 'type' => 'checkbox', +# }, + + 'international_prefix' => { 'name' => 'Destination prefix for international CDR records', + 'default' => '011', + }, + + #XXX also have option for an external db # 'cdr_location' => { 'name' => 'CDR database location' # 'type' => 'select', # 'select_options' => \%cdr_location, @@ -77,7 +95,7 @@ tie my %rating_method, 'Tie::IxHash', # }, }, - 'fieldorder' => [qw( setup_fee recur_flat unused_credit ratenum rating_method default_prefix )], + 'fieldorder' => [qw( setup_fee recur_fee unused_credit ratenum rating_method default_prefix disable_src domestic_prefix international_prefix )], 'weight' => 40, ); @@ -144,10 +162,12 @@ sub calc_recur { # $dest =~ s/^(\w+):// and $proto = $1; #sip: # my $siphost = ''; # $dest =~ s/\@(.*)$// and $siphost = $1; # @10.54.32.1, @sip.example.com + + my $intl = $self->option('international_prefix') || '011'; #determine the country code my $countrycode; - if ( $number =~ /^011(((\d)(\d))(\d))(\d+)$/ + if ( $number =~ /^$intl(((\d)(\d))(\d))(\d+)$/ || $number =~ /^\+(((\d)(\d))(\d))(\d+)$/ ) { @@ -166,8 +186,8 @@ sub calc_recur { } } else { - $countrycode = '1'; - $number =~ s/^1//;# if length($number) > 10; + $countrycode = $self->option('domestic_prefix') || '1'; + $number =~ s/^$countrycode//;# if length($number) > 10; } warn "rating call $to_or_from +$countrycode $number\n" if $DEBUG; @@ -189,7 +209,7 @@ sub calc_recur { }); # - die "Can't find rate for call $to_or_from +$countrycode $\numbern" + die "Can't find rate for call $to_or_from +$countrycode $number\n" unless $rate_prefix; $regionnum = $rate_prefix->regionnum; @@ -234,6 +254,22 @@ sub calc_recur { } + } elsif ( $self->option('rating_method') eq 'upstream_simple' ) { + + #XXX $charge = sprintf('%.2f', $cdr->upstream_price); + $charge = sprintf('%.3f', $cdr->upstream_price); + $charges += $charge; + + @call_details = ( + #time2str("%Y %b %d - %r", $cdr->calldate_unix ), + time2str("%c", $cdr->calldate_unix), #XXX this should probably be a config option dropdown so they can select US vs- rest of world dates or whatnot + sprintf('%.2f', $cdr->billsec / 60 ).'m', + '$'.$charge, #XXX $money_char + #$pretty_destnum, + $cdr->userfield, #$rate_region->regionname, + $cdr->dst, + ); + } else { die "don't know how to rate CDRs using method: ". $self->option('rating_method'). "\n"; @@ -260,9 +296,10 @@ sub calc_recur { unless exists $included_min{$regionnum}; my $granularity = $rate_detail->sec_granularity; - my $seconds = $cdr->billsec; # |ength($cdr->billsec) ? $cdr->billsec : $cdr->duration; + my $seconds = $cdr->billsec; # length($cdr->billsec) ? $cdr->billsec : $cdr->duration; $seconds += $granularity - ( $seconds % $granularity ) - if $granularity; # 0 is per call + if $seconds # don't granular-ize 0 billsec calls (bills them) + && $granularity; # 0 is per call my $minutes = sprintf("%.1f", $seconds / 60); $minutes =~ s/\.0$// if $granularity == 60; @@ -294,9 +331,10 @@ sub calc_recur { warn " adding details on charge to invoice: ". join(' - ', @call_details ) - if $DEBUG; + if $DEBUG && $charge > 0; - push @$details, join(' - ', @call_details); #\@call_details, + push @$details, join(' - ', @call_details) #\@call_details, + if $charge > 0; # if the customer flag is on, call "downstream_csv" or something # like it to export the call downstream! @@ -340,7 +378,7 @@ sub calc_recur { } #if ( $spool_cdr && length($downstream_cdr) ) - $self->option('recur_flat') + $charges; + $self->option('recur_fee') + $charges; } @@ -350,7 +388,7 @@ sub is_free { sub base_recur { my($self, $cust_pkg) = @_; - $self->option('recur_flat'); + $self->option('recur_fee'); } 1;