-sub latacheck {
- my ($latanum,$latadesc) = (shift,shift);
- fatal("no lata found for latanum $latanum") unless exists($latas{$latanum});
-
- # unsurprisingly, our idea of a LATA name doesn't always match their idea
- # of the same. Specifically, they randomly expand the state portion and
- # abbreviate it arbitrarily
-
- my $ourdesc = $latas{$latanum};
-
- # strip off the fixed state abbreviation portion in ours
- $ourdesc =~ s/ ..$//;
-
- # strip off the variable state abbreviation (or full name) portion in theirs
- $latadesc =~ s/\s\w+$// unless uc($ourdesc) eq uc($latadesc); # yeah...long story :(
-
- fatal("their LATA description '$latadesc' doesn't match our LATA description '$ourdesc'")
- unless uc($ourdesc) eq uc($latadesc);
-}
-
-# XXX: performance
-sub msacheck {
- my $msadesc = shift;
- my $state = shift;
- my $msanum = -1;
-
- # XXX: no idea what the MSA is for Danbury, so discard it for now and deal with it manually/later
- $msadesc = '' if $msadesc eq 'Danbury';
-
- # hax on hax
- $msadesc = 'Portland OR' if ($msadesc eq 'Portland' && $state eq 'OR');
- $msadesc = 'Portland ME' if ($msadesc eq 'Portland' && $state eq 'ME');
-
- # not everything in their file has a MSA
- if ( $msadesc =~ /^[\w\s]+$/ ) {
-
- # their idea of a MSA differs from our idea of it
- if ( exists($msamap{$msadesc}) ) {
- $msanum = $msamap{$msadesc};
- }
- else {
- my @msa = qsearch('msa', { 'description' => {
- 'op' => 'ILIKE',
- 'value' => "$msadesc%"
- }
- });
-
- # so now we have two cases for a match and everything else is a non-match
- foreach my $msa ( @msa ) {
- # a. our MSA stripped of state portion matches their MSA exactly
- my $msatest1 = $msa->description;
- $msatest1 =~ s/,.*?$//;
- if($msatest1 eq $msadesc) {
- fatal("multiple MSA matches (case 1) for $msadesc") unless $msanum == -1;
- $msanum = $msa->msanum;
- }
-
- # b. our MSA stripped of state portion and up to the first hyphen matches their MSA exactly
- my $msatest2 = $msa->description;
- if($msatest2 =~ /^([\w\s]+)-/ && $1 eq $msadesc) {
- fatal("multiple MSA matches (case 2) for $msadesc") unless $msanum == -1;
- $msanum = $msa->msanum;
- }
- }
-
- $msamap{$msadesc} = $msanum if $msanum != -1;
- }
- fatal("msa $msadesc not found") if $msanum == -1;
- warn "$msadesc matched msanum $msanum for line $linenum\n" if $debug;
- }
-
- $msanum;
-}
-
-sub ratecentercheck {
- my ($rate_center, $rate_center_abbrev) = (shift,shift);
-
- if ( exists $rate_center{$rate_center} ) {
- fatal("rate center abbreviation for '$rate_center' doesn't exist or doesn't match '$rate_center_abbrev'")
- unless ( exists $rate_center_abbrev{$rate_center} &&
- $rate_center_abbrev{$rate_center} eq $rate_center_abbrev);
- } else {
- my $rc = new FS::rate_center{ description => $rate_center };
- my $error = $rc->insert;
- fatal("can't insert rate center '$rate_center': $error") if $error;
- $rate_center{$rate_center} = $rc->ratecenternum;
- $rate_center_abbrev{$rate_center} = $rate_center_abbrev;
- }
-
- $rate_center{$rate_center};