58faf85a19c7d7f384f71ee6ea33c4a2e0d861a8
[kivitendo-erp.git] / SL / Controller / BankImport.pm
1 package SL::Controller::BankImport;
2 use strict;
3 use Data::Dumper;
4 use parent qw(SL::Controller::Base);
5
6 use SL::Locale::String qw(t8);
7 use SL::DB::CsvImportProfile;
8 use SL::Helper::MT940;
9
10
11 sub action_upload_mt940 {
12   my ($self, %params) = @_;
13
14   my $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => $::myconfig{login});
15   $self->render('bankimport/form', title => $::locale->text('MT940 import'), profile => $profile ? 1 : 0);
16
17 }
18
19 sub action_import_mt940 {
20   my ($self, %params) = @_;
21
22   die "missing file for action import" unless $::form->{file};
23
24   my $converted_data = SL::Helper::MT940::convert_mt940_data($::form->{file});
25
26   # store the converted data in a session file with a name expected by the profile type "bank_transactions"
27   my $file = SL::SessionFile->new("csv-import-bank_transactions.csv", mode => '>');
28   $file->fh->print($converted_data);
29   $file->fh->close;
30
31   my $profile = SL::DB::Manager::CsvImportProfile->find_by(name => 'MT940', login => $::myconfig{login});
32   die t8("The MT940 import needs an import profile called MT940") unless $profile;
33
34   $self->redirect_to(controller => 'controller.pl', action => 'CsvImport/test', 'profile.type' => 'bank_transactions', 'profile.id' => $profile->id, force_profile => 1);
35
36 };
37
38 1;
39