X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fnorthern_911.pm;h=789d839e2573b6c41d0c751dbcabe9c797b48c7b;hp=27f150cbab8e3e5efefa495b022ffff57faed43c;hb=b41ff1359baf325376d41d8c1378e187a208cc8d;hpb=3e8421688bfed701dd6d3be79c270db4af2b3e8d diff --git a/FS/FS/part_export/northern_911.pm b/FS/FS/part_export/northern_911.pm index 27f150cba..789d839e2 100644 --- a/FS/FS/part_export/northern_911.pm +++ b/FS/FS/part_export/northern_911.pm @@ -1,10 +1,11 @@ package FS::part_export::northern_911; +use base 'FS::part_export'; use strict; use vars qw(@ISA %info); use Tie::IxHash; use FS::Record qw(qsearch dbh); -use base 'FS::part_export'; +use WebService::Northern911; use Data::Dumper; tie my %options, 'Tie::IxHash', @@ -22,9 +23,6 @@ tie my %options, 'Tie::IxHash', 'options' => \%options, 'no_machine' => 1, 'notes' => <<'END' -Requires installation of -WebService::Northern911 -from CPAN. END ); @@ -32,9 +30,6 @@ sub client { my $self = shift; if (!$self->get('client')) { - local $@; - eval "use WebService::Northern911"; - return "error loading WebService::Northern911 ($@)" if $@; $self->set('client', WebService::Northern911->new( vendor_code => $self->option('vendor_code'), @@ -47,11 +42,12 @@ sub client { return $self->get('client'); } -sub export_insert { +sub _export_insert { my( $self, $svc_phone ) = (shift, shift); my %location_hash = $svc_phone->location_hash; $location_hash{address1} =~ /^(\w+) +(.*)$/; + my %customer = ( 'PHONE_NUMBER' => $svc_phone->phonenum, 'STREET_NUMBER' => $1, @@ -61,6 +57,31 @@ sub export_insert { 'POSTAL_CODE_ZIP' => $location_hash{zip}, 'OTHER_ADDRESS_INFO' => $location_hash{address2}, ); + my $phone_name = $svc_phone->phone_name; + if ( $phone_name ) { + # could be a personal name or a business... + if ( $svc_phone->e911_class and + grep { $_ eq $svc_phone->e911_class } + ( 2, 4, 5, 6, 7, 0, 'A', 'D', 'E', 'K') + ) + { + # one of the "Business" classes, Centrex, a payphone, or + # VoIP Enterprise class + $customer{'LAST_NAME'} = $phone_name; + } else { + # assume residential, and try (inaccurately) to make a first/last + # name out of it. + @customer{'FIRST_NAME', 'LAST_NAME'} = split(' ', $phone_name, 2); + } + } else { + my $cust_main = $svc_phone->cust_svc->cust_pkg->cust_main; + if ($cust_main->company) { + $customer{'LAST_NAME'} = $cust_main->company; + } else { + $customer{'LAST_NAME'} = $cust_main->last; + $customer{'FIRST_NAME'} = $cust_main->first; + } + } if ($self->option('debug')) { warn "\nAddorUpdateCustomer:\n".Dumper(\%customer)."\n\n"; @@ -72,7 +93,7 @@ sub export_insert { ''; } -sub export_replace { +sub _export_replace { my( $self, $new, $old ) = (shift, shift, shift); # except when changing the phone number, exactly like export_insert; @@ -83,7 +104,7 @@ sub export_replace { $self->export_insert($new); } -sub export_delete { +sub _export_delete { my ($self, $svc_phone) = (shift, shift); if ($self->option('debug')) {