skip_max_callers meaning was reversed. doh! RT#9907
[freeside.git] / FS / FS / part_pkg / voip_cdr.pm
index 1d2f673..321be2a 100644 (file)
@@ -95,6 +95,10 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                      'select_label' => 'ratename',
                    },
 
+    'min_included' => { 'name' => 'Minutes included when using "single price per minute" rating method',
+                    },
+
+
     'min_charge' => { 'name' => 'Charge per minute when using "single price per minute" rating method',
                     },
 
@@ -149,10 +153,10 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
     'use_cdrtypenum' => { 'name' => 'Do not charge for CDRs where the CDR Type is not set to: ',
                          },
 
-    'skip_dst_prefix' => { 'name' => 'Do not charge for CDRs where the destination number starts with any of these values:',
+    'skip_dst_prefix' => { 'name' => 'Do not charge for CDRs where the destination number starts with any of these values: ',
     },
 
-    'skip_dcontext' => { 'name' => 'Do not charge for CDRs where the dcontext is set to any of these (comma-separated) values:',
+    'skip_dcontext' => { 'name' => 'Do not charge for CDRs where the dcontext is set to any of these (comma-separated) values: ',
                        },
 
     'skip_dstchannel_prefix' => { 'name' => 'Do not charge for CDRs where the dstchannel starts with:',
@@ -161,12 +165,12 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
     'skip_src_length_more' => { 'name' => 'Do not charge for CDRs where the source is more than this many digits:',
                               },
 
-    'noskip_src_length_accountcode_tollfree' => { 'name' => 'Do charge for CDRs where source is equal or greater than the specified digits and accountcode is toll free',
+    'noskip_src_length_accountcode_tollfree' => { 'name' => 'Do charge for CDRs where source is equal or greater than the specified digits, when accountcode is toll free',
                                                   'type' => 'checkbox',
                                                 },
 
     'accountcode_tollfree_ratenum' => {
-      'name' => 'Optional alternate rate plan when accountcode is toll free',
+      'name' => 'Optional alternate rate plan when accountcode is toll free',
       'type' => 'select',
       'select_table'  => 'rate',
       'select_key'    => 'ratenum',
@@ -178,9 +182,16 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
     'skip_dst_length_less' => { 'name' => 'Do not charge for CDRs where the destination is less than this many digits:',
                               },
 
-    'skip_lastapp' => { 'name' => 'Do not charge for CDRs where the lastapp matches this value',
+    'noskip_dst_length_accountcode_tollfree' => { 'name' => 'Do charge for CDRs where dst is less than the specified digits, when accountcode is toll free',
+                                                  'type' => 'checkbox',
+                                                },
+
+    'skip_lastapp' => { 'name' => 'Do not charge for CDRs where the lastapp matches this value: ',
                       },
 
+    'skip_max_callers' => { 'name' => 'Do not charge for CDRs where max_callers is less than or equal to this value: ',
+                          },
+
     'use_duration'   => { 'name' => 'Calculate usage based on the duration field instead of the billsec field',
                           'type' => 'checkbox',
                         },
@@ -195,7 +206,7 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                          'default'        => 'default', #XXX test
                        },
 
-    'usage_section' => { 'name' => 'Section in which to place usage charges (whether separated or not)',
+    'usage_section' => { 'name' => 'Section in which to place usage charges (whether separated or not)',
                        },
 
     'summarize_usage' => { 'name' => 'Include usage summary with recurring charges when usage is in separate section',
@@ -255,7 +266,10 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                        skip_dstchannel_prefix skip_src_length_more 
                        noskip_src_length_accountcode_tollfree
                        accountcode_tollfree_ratenum
-                       skip_dst_length_less skip_lastapp
+                       skip_dst_length_less
+                       noskip_dst_length_accountcode_tollfree
+                       skip_lastapp
+                       skip_max_callers
                        use_duration
                        411_rewrite
                        output_format usage_mandate summarize_usage usage_section
@@ -314,7 +328,7 @@ sub calc_usage {
 
 #  my $downstream_cdr = '';
 
-  my $cdr_svc_method    = $self->option('cdr_svc_method')||'svc_phone.phonenum';
+  my $cdr_svc_method    = $self->option('cdr_svc_method',1)||'svc_phone.phonenum';
   my $rating_method     = $self->option('rating_method') || 'prefix';
   my $intl              = $self->option('international_prefix') || '011';
   my $domestic_prefix   = $self->option('domestic_prefix');
@@ -699,6 +713,8 @@ sub calc_usage {
 
           $classnum = $rate_detail->classnum;
           $charge = sprintf('%.2f', $charge);
+          warn "Incrementing \$charges by $charge.  Now $charges\n" if $DEBUG;
+          $charges += $charge;
 
           @call_details = (
             $cdr->downstream_csv( 'format'         => $output_format,
@@ -718,8 +734,6 @@ sub calc_usage {
 
         if ( $charge > 0 ) {
           #just use FS::cust_bill_pkg_detail objects?
-          warn "Incrementing \$charges by $charge.  Now $charges\n" if $DEBUG;
-          $charges += $charge;
           my $call_details;
           my $phonenum = $cust_svc->svc_x->phonenum;
 
@@ -827,8 +841,9 @@ sub check_chargable {
     skip_dcontext
     skip_dstchannel_prefix
     skip_src_length_more noskip_src_length_accountcode_tollfree
-    skip_dst_length_less
+    skip_dst_length_less noskip_dst_length_accountcode_tollfree
     skip_lastapp
+    skip_max_callers
   );
   foreach my $opt (grep !exists($flags{option_cache}->{$_}), @opt ) {
     $flags{option_cache}->{$opt} = $self->option($opt, 1);
@@ -869,7 +884,10 @@ sub check_chargable {
 
   my $dst_length = $opt{'skip_dst_length_less'};
   return "destination less than $dst_length digits"
-    if $dst_length && length($cdr->dst) < $dst_length;
+    if $dst_length && length($cdr->dst) < $dst_length
+    && ! ( $opt{'noskip_dst_length_accountcode_tollfree'}
+            && $cdr->is_tollfree
+         );
 
   return "lastapp is $opt{'skip_lastapp'}"
     if length($opt{'skip_lastapp'}) && $cdr->lastapp eq $opt{'skip_lastapp'};
@@ -894,6 +912,11 @@ sub check_chargable {
 
   }
 
+  return "max_callers <= $opt{skip_max_callers}"
+    if length($opt{'skip_max_callers'})
+      and length($cdr->max_callers)
+      and $cdr->max_callers <= $opt{'skip_max_callers'};
+
   #all right then, rate it
   '';
 }