kivitendo/SL/Controller/BankImport.pm @ 031566ec
d180d84e | Geoffrey Richardson | package SL::Controller::BankImport;
|
||
use strict;
|
||||
use Data::Dumper;
|
||||
use parent qw(SL::Controller::Base);
|
||||
use SL::Locale::String qw(t8);
|
||||
use SL::DB::CsvImportProfile;
|
||||
use SL::Helper::MT940;
|
||||
401fc133 | Bernd Bleßmann | use SL::SessionFile::Random;
|
||
d180d84e | Geoffrey Richardson | |||
4fef0591 | Bernd Bleßmann | use Rose::Object::MakeMethods::Generic
|
||
(
|
||||
'scalar --get_set_init' => [ qw(profile) ],
|
||||
);
|
||||
6ebec7f9 | Geoffrey Richardson | __PACKAGE__->run_before('check_auth');
|
||
d180d84e | Geoffrey Richardson | |||
sub action_upload_mt940 {
|
||||
my ($self, %params) = @_;
|
||||
37c03103 | Moritz Bunkus | $self->setup_upload_mt940_action_bar;
|
||
4fef0591 | Bernd Bleßmann | $self->render('bankimport/form', title => $::locale->text('MT940 import'), profile => $self->profile ? 1 : 0);
|
||
d180d84e | Geoffrey Richardson | }
|
||
sub action_import_mt940 {
|
||||
my ($self, %params) = @_;
|
||||
die "missing file for action import" unless $::form->{file};
|
||||
my $converted_data = SL::Helper::MT940::convert_mt940_data($::form->{file});
|
||||
401fc133 | Bernd Bleßmann | # store the converted data in a session file and create a temporary profile with it's name
|
||
my $file = SL::SessionFile::Random->new(mode => '>');
|
||||
d180d84e | Geoffrey Richardson | $file->fh->print($converted_data);
|
||
$file->fh->close;
|
||||
401fc133 | Bernd Bleßmann | $self->profile->set('file_name', $file->file_name);
|
||
$self->profile($self->profile->clone_and_reset_deep)->save;
|
||||
d180d84e | Geoffrey Richardson | |||
4fef0591 | Bernd Bleßmann | die t8("The MT940 import needs an import profile called MT940") unless $self->profile;
|
||
d180d84e | Geoffrey Richardson | |||
4fef0591 | Bernd Bleßmann | $self->redirect_to(controller => 'controller.pl', action => 'CsvImport/test', 'profile.type' => 'bank_transactions', 'profile.id' => $self->profile->id, force_profile => 1);
|
||
37c03103 | Moritz Bunkus | }
|
||
d180d84e | Geoffrey Richardson | |||
6ebec7f9 | Geoffrey Richardson | sub check_auth {
|
||
$::auth->assert('bank_transaction');
|
||||
}
|
||||
4fef0591 | Bernd Bleßmann | 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;
|
||||
}
|
||||
37c03103 | Moritz Bunkus | 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',
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
d180d84e | Geoffrey Richardson | |||
37c03103 | Moritz Bunkus | 1;
|