X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport%2FPart.pm;h=2ca12300a90f064d94ee27f3ca532dc5e46d217b;hb=cac2ae9bcd47fc55d35c37e25dbb03cd6ac6edeb;hp=d7a892bdd1bf96ebaac6e08ec12f3302360bc6df;hpb=43764f14ab26f3a41b280115c8094485b4a944d4;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport/Part.pm b/SL/Controller/CsvImport/Part.pm index d7a892bdd..2ca12300a 100644 --- a/SL/Controller/CsvImport/Part.pm +++ b/SL/Controller/CsvImport/Part.pm @@ -4,6 +4,7 @@ use strict; use SL::Helper::Csv; +use SL::DBUtils; use SL::DB::Buchungsgruppe; use SL::DB::CustomVariable; use SL::DB::CustomVariableConfig; @@ -60,13 +61,19 @@ sub init_units_by { sub init_parts_by { my ($self) = @_; - my $parts_by = { id => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } }, - partnumber => { part => { }, - service => { } } }; - - foreach my $part (@{ $self->existing_objects }) { - next if $part->assembly; - $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part; +# my $parts_by = { id => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } }, +# partnumber => { part => { }, +# service => { } } }; +# +# foreach my $part (@{ $self->existing_objects }) { +# next if $part->assembly; +# $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part; +# } + + my $parts_by = {}; + my $sth = prepare_execute_query($::form, $::form->get_standard_dbh, 'SELECT partnumber FROM parts'); + while (my ($partnumber) = $sth->fetchrow_array()) { + $parts_by->{partnumber}{$partnumber} = 1; } return $parts_by; @@ -110,7 +117,7 @@ sub check_objects { my $i; my $num_data = scalar @{ $self->controller->data }; foreach my $entry (@{ $self->controller->data }) { - $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 1000 == 0; + $self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0; $self->check_buchungsgruppe($entry); $self->check_type($entry); @@ -196,12 +203,17 @@ sub check_existing { my $object = $entry->{object}; - $entry->{part} = SL::DB::Manager::Part->find_by( - SL::DB::Manager::Part->type_filter($object->type), - ( partnumber => $object->partnumber ) x!! $object->partnumber, - ); + if (!$self->test_run && $object->partnumber && $self->parts_by->{partnumber}{$object->partnumber}) { + $entry->{part} = SL::DB::Manager::Part->find_by( + SL::DB::Manager::Part->type_filter($object->type), + ( partnumber => $object->partnumber ) x!! $object->partnumber, + ); + } if ($self->settings->{article_number_policy} eq 'update_prices') { + if ($object->partnumber && $self->parts_by->{partnumber}{$object->partnumber}) { + push @{ $entry->{information} }, $::locale->text('Updating prices of existing entry in database'); + } if ($entry->{part}) { map { $entry->{part}->$_( $object->$_ ) if defined $object->$_ } qw(sellprice listprice lastcost);