[freeside-commits] branch FREESIDE_4_BRANCH updated. ad732e19a7f1f3553140a057eeb591d7af88fd64
Ivan
ivan at 420.am
Mon May 22 10:05:26 PDT 2017
The branch, FREESIDE_4_BRANCH has been updated
via ad732e19a7f1f3553140a057eeb591d7af88fd64 (commit)
from 8659250344871e79d6445cd853577bb56dcac660 (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 ad732e19a7f1f3553140a057eeb591d7af88fd64
Author: Ivan Kohler <ivan at freeside.biz>
Date: Mon May 22 10:05:25 2017 -0700
threshold rate import, RT#75897
diff --git a/bin/rate-threshold.import b/bin/rate-threshold.import
new file mode 100755
index 0000000..ebc2f8c
--- /dev/null
+++ b/bin/rate-threshold.import
@@ -0,0 +1,89 @@
+#!/usr/bin/perl
+
+use strict;
+use Text::CSV;
+use FS::Misc::Getopt;
+use FS::Record qw( dbh );
+
+getopts('');
+
+$FS::UID::AutoCommit = 0;
+my $dbh = dbh;
+
+my $file = shift or usage();
+open my $in, '<', $file or die "$file: $!\n";
+my $csv = Text::CSV->new({ binary => 1, auto_diag => 2 });
+# set header row
+$csv->column_names($csv->getline($in));
+
+#my $error;
+
+my $rate = new FS::rate {
+ 'ratename' => 'Long Distance base rates',
+};
+my $r_error = $rate->insert;
+die $r_error if $r_error;
+my $ratenum = $rate->ratenum;
+
+my %rate_region = ();
+
+my( $rr, $rp ) = (0,0);
+
+while (my $row = $csv->getline_hr($in)) {
+ print $csv->string;
+
+ my $key = join('|', map $row->{$_}, 'Country Code', 'Destination Name', 'Rate Per Minute (USD)' );
+
+ unless ( $rate_region{$key} ) {
+
+ my $rate_region = new FS::rate_region {
+ 'regionname' => $row->{'Destination Name'},
+ };
+ my $rr_error = $rate_region->insert;
+ die $rr_error if $rr_error;
+ $rate_region{$key} = $rate_region;
+
+ my $rate_detail = new FS::rate_detail {
+ 'ratenum' => $ratenum,
+ 'dest_regionnum' => $rate_region->regionnum,
+ 'conn_charge' => ( ( $row->{'minimum seconds'} / 60 ) * $row->{'Rate Per Minute (USD)'} ),
+ 'conn_sec' => $row->{'minimum seconds'},
+ 'min_charge' => $row->{'Rate Per Minute (USD)'},
+ 'sec_granularity' => $row->{"add'l sec increment"},
+ 'min_included' => 0,
+ };
+ my $rd_error = $rate_detail->insert;
+ die $rd_error if $rd_error;
+
+ $rr++;
+
+ }
+
+ my $cc = $row->{'Country Code'};
+ my $npa = $row->{'Digits'};
+
+ if ( $cc =~ /^1(\d{3})$/ ) {
+ $cc = '1';
+ $npa = $1.$npa;
+ }
+
+ my $rate_prefix = new FS::rate_prefix {
+ 'regionnum' => $rate_region{$key}->regionnum,
+ 'countrycode' => $cc,
+ 'npa' => $npa,
+ };
+ my $rp_error = $rate_prefix->insert;
+ die $rp_error if $rp_error;
+
+ $rp++;
+}
+
+dbh->commit;
+print "Inserted $rp prefixes in $rr regions\n";
+
+1;
+
+sub usage {
+ die "Usage: rate-threshold.import <user> <file>.csv\n\n";
+}
+
diff --git a/bin/rate-threshold_tollfree.import b/bin/rate-threshold_tollfree.import
new file mode 100755
index 0000000..3fa9ced
--- /dev/null
+++ b/bin/rate-threshold_tollfree.import
@@ -0,0 +1,80 @@
+#!/usr/bin/perl
+
+use strict;
+use Text::CSV;
+use FS::Misc::Getopt;
+use FS::Record qw( dbh );
+
+getopts('');
+
+$FS::UID::AutoCommit = 0;
+my $dbh = dbh;
+
+my $file = shift or usage();
+open my $in, '<', $file or die "$file: $!\n";
+my $csv = Text::CSV->new({ binary => 1, auto_diag => 2 });
+# set header row
+$csv->column_names($csv->getline($in));
+
+#my $error;
+
+my $rate = new FS::rate {
+ 'ratename' => 'Toll-Free base rates',
+};
+my $r_error = $rate->insert;
+die $r_error if $r_error;
+my $ratenum = $rate->ratenum;
+
+my %rate_region = ();
+
+my $rp = 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;
+
+ 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;
+
+ $rp++;
+}
+
+dbh->commit;
+print "Inserted $rp regions\n";
+
+1;
+
+sub usage {
+ die "Usage: rate-threshold_tollfree.import <user> <file>.csv\n\n";
+}
+
-----------------------------------------------------------------------
Summary of changes:
bin/{rate-login.import => rate-threshold.import} | 34 ++++-----
bin/rate-threshold_tollfree.import | 80 ++++++++++++++++++++++
2 files changed, 95 insertions(+), 19 deletions(-)
copy bin/{rate-login.import => rate-threshold.import} (62%)
create mode 100755 bin/rate-threshold_tollfree.import
More information about the freeside-commits
mailing list