X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FCsv%2FDispatcher.pm;h=801e8229f2bfb2d997376bde3c7383306119c4d8;hb=bfa674c9d4edc551afa6e27aac6f684a7b8cb656;hp=a08a63397b38628f1f349856e691c8b71f208a72;hpb=8ad3a60e282dc36dd0738751ff714e1d04abdd8f;p=kivitendo-erp.git diff --git a/SL/Helper/Csv/Dispatcher.pm b/SL/Helper/Csv/Dispatcher.pm index a08a63397..801e8229f 100644 --- a/SL/Helper/Csv/Dispatcher.pm +++ b/SL/Helper/Csv/Dispatcher.pm @@ -99,8 +99,8 @@ sub apply { } sub is_known { - my ($self, $col) = @_; - return grep { $col eq $_->{key} } $self->_specs; + my ($self, $col, $row) = @_; + return grep { $col eq $_->{key} } @{ $self->_specs->[$row // 0] }; } sub parse_profile { @@ -109,9 +109,11 @@ sub parse_profile { my @specs; my $csv_profile = $self->_csv->profile; + my $h_aref = ($self->_csv->is_multiplexed)? $self->_csv->header : [ $self->_csv->header ]; my $i = 0; - foreach my $header (@{ $self->_csv->header }) { + foreach my $header (@{ $h_aref }) { my $spec = $self->_parse_profile(profile => $csv_profile->[$i]->{profile}, + mapping => $csv_profile->[$i]->{mapping}, class => $csv_profile->[$i]->{class}, header => $header); push @specs, $spec; @@ -128,23 +130,24 @@ sub parse_profile { sub _parse_profile { my ($self, %params) = @_; - my $profile = $params{profile}; + my $profile = $params{profile} // {}; my $class = $params{class}; my $header = $params{header}; + my $mapping = $params{mapping}; my @specs; for my $col (@$header) { next unless $col; - if ($self->_csv->strict_profile) { - if (exists $profile->{$col}) { - push @specs, $self->make_spec($col, $profile->{$col}, $class); - } else { - $self->unknown_column($col, undef); - } + if (exists $mapping->{$col} && $profile->{$mapping->{$col}}) { + push @specs, $self->make_spec($col, $profile->{$mapping->{$col}}, $class); + } elsif (exists $mapping->{$col} && !%{ $profile }) { + push @specs, $self->make_spec($col, $mapping->{$col}, $class); + } elsif (exists $profile->{$col}) { + push @specs, $self->make_spec($col, $profile->{$col}, $class); } else { - if (exists $profile->{$col}) { - push @specs, $self->make_spec($col, $profile->{$col}, $class); + if ($self->_csv->strict_profile) { + $self->unknown_column($col, undef); } else { push @specs, $self->make_spec($col, $col, $class); } @@ -157,7 +160,7 @@ sub _parse_profile { sub make_spec { my ($self, $col, $path, $cur_class) = @_; - my $spec = { key => $col, steps => [] }; + my $spec = { key => $col, path => $path, steps => [] }; return unless $path;