X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pkg%2FImport.pm;h=694d8147f0864a6c56cbdc2ac0e7de5b770e064a;hb=c8d94e67465c81cbdef6e85f6fe303cc3a403e63;hp=9c93677a7cd4a8688bd8f78eb5ec3982a858f355;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/FS/FS/cust_pkg/Import.pm b/FS/FS/cust_pkg/Import.pm index 9c93677a7..694d8147f 100644 --- a/FS/FS/cust_pkg/Import.pm +++ b/FS/FS/cust_pkg/Import.pm @@ -106,6 +106,7 @@ my %formatfields = ( 'svc_acct' => [qw( username _password domsvc )], 'svc_phone' => [qw( countrycode phonenum sip_password pin )], 'svc_external' => [qw( id title )], + 'location' => [qw( address1 address2 city state zip country )], ); sub _formatfields { @@ -115,11 +116,31 @@ sub _formatfields { my %import_options = ( 'table' => 'cust_pkg', + 'preinsert_callback' => sub { + my($record, $param) = @_; + my @location_params = grep /^location\./, keys %$param; + if (@location_params) { + my $cust_location = FS::cust_location->new({ + 'custnum' => $record->custnum, + }); + foreach my $p (@location_params) { + $p =~ /^location.(\w+)$/; + $cust_location->set($1, $param->{$p}); + } + +warn Dumper $cust_location; # XXX + my $error = $cust_location->find_or_insert; # this avoids duplicates + return "error creating location: $error" if $error; + $record->set('locationnum', $cust_location->locationnum); + } + ''; + }, + 'postinsert_callback' => sub { my( $record, $param ) = @_; my $formatfields = _formatfields; - foreach my $svc_x ( grep { $_ ne 'default' } keys %$formatfields ) { + foreach my $svc_x ( grep /^svc/, keys %$formatfields ) { my $ff = $formatfields->{$svc_x}; @@ -170,8 +191,9 @@ sub batch_import { my $format = delete $opt->{'format'}; my @fields = (); - if ( $format =~ /^(.*)-agent_custid$/ ) { + if ( $format =~ /^(.*)-agent_custid(-agent_pkgid)?$/ ) { $format = $1; + my $agent_pkgid = $2; @fields = ( sub { my( $self, $value ) = @_; # $conf, $param @@ -182,6 +204,7 @@ sub batch_import { $self->custnum($cust_main->custnum) if $cust_main; }, ); + push @fields, 'agent_pkgid' if $agent_pkgid; } else { @fields = ( 'custnum' ); }