1 package SL::Helper::MT940;
 
   5 sub convert_mt940_data {
 
   8   # takes the data from an uploaded mt940 file, converts it to csv via aqbanking and returns the converted data
 
   9   # The uploaded file data is stored as a session file, just like the aqbanking settings file.
 
  11   my $import_filename = 'bank_transfer.940';
 
  12   my $sfile = SL::SessionFile->new($import_filename, mode => '>');
 
  13   $sfile->fh->print($mt940_data);
 
  16   my $aqbin = $::lx_office_conf{applications}->{aqbanking};
 
  17   die "Can't find aqbanking-cli, please check your configuration file.\n" unless -f $aqbin;
 
  18   my $cmd = "$aqbin --cfgdir=\"" . $sfile->get_path . "\" import --importer=\"swift\" --profile=\"SWIFT-MT940\" -f " . $sfile->get_path . "/$import_filename | $aqbin --cfgdir=\"" . $sfile->get_path . "\" listtrans --exporter=\"csv\" --profile=\"AqMoney2\" ";
 
  20   my $converted_data = '"empty";"local_bank_code";"local_account_number";"remote_bank_code";"remote_account_number";"transdate";"valutadate";"amount";"currency";"remote_name";"remote_name_1";"purpose";"purpose1";"purpose2";"purpose3";"purpose4";"purpose5";"purpose6";"purpose7";"purpose8";"purpose9";"purpose10";"purpose11"' . "\n";
 
  22   open my $mt, "-|", "$cmd" || die "Problem with executing aqbanking\n";
 
  23   my $headerline = <$mt>;  # discard original aqbanking header line
 
  25     $converted_data .= $_;
 
  28   return $converted_data;