From 4fef059183b047e18d8fee7b4b75195b83d6ef23 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 20 Feb 2017 21:08:14 +0100 Subject: [PATCH] =?utf8?q?BankImport:=20Refactoring:=20Profil=20=C3=BCber?= =?utf8?q?=20init-Methode=20laden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/BankImport.pm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/SL/Controller/BankImport.pm b/SL/Controller/BankImport.pm index 6204e736a..7e08fc603 100644 --- a/SL/Controller/BankImport.pm +++ b/SL/Controller/BankImport.pm @@ -7,18 +7,18 @@ use SL::Locale::String qw(t8); use SL::DB::CsvImportProfile; use SL::Helper::MT940; +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}); - if ( ! $profile ) { - $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => 'default'); - } - $self->setup_upload_mt940_action_bar; - $self->render('bankimport/form', title => $::locale->text('MT940 import'), profile => $profile ? 1 : 0); + $self->render('bankimport/form', title => $::locale->text('MT940 import'), profile => $self->profile ? 1 : 0); } sub action_import_mt940 { @@ -33,19 +33,23 @@ sub action_import_mt940 { $file->fh->print($converted_data); $file->fh->close; - 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'); - } - 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'); } +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) = @_; -- 2.20.1