X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport%2FShipto.pm;h=6c01a1426b2325094fca6b7294de807927f7e761;hb=e0f5deeae4cdcf3faf3bc68a202f20ec6cd9af2e;hp=f46c09d33c9732cc6d161be2512b5419a1e39884;hpb=72b340de2352eec7d3f99a00e2141a2df35f07f3;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport/Shipto.pm b/SL/Controller/CsvImport/Shipto.pm index f46c09d33..6c01a1426 100644 --- a/SL/Controller/CsvImport/Shipto.pm +++ b/SL/Controller/CsvImport/Shipto.pm @@ -11,6 +11,9 @@ use Rose::Object::MakeMethods::Generic scalar => [ qw(table) ], ); +sub set_profile_defaults { +}; + sub init_class { my ($self) = @_; $self->class('SL::DB::Shipto'); @@ -19,56 +22,73 @@ sub init_class { sub check_objects { my ($self) = @_; + $self->controller->track_progress(phase => 'building data', progress => 0); + + 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 % 100 == 0; + $self->check_vc($entry, 'trans_id'); $entry->{object}->module('CT'); + } continue { + $i++; } $self->add_info_columns({ header => $::locale->text('Customer/Vendor'), method => 'vc_name' }); } -sub check_duplicates { - my ($self, %params) = @_; - - my $normalizer = sub { my $name = $_[0]; $name =~ s/[\s,\.\-]//g; return $name; }; - my $name_maker = sub { return $normalizer->($_[0]->shiptoname) . '--' . $normalizer->($_[0]->shiptostreet) }; - - my %by_id_and_name; - if ('check_db' eq $self->controller->profile->get('duplicates')) { - foreach my $type (qw(customers vendors)) { - foreach my $vc (@{ $self->all_vc->{$type} }) { - $by_id_and_name{ $vc->id } = { map { ( $name_maker->($_) => 'db' ) } @{ $vc->shipto } }; +sub get_duplicate_check_fields { + return { + shiptoname_and_shiptostreet => { + label => $::locale->text('Name and Street'), + default => 1, + maker => sub { + my $o = shift; + return join( + '--', + $o->trans_id, + map( + { s/[\s,\.\-]//g; $_ } + $o->shiptoname, + $o->shiptostreet + ) + ); } - } - } - - foreach my $entry (@{ $self->controller->data }) { - next if @{ $entry->{errors} }; - - my $name = $name_maker->($entry->{object}); - - $by_id_and_name{ $entry->{vc}->id } ||= { }; - if (!$by_id_and_name{ $entry->{vc}->id }->{ $name }) { - $by_id_and_name{ $entry->{vc}->id }->{ $name } = 'csv'; - - } else { - push @{ $entry->{errors} }, $by_id_and_name{ $entry->{vc}->id }->{ $name } eq 'db' ? $::locale->text('Duplicate in database') : $::locale->text('Duplicate in CSV file'); - } - } -} - -sub field_lengths { - return ( shiptoname => 75, - shiptodepartment_1 => 75, - shiptodepartment_2 => 75, - shiptostreet => 75, - shiptozipcode => 75, - shiptocity => 75, - shiptocountry => 75, - shiptocontact => 75, - shiptophone => 30, - shiptofax => 30, - ); + }, + + shiptoname => { + label => $::locale->text('Name'), + default => 1, + maker => sub { + my $o = shift; + return join( + '--', + $o->trans_id, + map( + { s/[\s,\.\-]//g; $_ } + $o->shiptoname + ) + ); + } + }, + + shiptostreet => { + label => $::locale->text('Street'), + default => 1, + maker => sub { + my $o = shift; + return join( + '--', + $o->trans_id, + map( + { s/[\s,\.\-]//g; $_ } + $o->shiptostreet + ) + ); + } + }, + }; } sub init_profile { @@ -92,6 +112,7 @@ sub setup_displayable_columns { { name => 'shiptodepartment_2', description => $::locale->text('Department 2') }, { name => 'shiptoemail', description => $::locale->text('E-mail') }, { name => 'shiptofax', description => $::locale->text('Fax') }, + { name => 'shiptogln', description => $::locale->text('GLN') }, { name => 'shiptoname', description => $::locale->text('Name') }, { name => 'shiptophone', description => $::locale->text('Phone') }, { name => 'shiptostreet', description => $::locale->text('Street') },