X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/13b5fc65921f5c030a64a3c6f2faf4c822bc14a4..7caf72fffe2dfe58d11da0acd0e2892e6737330a:/SL/Controller/CsvImport.pm diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 806429d7d..c2f2a6ce0 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -6,7 +6,10 @@ use SL::DB::Buchungsgruppe; use SL::DB::CsvImportProfile; use SL::Helper::Flash; use SL::SessionFile; +use SL::Controller::CsvImport::Contact; use SL::Controller::CsvImport::CustomerVendor; +use SL::Controller::CsvImport::Part; +use SL::Controller::CsvImport::Shipto; use List::MoreUtils qw(none); @@ -15,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 data num_imported num_importable) ], + import_status errors headers raw_data_headers data num_imported num_importable worker displayable_columns) ], ); __PACKAGE__->run_before('check_auth'); @@ -121,6 +124,8 @@ sub render_inputs { $self->all_buchungsgruppen(SL::DB::Manager::Buchungsgruppe->get_all_sorted); + $self->setup_help; + $self->render('csv_import/form', title => $title); } @@ -141,15 +146,15 @@ sub test_and_import { return $self->action_new; } - my $worker = $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(controller => $self, file => $file) - : die "Program logic error"; - + my $worker = $self->create_worker($file); $worker->run; $worker->save_objects if !$params{test}; - $self->num_importable(scalar grep { !$_ } map { scalar @{ $_->{errors} } } @{ $self->data }); + $self->num_importable(scalar grep { !$_ } map { scalar @{ $_->{errors} } } @{ $self->data || [] }); $self->import_status($params{test} ? 'tested' : 'imported'); + flash('info', $::locale->text('Objects have been imported.')) if !$params{test}; + $self->action_new; } @@ -188,6 +193,10 @@ sub profile_from_form { push @settings, { key => "${type}_char", value => $char }; } + if ($self->type eq 'parts') { + $::form->{settings}->{sellprice_adjustment} = $::form->parse_amount(\%::myconfig, $::form->{settings}->{sellprice_adjustment}); + } + delete $::form->{profile}->{id}; $self->profile($existing_profile || SL::DB::CsvImportProfile->new); $self->profile->assign_attributes(%{ $::form->{profile} }); @@ -216,4 +225,21 @@ sub csv_file_name { return "csv-import-" . $self->type . ".csv"; } +sub create_worker { + my ($self, $file) = @_; + + return $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(controller => $self, file => $file) + : $self->{type} eq 'contacts' ? SL::Controller::CsvImport::Contact->new( controller => $self, file => $file) + : $self->{type} eq 'addresses' ? SL::Controller::CsvImport::Shipto->new( controller => $self, file => $file) + : $self->{type} eq 'parts' ? SL::Controller::CsvImport::Part->new( controller => $self, file => $file) + : die "Program logic error"; +} + +sub setup_help { + my ($self) = @_; + + $self->create_worker->setup_displayable_columns; +} + + 1;