X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fnena2.pm;h=8d59425b71cedf5a14cd10f87e02b707cf83b90c;hb=95759ff41840195d29cc28e492c895d6db55dd8f;hp=85576d20ba0f0cb28e42dea15cf17601a3eaf9bf;hpb=b57377d091b08fe8874d362d885361cc8380ca69;p=freeside.git diff --git a/FS/FS/part_export/nena2.pm b/FS/FS/part_export/nena2.pm index 85576d20b..8d59425b7 100644 --- a/FS/FS/part_export/nena2.pm +++ b/FS/FS/part_export/nena2.pm @@ -15,7 +15,7 @@ my %upload_targets; tie %options, 'Tie::IxHash', ( 'company_name' => { label => 'Company name for header record', - type => 'text' + type => 'text', }, 'company_id' => { label => 'NENA company ID', type => 'text', @@ -23,6 +23,9 @@ tie %options, 'Tie::IxHash', ( 'customer_code' => { label => 'Customer code', type => 'text', }, + 'area_code' => { label => 'Default area code for 7 digit numbers', + type => 'text', + }, 'prefix' => { label => 'File name prefix', type => 'text', }, @@ -166,15 +169,6 @@ my %function_code = ( ); sub immediate { - local $@; - eval "use Geo::StreetAddress::US"; - if ($@) { - if ($@ =~ /^Can't locate/) { - return "Geo::StreetAddress::US must be installed to use the NENA2 export."; - } else { - die $@; - } - } # validate some things my ($self, $action, $svc) = @_; @@ -206,6 +200,15 @@ sub create_item { } sub data { + local $@; + eval "use Geo::StreetAddress::US"; + if ($@) { + if ($@ =~ /^Can't locate/) { + return "Geo::StreetAddress::US must be installed to use the NENA2 export."; + } else { + die $@; + } + } # generate the entire record here. reconciliation of multiple updates to # the same service can be done at process time. my $self = shift; @@ -221,9 +224,15 @@ sub data { my %hash = map { $_ => '' } @{ $item_format->names }; $hash{function_code} = $function_code{$action}; - - # phone number - $svc->phonenum =~ /^(\d{3})(\d*)$/; + + # Add default area code if phonenum is 7 digits + my $phonenum = $svc->phonenum; + if ($self->option('area_code') =~ /^\d{3}$/ && $phonenum =~ /^\d{7}$/ ){ + $phonenum = $self->option('area_code'). $svc->phonenum; + } + + # phone number + $phonenum =~ /^(\d{3})(\d*)$/; $hash{npa} = $1; $hash{calling_number} = $2; @@ -250,11 +259,19 @@ sub data { } else { $hash{location} = $cust_location->address2; } - $hash{location} = $location_hash->{address2}; # customer name and class $hash{customer_name} = $svc->phone_name_or_cust; $hash{class_of_service} = $svc->e911_class; + if (!$hash{class_of_service}) { + # then guess + my $cust_main = $svc->cust_main; + if ($cust_main->company) { + $hash{class_of_service} = '2'; + } else { + $hash{class_of_service} = '1'; + } + } $hash{type_of_service} = $svc->e911_type || '0'; $hash{exchange} = '';