[freeside-commits] branch master updated. 9a0f96fd68eb0b75d63a707d182712ea955b8406

Ivan ivan at 420.am
Tue May 23 14:07:46 PDT 2017


The branch, master has been updated
       via  9a0f96fd68eb0b75d63a707d182712ea955b8406 (commit)
      from  884d54765a4709bee112d7204b127670648b7a55 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9a0f96fd68eb0b75d63a707d182712ea955b8406
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue May 23 14:07:45 2017 -0700

    threshold rate import, RT#75897

diff --git a/bin/rate-threshold_tollfree.import b/bin/rate-threshold_tollfree.import
index 3fa9ced..a47f7ff 100755
--- a/bin/rate-threshold_tollfree.import
+++ b/bin/rate-threshold_tollfree.import
@@ -3,7 +3,10 @@
 use strict;
 use Text::CSV;
 use FS::Misc::Getopt;
-use FS::Record qw( dbh );
+use FS::Record qw( qsearch qsearchs dbh );
+use FS::rate;
+use FS::rate_region;
+use FS::rate_prefix;
 
 getopts('');
 
@@ -27,50 +30,97 @@ my $ratenum = $rate->ratenum;
 
 my %rate_region = ();
 
-my $rp = 0;
+my ($rd, $rp, $nr) = (0, 0, 0);
 
 while (my $row = $csv->getline_hr($in)) {
   print $csv->string;
 
-  my $rate_region = new FS::rate_region {
-    'regionname' => $row->{'Originating Location'},
-  };
-  my $rr_error = $rate_region->insert;
-  die $rr_error if $rr_error;
-
-  my $rate_detail = new FS::rate_detail {
-    'ratenum'         => $ratenum,
-    'dest_regionnum'  => $rate_region->regionnum,
-    'conn_charge'     => ( ( $row->{'minimum seconds'} / 60 ) * $row->{'Dedicated Carrier (in US)'} ),
-    'conn_sec'        => $row->{'minimum seconds'},
-    'min_charge'      => $row->{'Dedicated Carrier (in US)'},
-    'sec_granularity' => $row->{"add'l sec increment"},
-    'min_included'    => 0,
-  };
-  my $rd_error = $rate_detail->insert;
-  die $rd_error if $rd_error;
+
+  #no, this creates duplicate regions/prefixes
+  #my $rate_region = new FS::rate_region {
+  #  'regionname' => $row->{'Originating Location'},
+  #};
+  #my $rr_error = $rate_region->insert;
+  #die $rr_error if $rr_error;
 
   my $cc = $row->{'Country Code'};
   my $npa = '';
-
   if ( $row->{'World Zone'} eq '1' ) {
     $npa = $cc;
     $cc = '1';
   }
 
-  my $rate_prefix = new FS::rate_prefix {
-    'regionnum'   => $rate_region->regionnum,
-    'countrycode' => $cc,
-    'npa'         => $npa,
-  };
-  my $rp_error = $rate_prefix->insert;
-  die $rp_error if $rp_error;
+  my @rate_prefix = ();
+  if ( length($npa) ) {
+    push @rate_prefix, qsearchs('rate_prefix', { countrycode=>$cc, npa=>$npa } )
+      or do {
+              my $regionname = $row->{'Originating Location'};
+
+              warn "WARNING: previously unknown countrycode/npa $cc/$npa; ".
+                   "make sure to update previous rates for new '$regionname' ".
+                   "region\n";
+
+              my $rate_region = new FS::rate_region {
+                'regionname' => $row->{'Originating Location'},
+              };
+              my $rr_error = $rate_region->insert;
+              die $rr_error if $rr_error;
+
+              $nr++;
+
+              my $rate_prefix = new FS::rate_prefix {
+                'regionnum'   => $rate_region->regionnum,
+                'countrycode' => $cc,
+                'npa'         => $npa,
+              };
+              my $rp_error = $rate_prefix->insert;
+              die $rp_error if $rp_error;
+
+              push @rate_prefix, $rate_prefix;
+
+            };
+  } else {
+    push @rate_prefix, qsearch('rate_prefix', { countrycode=>$cc } )
+      or die "unknown countrycode/npa $cc/$npa\n";
+  }
+
+  my %saw = ();
+  my @regionnum = grep !$saw{$_}++, map $_->regionnum, @rate_prefix;
+
+  foreach my $regionnum (@regionnum) {
+
+    my $rate_detail = new FS::rate_detail {
+      'ratenum'         => $ratenum,
+      'dest_regionnum'  => $regionnum,
+      'conn_charge'     => ( ( $row->{'minimum seconds'} / 60 ) * $row->{'Dedicated Carrier (in US)'} ),
+      'conn_sec'        => $row->{'minimum seconds'},
+      'min_charge'      => $row->{'Dedicated Carrier (in US)'},
+      'sec_granularity' => $row->{"add'l sec increment"},
+      'min_included'    => 0,
+    };
+    my $rd_error = $rate_detail->insert;
+    die $rd_error if $rd_error;
+
+    $rd++;
+
+  }
+
+
+  #no, this creates duplicate regions/prefixes
+  #my $rate_prefix = new FS::rate_prefix {
+  #  'regionnum'   => $rate_region->regionnum,
+  #  'countrycode' => $cc,
+  #  'npa'         => $npa,
+  #};
+  #my $rp_error = $rate_prefix->insert;
+  #die $rp_error if $rp_error;
   
   $rp++;
 }
 
 dbh->commit;
-print "Inserted $rp regions\n";
+print "Inserted $rd rates for $rp regions\n";
+print "(Inserted $nr new regions)\n";
 
 1;
 

-----------------------------------------------------------------------

Summary of changes:
 bin/rate-threshold_tollfree.import |  106 ++++++++++++++++++++++++++----------
 1 file changed, 78 insertions(+), 28 deletions(-)




More information about the freeside-commits mailing list