X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/47186d7ac6ce4d55284c8b337ac4eab122f38db1..7cd6d451d97d1f1e7f3c0f9db2de03735dc8c8f0:/SL/Controller/CsvImport/Base.pm diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 2eff5b276..43906bf80 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -188,8 +188,8 @@ sub init_vc_by { vendors => { map { ( $_->vendornumber => $_ ) } @{ $self->all_vc->{vendors} } } ); my %by_name = ( customers => { map { ( $_->name => $_ ) } @{ $self->all_vc->{customers} } }, vendors => { map { ( $_->name => $_ ) } @{ $self->all_vc->{vendors} } } ); - my %by_gln = ( customers => { map { ( $_->gln => $_ ) } @{ $self->all_vc->{customers} } }, - vendors => { map { ( $_->gln => $_ ) } @{ $self->all_vc->{vendors} } } ); + my %by_gln = ( customers => { map { ( $_->gln => $_ ) } grep $_->gln, @{ $self->all_vc->{customers} } }, + vendors => { map { ( $_->gln => $_ ) } grep $_->gln, @{ $self->all_vc->{vendors} } } ); return { id => \%by_id, number => \%by_number, @@ -200,14 +200,14 @@ sub init_vc_by { sub init_vc_counts_by { my ($self) = @_; - my $vc_counts_by; + my $vc_counts_by = {}; $vc_counts_by->{number}->{customers}->{$_->customernumber}++ for @{ $self->all_vc->{customers} }; $vc_counts_by->{number}->{vendors}-> {$_->vendornumber}++ for @{ $self->all_vc->{vendors} }; $vc_counts_by->{name}-> {customers}->{$_->name}++ for @{ $self->all_vc->{customers} }; $vc_counts_by->{name}-> {vendors}-> {$_->name}++ for @{ $self->all_vc->{vendors} }; - $vc_counts_by->{gln}-> {customers}->{$_->gln}++ for @{ $self->all_vc->{customers} }; - $vc_counts_by->{gln}-> {vendors}-> {$_->gln}++ for @{ $self->all_vc->{vendors} }; + $vc_counts_by->{gln}-> {customers}->{$_->gln}++ for grep $_->gln, @{ $self->all_vc->{customers} }; + $vc_counts_by->{gln}-> {vendors}-> {$_->gln}++ for grep $_->gln, @{ $self->all_vc->{vendors} }; return $vc_counts_by; } @@ -221,47 +221,58 @@ sub check_vc { my $is_ambiguous; if (!$entry->{object}->$id_column) { - my $vc = $entry->{raw_data}->{customernumber} && $self->vc_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} }; - if ($vc && $self->vc_counts_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} } > 1) { - $vc = undef; - $is_ambiguous = 1; - } - $vc ||= $entry->{raw_data}->{vendornumber} && $self->vc_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} }; - if ($vc && $self->vc_counts_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} } > 1) { - $vc = undef; - $is_ambiguous = 1; + my $vc; + if ($entry->{raw_data}->{customernumber}) { + $vc = $self->vc_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} }; + if ($vc && $self->vc_counts_by->{number}->{customers}->{ $entry->{raw_data}->{customernumber} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + } elsif ($entry->{raw_data}->{vendornumber}) { + $vc = $self->vc_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} }; + if ($vc && $self->vc_counts_by->{number}->{vendors}->{ $entry->{raw_data}->{vendornumber} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } } $entry->{object}->$id_column($vc->id) if $vc; } if (!$entry->{object}->$id_column) { - my $vc = $entry->{raw_data}->{customer} && $self->vc_by->{name}->{customers}->{ $entry->{raw_data}->{customer} }; - if ($vc && $self->vc_counts_by->{name}->{customers}->{ $entry->{raw_data}->{customer} } > 1) { - $vc = undef; - $is_ambiguous = 1; - } - $vc ||= $entry->{raw_data}->{vendor} && $self->vc_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} }; - if ($vc && $self->vc_counts_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} } > 1) { - $vc = undef; - $is_ambiguous = 1; + my $vc; + if ($entry->{raw_data}->{customer}) { + $vc = $self->vc_by->{name}->{customers}->{ $entry->{raw_data}->{customer} }; + if ($vc && $self->vc_counts_by->{name}->{customers}->{ $entry->{raw_data}->{customer} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + } elsif ($entry->{raw_data}->{vendor}) { + $vc = $self->vc_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} }; + if ($vc && $self->vc_counts_by->{name}->{vendors}->{ $entry->{raw_data}->{vendor} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } } $entry->{object}->$id_column($vc->id) if $vc; } if (!$entry->{object}->$id_column) { - my $vc = $entry->{raw_data}->{customer_gln} && $self->vc_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} }; - if ($vc && $self->vc_counts_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} } > 1) { - $vc = undef; - $is_ambiguous = 1; - } - $vc ||= $entry->{raw_data}->{vendor_gln} && $self->vc_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} }; - if ($vc && $self->vc_counts_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} } > 1) { - $vc = undef; - $is_ambiguous = 1; + my $vc; + if ($entry->{raw_data}->{customer_gln}) { + $vc = $self->vc_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} }; + if ($vc && $self->vc_counts_by->{gln}->{customers}->{ $entry->{raw_data}->{customer_gln} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } + } elsif ($entry->{raw_data}->{vendor_gln}) { + $vc = $self->vc_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} }; + if ($vc && $self->vc_counts_by->{gln}->{vendors}->{ $entry->{raw_data}->{vendor_gln} } > 1) { + $vc = undef; + $is_ambiguous = 1; + } } - $entry->{object}->$id_column($vc->id) if $vc; }