add option to rate CDRs with toll-free accountcodes on src, RT#24031
authorIvan Kohler <ivan@freeside.biz>
Tue, 10 Dec 2013 22:52:08 +0000 (14:52 -0800)
committerIvan Kohler <ivan@freeside.biz>
Tue, 10 Dec 2013 22:52:08 +0000 (14:52 -0800)
FS/FS/cdr.pm
FS/FS/part_pkg/voip_cdr.pm

index bf508dd..5658be9 100644 (file)
@@ -680,8 +680,19 @@ sub rate_prefix {
   # (or calling station id for toll free calls)
   ###
 
   # (or calling station id for toll free calls)
   ###
 
+  my $eff_ratenum = $self->is_tollfree('accountcode')
+    ? $part_pkg->option_cacheable('accountcode_tollfree_ratenum')
+    : '';
+
   my( $to_or_from, $column );
   my( $to_or_from, $column );
-  if ( $self->is_tollfree && ! $part_pkg->option_cacheable('disable_tollfree') )
+  if(
+        ( $self->is_tollfree
+           && ! $part_pkg->option_cacheable('disable_tollfree')
+        )
+     or ( $eff_ratenum
+           && $part_pkg->option_cacheable('accountcode_tollfree_field') eq 'src'
+        )
+    )
   { #tollfree call
     $to_or_from = 'from';
     $column = 'src';
   { #tollfree call
     $to_or_from = 'from';
     $column = 'src';
@@ -702,10 +713,6 @@ sub rate_prefix {
   #asterisks here causes inserting the detail to barf, so:
   $pretty_dst =~ s/\*//g;
 
   #asterisks here causes inserting the detail to barf, so:
   $pretty_dst =~ s/\*//g;
 
-  my $eff_ratenum = $self->is_tollfree('accountcode')
-    ? $part_pkg->option_cacheable('accountcode_tollfree_ratenum')
-    : '';
-
   my $ratename = '';
   my $intrastate_ratenum = $part_pkg->option_cacheable('intrastate_ratenum');
   if ( $intrastate_ratenum && !$self->is_tollfree ) {
   my $ratename = '';
   my $intrastate_ratenum = $part_pkg->option_cacheable('intrastate_ratenum');
   if ( $intrastate_ratenum && !$self->is_tollfree ) {
index f23b7a7..1a99bd7 100644 (file)
@@ -61,6 +61,11 @@ tie my %detail_formats, 'Tie::IxHash',
   FS::cdr::invoice_formats()
 ;
 
   FS::cdr::invoice_formats()
 ;
 
+tie my %accountcode_tollfree_field, 'Tie::IxHash',
+  'dst' => 'Destination (dst)',
+  'src' => 'Source (src)',
+;
+
 %info = (
   'name' => 'VoIP rating by plan of CDR records in an internal (or external) SQL table',
   'shortname' => 'VoIP/telco CDR rating (standard)',
 %info = (
   'name' => 'VoIP rating by plan of CDR records in an internal (or external) SQL table',
   'shortname' => 'VoIP/telco CDR rating (standard)',
@@ -211,6 +216,12 @@ tie my %detail_formats, 'Tie::IxHash',
       'empty_label'   => '',
     },
 
       'empty_label'   => '',
     },
 
+    'accountcode_tollfree_field' => {
+      'name'           => 'When using an alternate rate plan for toll-free accountcodes, the CDR field to use in rating calculations',
+      'type'           => 'select',
+      'select_options' => \%accountcode_tollfree_field,
+    },
+
     'skip_dst_length_less' => { 'name' => 'Do not charge for CDRs where the destination is less than this many digits:',
                               },
 
     'skip_dst_length_less' => { 'name' => 'Do not charge for CDRs where the destination is less than this many digits:',
                               },
 
@@ -330,7 +341,7 @@ tie my %detail_formats, 'Tie::IxHash',
                        skip_dcontext skip_dst_prefix 
                        skip_dstchannel_prefix skip_src_length_more 
                        noskip_src_length_accountcode_tollfree
                        skip_dcontext skip_dst_prefix 
                        skip_dstchannel_prefix skip_src_length_more 
                        noskip_src_length_accountcode_tollfree
-                       accountcode_tollfree_ratenum
+                       accountcode_tollfree_ratenum accountcode_tollfree_field
                        skip_dst_length_less
                        noskip_dst_length_accountcode_tollfree
                        skip_lastapp
                        skip_dst_length_less
                        noskip_dst_length_accountcode_tollfree
                        skip_lastapp