X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport.pm;h=e603faa407023b7b25b55eabfc60769c9a65b73f;hb=e74dac176e01090f7e3b6bd9e99596a36e614284;hp=757110a553b4f44df886d8cd0d1f1ec58eb9eb24;hpb=35948584de818b00974b9dab65682c4d5ceba67f;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 757110a55..e603faa40 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -4,6 +4,7 @@ use strict; use SL::DB::Buchungsgruppe; use SL::DB::CsvImportProfile; +use SL::DB::Unit; use SL::Helper::Flash; use SL::SessionFile; use SL::Controller::CsvImport::Contact; @@ -17,8 +18,8 @@ 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) ], + 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 all_units + import_status errors headers raw_data_headers info_headers data num_imported num_importable displayable_columns) ], ); __PACKAGE__->run_before('check_auth'); @@ -67,6 +68,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, name => $file_name); +} + # # filters # @@ -122,7 +143,12 @@ 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->all_units(SL::DB::Manager::Unit->get_all_sorted); + } + + $self->setup_help; $self->render('csv_import/form', title => $title); } @@ -146,6 +172,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 || [] }); @@ -233,4 +261,11 @@ sub create_worker { : die "Program logic error"; } +sub setup_help { + my ($self) = @_; + + $self->create_worker->setup_displayable_columns; +} + + 1;