1 package SL::Controller::BankImport;
4 use parent qw(SL::Controller::Base);
6 use SL::Locale::String qw(t8);
7 use SL::DB::CsvImportProfile;
9 use SL::SessionFile::Random;
11 use Rose::Object::MakeMethods::Generic
13 'scalar --get_set_init' => [ qw(profile) ],
16 __PACKAGE__->run_before('check_auth');
18 sub action_upload_mt940 {
19 my ($self, %params) = @_;
21 $self->setup_upload_mt940_action_bar;
22 $self->render('bankimport/form', title => $::locale->text('MT940 import'), profile => $self->profile ? 1 : 0);
25 sub action_import_mt940 {
26 my ($self, %params) = @_;
28 die "missing file for action import" unless $::form->{file};
30 my $converted_data = SL::Helper::MT940::convert_mt940_data($::form->{file});
32 # store the converted data in a session file and create a temporary profile with it's name
33 my $file = SL::SessionFile::Random->new(mode => '>');
34 $file->fh->print($converted_data);
36 $self->profile->set('file_name', $file->file_name);
37 $self->profile($self->profile->clone_and_reset_deep)->save;
39 die t8("The MT940 import needs an import profile called MT940") unless $self->profile;
41 $self->redirect_to(controller => 'controller.pl', action => 'CsvImport/test', 'profile.type' => 'bank_transactions', 'profile.id' => $self->profile->id, force_profile => 1);
45 $::auth->assert('bank_transaction');
49 my $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => $::myconfig{login});
51 $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => 'default');
56 sub setup_upload_mt940_action_bar {
59 for my $bar ($::request->layout->get('actionbar')) {
62 $::locale->text('Preview'),
63 submit => [ '#form', { action => 'BankImport/import_mt940' } ],