CDR rating: migrate use_disposition and use_disposition_taqua to disposition_in,...
authorlevinse <levinse>
Fri, 17 Jun 2011 02:48:44 +0000 (02:48 +0000)
committerlevinse <levinse>
Fri, 17 Jun 2011 02:48:44 +0000 (02:48 +0000)
FS/FS/part_pkg.pm
FS/FS/part_pkg/voip_cdr.pm
FS/FS/part_pkg/voip_inbound.pm

index 2859700..f754167 100644 (file)
@@ -1484,6 +1484,40 @@ sub _upgrade_data { # class method
       die $error if $error;
     }
   }
+
+  # migrate use_disposition_taqua and use_disposition to disposition_in
+  @part_pkg_option = qsearch('part_pkg_option',
+    { 'optionname'  => { op => 'LIKE',
+                         value => 'use_disposition%',
+                       },
+      'optionvalue' => 1,
+    });
+  my %newopts = map { $_->pkgpart => $_ } 
+    qsearch('part_pkg_option',  { 'optionname'  => 'disposition_in', } );
+  foreach my $old_opt (@part_pkg_option) {
+        my $pkgpart = $old_opt->pkgpart;
+        my $newval = $old_opt->optionname eq 'use_disposition_taqua' ? '100' 
+                                                                  : 'ANSWERED';
+        my $error = $old_opt->delete;
+        die $error if $error;
+
+        if ( exists($newopts{$pkgpart}) ) {
+            my $opt = $newopts{$pkgpart};
+            $opt->optionvalue($opt->optionvalue.",$newval");
+            $error = $opt->replace;
+            die $error if $error;
+        } else {
+            my $new_opt = new FS::part_pkg_option {
+                'pkgpart'     => $pkgpart,
+                'optionname'  => 'disposition_in',
+                'optionvalue' => $newval,
+              };
+              $error = $new_opt->insert;
+              die $error if $error;
+              $newopts{$pkgpart} = $new_opt;
+        }
+  }
+
 }
 
 =item curuser_pkgs_sql
index b522a99..158debd 100644 (file)
@@ -141,14 +141,6 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                         'type' => 'checkbox',
                       },
 
-    'use_disposition' => { 'name' => 'Do not charge for CDRs where the disposition flag is not set to "ANSWERED".',
-                           'type' => 'checkbox',
-                         },
-
-    'use_disposition_taqua' => { 'name' => 'Do not charge for CDRs where the disposition is not set to "100" (Taqua).',
-                                 'type' => 'checkbox',
-                               },
-
     'use_carrierid' => { 'name' => 'Do not charge for CDRs where the Carrier ID is not set to: ',
                          },
 
@@ -160,6 +152,9 @@ 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: ',
+                         },
 
     'skip_dst_prefix' => { 'name' => 'Do not charge for CDRs where the destination number starts with any of these values: ',
     },
@@ -275,10 +270,10 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                        disable_src
                        domestic_prefix international_prefix
                        disable_tollfree
-                       use_amaflags use_disposition
-                       use_disposition_taqua use_carrierid 
+                       use_amaflags
+                       use_carrierid 
                        use_cdrtypenum ignore_cdrtypenum
-                       ignore_disposition
+                       ignore_disposition disposition_in
                        skip_dcontext skip_dst_prefix 
                        skip_dstchannel_prefix skip_src_length_more 
                        noskip_src_length_accountcode_tollfree
@@ -881,11 +876,10 @@ sub check_chargable {
 
   my @opt = qw(
     use_amaflags
-    use_disposition
-    use_disposition_taqua
     use_carrierid
     use_cdrtypenum
     ignore_cdrtypenum
+    disposition_in
     ignore_disposition
     skip_dst_prefix
     skip_dcontext
@@ -903,11 +897,9 @@ sub check_chargable {
   return 'amaflags != 2'
     if $opt{'use_amaflags'} && $cdr->amaflags != 2;
 
-  return 'disposition != ANSWERED'
-    if $opt{'use_disposition'} && $cdr->disposition ne 'ANSWERED';
-
-  return "disposition != 100"
-    if $opt{'use_disposition_taqua'} && $cdr->disposition != 100;
+  return "disposition NOT IN ( $opt{'disposition_in'} )"
+    if $opt{'disposition_in'} =~ /\S/
+    && !grep { $cdr->disposition eq $_ } split(/\s*,\s*/, $opt{'disposition_in'});
   
   return "disposition IN ( $opt{'ignore_disposition'} )"
     if $opt{'ignore_disposition'} =~ /\S/
index 7cdf2ab..7b80e02 100644 (file)
@@ -68,14 +68,6 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                         'type' => 'checkbox',
                       },
 
-    'use_disposition' => { 'name' => 'Do not charge for CDRs where the disposition flag is not set to "ANSWERED".',
-                           'type' => 'checkbox',
-                         },
-
-    'use_disposition_taqua' => { 'name' => 'Do not charge for CDRs where the disposition is not set to "100" (Taqua).',
-                                 'type' => 'checkbox',
-                               },
-
     'use_carrierid' => { 'name' => 'Do not charge for CDRs where the Carrier ID is not set to: ',
                          },
 
@@ -87,6 +79,9 @@ 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: ',
+                         },
 
     'skip_dcontext' => { 'name' => 'Do not charge for CDRs where the dcontext is set to any of these (comma-separated) values:',
                        },
@@ -157,10 +152,10 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities();
                        min_charge min_included sec_granularity
                        default_prefix
                        disable_tollfree
-                       use_amaflags use_disposition
-                       use_disposition_taqua use_carrierid
+                       use_amaflags
+                       use_carrierid
                        use_cdrtypenum ignore_cdrtypenum
-                       ignore_disposition
+                       ignore_disposition disposition_in
                        skip_dcontext skip_dstchannel_prefix
                        skip_dst_length_less skip_lastapp
                        use_duration
@@ -333,11 +328,10 @@ sub check_chargable {
 
   my @opt = qw(
     use_amaflags
-    use_disposition
-    use_disposition_taqua
     use_carrierid
     use_cdrtypenum
     ignore_cdrtypenum
+    disposition_in
     ignore_disposition
     skip_dcontext
     skip_dstchannel_prefix
@@ -352,11 +346,9 @@ sub check_chargable {
   return 'amaflags != 2'
     if $opt{'use_amaflags'} && $cdr->amaflags != 2;
 
-  return 'disposition != ANSWERED'
-    if $opt{'use_disposition'} && $cdr->disposition ne 'ANSWERED';
-
-  return "disposition != 100"
-    if $opt{'use_disposition_taqua'} && $cdr->disposition != 100;
+  return "disposition NOT IN ( $opt{'disposition_in'} )"
+    if $opt{'disposition_in'} =~ /\S/
+    && !grep { $cdr->disposition eq $_ } split(/\s*,\s*/, $opt{'disposition_in'});
     
   return "disposition IN ( $opt{'ignore_disposition'} )"
     if $opt{'ignore_disposition'} =~ /\S/