4 #use Spreadsheet::ParseExcel;
6 use FS::UID qw(adminsuidsetup);
13 my $user = shift or usage();
17 #die "Usage:\n\n rate.import user rates.xls worksheet_name";
18 die "Usage:\n\n rate.import user";
23 foreach my $file ( 'areas and rates US.xls',
24 'areas and rates US2.xls',
25 'areas and rates US3.xls',
29 my $dbh = DBI->connect("DBI:Excel:file=$file")
30 or die "can't connect: $DBI::errstr";
32 #my $table = shift or usage();
34 my $sth = $dbh->prepare("select * from $table")
35 or die "can't prepare: ". $dbh->errstr;
37 or die "can't execute: ". $sth->errstr;
39 while ( my $row = $sth->fetchrow_hashref ) {
41 #print join(' - ', map $row->{$_}, qw( rate_center Code Area_Prefix Rate ) ). "\n";
43 my $regionname = $row->{'rate_center'};
44 $regionname =~ s/\xA0//g;
45 #$regionname =~ s/\xE9/e/g; #e with accent aigu
46 $regionname =~ s/(^\s+|\s+$)//;
47 $regionname .= ', USA';
49 my $prefix = $row->{'area_prefix'};
52 #my $prefixprefix = '';
53 #if ( $prefix =~ /^\s*(\d+)\s*\((.*)\)\s*$/ ) {
56 #} elsif ( $prefix =~ /^\s*\((\d{3})\)\s*(.*)$/ ) {
61 my @rate_prefix = map {
62 #warn $row->{'rate_center'}. ": $prefixprefix$_\n";
64 'countrycode' => '1', # $row->{'Country'}
65 #'npa' => $prefixprefix.$_,
69 split(/\s*[;,]\s*/, $prefix);
72 my $dest_detail = new FS::rate_detail {
73 'ratenum' => $ratenum,
76 sprintf('%.2f', $row->{'rate'} ),
77 'sec_granularity' => 60,
80 unless ( exists $rate_region{$regionname} ) {
82 my $rate_region = new FS::rate_region {
83 'regionname' => $regionname,
86 my $error = $rate_region->insert( 'rate_prefix' => \@rate_prefix,
87 'dest_detail' => [ $dest_detail ],
91 $rate_region{$regionname} = $rate_region->regionnum;
95 foreach my $rate_prefix ( @rate_prefix ) {
96 $rate_prefix->regionnum($rate_region{$regionname});
97 my $error = $rate_prefix->insert;
101 #$rate_detail->dest_regionnum($rate_region{$regionname});
102 #$error = $rate_detail->insert;
103 #die $error if $error;