1 package SL::Controller::BankImport;
4 use parent qw(SL::Controller::Base);
6 use SL::Locale::String qw(t8);
7 use SL::DB::CsvImportProfile;
10 use Rose::Object::MakeMethods::Generic
12 'scalar --get_set_init' => [ qw(profile) ],
15 __PACKAGE__->run_before('check_auth');
17 sub action_upload_mt940 {
18 my ($self, %params) = @_;
20 $self->setup_upload_mt940_action_bar;
21 $self->render('bankimport/form', title => $::locale->text('MT940 import'), profile => $self->profile ? 1 : 0);
24 sub action_import_mt940 {
25 my ($self, %params) = @_;
27 die "missing file for action import" unless $::form->{file};
29 my $converted_data = SL::Helper::MT940::convert_mt940_data($::form->{file});
31 # store the converted data in a session file with a name expected by the profile type "bank_transactions"
32 my $file = SL::SessionFile->new("csv-import-bank_transactions.csv", mode => '>');
33 $file->fh->print($converted_data);
36 die t8("The MT940 import needs an import profile called MT940") unless $self->profile;
38 $self->redirect_to(controller => 'controller.pl', action => 'CsvImport/test', 'profile.type' => 'bank_transactions', 'profile.id' => $self->profile->id, force_profile => 1);
42 $::auth->assert('bank_transaction');
46 my $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => $::myconfig{login});
48 $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => 'default');
53 sub setup_upload_mt940_action_bar {
56 for my $bar ($::request->layout->get('actionbar')) {
59 $::locale->text('Preview'),
60 submit => [ '#form', { action => 'BankImport/import_mt940' } ],