add some debugging to voip_sqlradacct
[freeside.git] / FS / FS / part_pkg / voip_sqlradacct.pm
index 3989cdb..3f044eb 100644 (file)
@@ -1,7 +1,7 @@
 package FS::part_pkg::voip_sqlradacct;
 
 use strict;
-use vars qw(@ISA %info);
+use vars qw(@ISA $DEBUG %info);
 use FS::Record qw(qsearchs qsearch);
 use FS::part_pkg;
 #use FS::rate;
@@ -9,6 +9,8 @@ use FS::rate_prefix;
 
 @ISA = qw(FS::part_pkg);
 
+$DEBUG = 1;
+
 %info = (
     'name' => 'VoIP rating by plan of CDR records in an SQL RADIUS radacct table',
     'fields' => {
@@ -24,8 +26,11 @@ use FS::rate_prefix;
                        'select_key'   => 'ratenum',
                        'select_label' => 'ratename',
                      },
+      'ignore_unrateable' => { 'name' => 'Ignore calls for which not rate prefix can be found (otherwise they are fatal)',
+                               'type' => 'checkbox',
+                             },
     },
-    'fieldorder' => [qw( setup_fee recur_flat ratenum )],
+    'fieldorder' => [qw( setup_fee recur_flat ratenum ignore_unrateable )],
     'weight' => 40,
 );
 
@@ -52,6 +57,7 @@ sub calc_recur {
     foreach my $session (
       $cust_svc->get_session_history( $last_bill, $$sdate )
     ) {
+      warn "rating session $session" if $DEBUG;
 
       ###
       # look up rate details based on called station id
@@ -84,6 +90,8 @@ sub calc_recur {
         $countrycode = '1';
       }
 
+      warn "rating call to +$countrycode $dest" if $DEBUG;
+
       #find a rate prefix, first look at most specific (4 digits) then 3, etc.,
       # finally trying the country code only
       my $rate_prefix = '';
@@ -97,8 +105,15 @@ sub calc_recur {
         'countrycode' => $countrycode,
         'npa'         => '',
       });
-      die "Can't find rate for call to countrycode $countrycode number $dest\n"
-        unless $rate_prefix;
+
+      unless ( $rate_prefix ) {
+        if ( $self->option('ignore_unrateable') ) {
+          warn "  skipping unrateable call to +$countrycode $dest";
+          next;
+        } else {
+          die "Can't find rate for call to +$countrycode $dest\n"
+        }
+      }
 
       my $regionnum = $rate_prefix->regionnum;
 
@@ -107,6 +122,10 @@ sub calc_recur {
         'dest_regionnum' => $regionnum,
       } );
 
+      warn "  found rate for regionnum $regionnum ".
+           "and rate detail $rate_detail"
+        if $DEBUG;
+
       ###
       # find the price and add detail to the invoice
       ###
@@ -130,6 +149,15 @@ sub calc_recur {
         $charges += $charge;
       }
 
+      warn "  adding details on charge to invoice: ".
+           join(' - ', 
+             "+$countrycode $dest",
+             $rate_prefix->rate_region->regionname,
+             $minutes.'m',
+             '$'.$charge,
+           )
+        if $DEBUG;
+
       push @$details, 
         #[
         join(' - ',