revert ignore_unrateable behavior change
[freeside.git] / FS / FS / part_pkg / voip_cdr.pm
index 5f191f2..0299227 100644 (file)
@@ -43,6 +43,13 @@ tie my %temporalities, 'Tie::IxHash',
 
 tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
 
+# previously "1" was "ignore"
+tie my %unrateable_opts, 'Tie::IxHash',
+  '' => 'Exit with a fatal error',
+  1  => 'Ignore and continue',
+  2  => 'Flag for later review',
+;
+
 %info = (
   'name' => 'VoIP rating by plan of CDR records in an internal (or external) SQL table',
   'shortname' => 'VoIP/telco CDR rating (standard)',
@@ -105,8 +112,9 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                            'select_options' => \%granularity,
                          },
 
-    'ignore_unrateable' => { 'name' => 'Ignore calls without a rate in the rate tables.  By default, the system will throw a fatal error upon encountering unrateable calls.',
-                             'type' => 'checkbox',
+    'ignore_unrateable' => { 'name' => 'Handling of calls without a rate in the rate table',
+                             'type' => 'select',
+                             'select_options' => \%unrateable_opts,
                            },
 
     'default_prefix' => { 'name'    => 'Default prefix optionally prepended to customer DID numbers when searching for CDR records',
@@ -133,14 +141,14 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                             'type' => 'checkbox',
                           },
 
-    'use_amaflags' => { 'name' => 'Do not charge for CDRs where the amaflags field is not set to "2" ("BILL"/"BILLING").',
+    'use_amaflags' => { 'name' => 'Only charge for CDRs where the amaflags field is set to "2" ("BILL"/"BILLING").',
                         'type' => 'checkbox',
                       },
 
-    'use_carrierid' => { 'name' => 'Do not charge for CDRs where the Carrier ID is not set to: ',
+    'use_carrierid' => { 'name' => 'Only charge for CDRs where the Carrier ID is set to: ',
                          },
 
-    'use_cdrtypenum' => { 'name' => 'Do not charge for CDRs where the CDR Type is not set to: ',
+    'use_cdrtypenum' => { 'name' => 'Only charge for CDRs where the CDR Type is set to: ',
                          },
     
     'ignore_cdrtypenum' => { 'name' => 'Do not charge for CDRs where the CDR Type is set to: ',
@@ -149,7 +157,7 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
     'ignore_disposition' => { 'name' => 'Do not charge for CDRs where the Disposition is set to any of these (comma-separated) values: ',
                          },
     
-    'disposition_in' => { 'name' => 'Do not charge for CDRs where the Disposition is not set to any of these (comma-separated) values: ',
+    'disposition_in' => { 'name' => 'Only charge for CDRs where the Disposition is set to any of these (comma-separated) values: ',
                          },
 
     'skip_dst_prefix' => { 'name' => 'Do not charge for CDRs where the destination number starts with any of these values: ',
@@ -637,8 +645,20 @@ sub calc_usage {
       #if ( ! $rate_detail && ! scalar(@call_details) ) {}
       if ( ! $rate_detail && $charge eq '' ) {
 
-        warn "no rate_detail found for CDR.acctid: ". $cdr->acctid.
-             "; skipping\n"
+        if ( $ignore_unrateable == 2 ) {
+          # mark the CDR as unrateable
+          my $error = $cdr->set_status_and_rated_price(
+            'failed',
+            '',
+            $cust_svc->svcnum
+          );
+          die $error if $error;
+        }
+        elsif ( $ignore_unrateable == 1 ) {
+          # warn and continue
+          warn "no rate_detail found for CDR.acctid: ". $cdr->acctid.
+               "; skipping\n"
+        } #if $ignore_unrateable
 
       } else { # there *is* a rate_detail (or call_details), proceed...
         # About this section:
@@ -899,6 +919,11 @@ sub check_chargable {
     if $opt{'ignore_disposition'} =~ /\S/
     && grep { $cdr->disposition eq $_ } split(/\s*,\s*/, $opt{'ignore_disposition'});
 
+  foreach(split(/\s*,\s*/, $opt{'skip_dst_prefix'})) {
+    return "dst starts with '$_'"
+    if length($_) && substr($cdr->dst,0,length($_)) eq $_;
+  }
+
   return "carrierid != $opt{'use_carrierid'}"
     if length($opt{'use_carrierid'})
     && $cdr->carrierid ne $opt{'use_carrierid'} #ne otherwise 0 matches ''
@@ -912,11 +937,6 @@ sub check_chargable {
     if length($opt{'ignore_cdrtypenum'})
     && $cdr->cdrtypenum eq $opt{'ignore_cdrtypenum'}; #eq otherwise 0 matches ''
 
-  foreach(split(',',$opt{'skip_dst_prefix'})) {
-    return "dst starts with '$_'"
-    if length($_) && substr($cdr->dst,0,length($_)) eq $_;
-  }
-
   return "dcontext IN ( $opt{'skip_dcontext'} )"
     if $opt{'skip_dcontext'} =~ /\S/
     && grep { $cdr->dcontext eq $_ } split(/\s*,\s*/, $opt{'skip_dcontext'});