X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FBankImport.pm;h=bc65d17b79db811f282a9e838525e945bc30f4b5;hb=bc89ebf428c7bde2205b31c5c9abb66879e673e4;hp=867589f104b0a68aae98012f51d6ffaa8a7b1210;hpb=6ebec7f9d7ddef3e7f8befb797314c89e1414635;p=kivitendo-erp.git diff --git a/SL/Controller/BankImport.pm b/SL/Controller/BankImport.pm index 867589f10..bc65d17b7 100644 --- a/SL/Controller/BankImport.pm +++ b/SL/Controller/BankImport.pm @@ -6,15 +6,20 @@ use parent qw(SL::Controller::Base); use SL::Locale::String qw(t8); use SL::DB::CsvImportProfile; use SL::Helper::MT940; +use SL::SessionFile::Random; + +use Rose::Object::MakeMethods::Generic +( + 'scalar --get_set_init' => [ qw(profile) ], +); __PACKAGE__->run_before('check_auth'); sub action_upload_mt940 { my ($self, %params) = @_; - my $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => $::myconfig{login}); - $self->render('bankimport/form', title => $::locale->text('MT940 import'), profile => $profile ? 1 : 0); - + $self->setup_upload_mt940_action_bar; + $self->render('bankimport/form', title => $::locale->text('MT940 import'), profile => $self->profile ? 1 : 0); } sub action_import_mt940 { @@ -24,21 +29,42 @@ sub action_import_mt940 { my $converted_data = SL::Helper::MT940::convert_mt940_data($::form->{file}); - # store the converted data in a session file with a name expected by the profile type "bank_transactions" - my $file = SL::SessionFile->new("csv-import-bank_transactions.csv", mode => '>'); + # store the converted data in a session file and create a temporary profile with it's name + my $file = SL::SessionFile::Random->new(mode => '>'); $file->fh->print($converted_data); $file->fh->close; + $self->profile->set('file_name', $file->file_name); + $self->profile($self->profile->clone_and_reset_deep)->save; - my $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => $::myconfig{login}); - die t8("The MT940 import needs an import profile called MT940") unless $profile; + die t8("The MT940 import needs an import profile called MT940") unless $self->profile; - $self->redirect_to(controller => 'controller.pl', action => 'CsvImport/test', 'profile.type' => 'bank_transactions', 'profile.id' => $profile->id, force_profile => 1); - -}; + $self->redirect_to(controller => 'controller.pl', action => 'CsvImport/test', 'profile.type' => 'bank_transactions', 'profile.id' => $self->profile->id, force_profile => 1); +} sub check_auth { $::auth->assert('bank_transaction'); } -1; +sub init_profile { + my $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => $::myconfig{login}); + if ( ! $profile ) { + $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => 'default'); + } + return $profile; +} + +sub setup_upload_mt940_action_bar { + my ($self) = @_; + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + $::locale->text('Preview'), + submit => [ '#form', { action => 'BankImport/import_mt940' } ], + accesskey => 'enter', + ], + ); + } +} + +1;