4 #use Spreadsheet::ParseExcel;
6 use FS::UID qw(adminsuidsetup);
13 my $user = shift or usage();
16 #my $file = shift or usage();
17 my $file = 'areas and rates.xls';
18 my $dbh = DBI->connect("DBI:Excel:file=$file")
19 or die "can't connect: $DBI::errstr";
21 #my $table = shift or usage();
22 my $table = 'areas_and_rates';
23 my $sth = $dbh->prepare("select * from $table")
24 or die "can't prepare: ". $dbh->errstr;
26 or die "can't execute: ". $sth->errstr;
29 #die "Usage:\n\n rate.import user rates.xls worksheet_name";
30 die "Usage:\n\n rate.import user";
35 while ( my $row = $sth->fetchrow_hashref ) {
37 #print join(' - ', map $row->{$_}, qw( Country Code Area_Prefix Rate ) ). "\n";
39 my $regionname = $row->{'Country'};
40 $regionname =~ s/\xA0//g;
41 $regionname =~ s/\xE9/e/g; #e with accent aigu
42 $regionname =~ s/(^\s+|\s+$)//;
44 #next if $regionname =~ /Sweden Telia Mobile/;
46 my $rate_region = new FS::rate_region {
47 'regionname' => $regionname,
50 my $prefix = $row->{'Area_Prefix'};
53 my $prefixprefix = '';
54 if ( $prefix =~ /^\s*(\d+)\s*\((.*)\)\s*$/ ) {
57 } elsif ( $prefix =~ /^\s*\((\d{3})\)\s*(.*)$/ ) {
63 if ( $prefix =~ /\d/ ) {
66 #warn $row->{'Country'}. ": $prefixprefix$_\n";
68 'countrycode' => $row->{'Code'},
69 'npa' => $prefixprefix.$_,
72 split(/\s*[;,]\s*/, $prefix);
75 @rate_prefix = ( new FS::rate_prefix {
76 'countycode' => $row->{'Code'},
82 my $dest_detail = new FS::rate_detail {
83 'ratenum' => $ratenum,
86 sprintf('%.2f', $row->{'Rate'} ),
87 'sec_granularity' => 60,
90 my $error = $rate_region->insert( 'rate_prefix' => \@rate_prefix,
91 'dest_detail' => [ $dest_detail ],