X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FCsvImport.pm;h=9549ae2a7dd352b1dbc6f8e42ce1060cca1899f9;hb=d582b83d62fea84292843a34dcee163929a4384e;hp=c2f2a6ce06f017eb0aec6c2c5ecdaafa2f960dd4;hpb=7caf72fffe2dfe58d11da0acd0e2892e6737330a;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index c2f2a6ce0..9549ae2a7 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -18,7 +18,7 @@ use parent qw(SL::Controller::Base); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen - import_status errors headers raw_data_headers data num_imported num_importable worker displayable_columns) ], + import_status errors headers raw_data_headers info_headers data num_imported num_importable displayable_columns) ], ); __PACKAGE__->run_before('check_auth'); @@ -67,6 +67,26 @@ sub action_destroy { $self->redirect_to(action => 'new', 'profile.type' => $self->type); } +sub action_download_sample { + my $self = shift; + + $self->profile_from_form; + $self->setup_help; + + my $file_name = 'csv_import_sample_' . $self->type . '.csv'; + my $file = SL::SessionFile->new($file_name, mode => '>', encoding => $self->profile->get('charset')); + my $csv = Text::CSV_XS->new({ binary => 1, map { ( $_ => $self->profile->get($_) ) } qw(sep_char escape_char quote_char),}); + + $csv->print($file->fh, [ map { $_->{name} } @{ $self->displayable_columns } ]); + $file->fh->print("\r\n"); + $csv->print($file->fh, [ map { $_->{description} } @{ $self->displayable_columns } ]); + $file->fh->print("\r\n"); + + $file->fh->close; + + $self->send_file($file->file_name); +} + # # filters # @@ -122,7 +142,9 @@ sub render_inputs { : $self->type eq 'parts' ? $::locale->text('CSV import: parts and services') : die; - $self->all_buchungsgruppen(SL::DB::Manager::Buchungsgruppe->get_all_sorted); + if ($self->{type} eq 'parts') { + $self->all_buchungsgruppen(SL::DB::Manager::Buchungsgruppe->get_all_sorted); + } $self->setup_help; @@ -148,6 +170,8 @@ sub test_and_import { my $worker = $self->create_worker($file); $worker->run; + + $self->num_imported(0); $worker->save_objects if !$params{test}; $self->num_importable(scalar grep { !$_ } map { scalar @{ $_->{errors} } } @{ $self->data || [] });