Merge branch 'master' of git@lx-office.linet-services.de:lx-office-erp
[kivitendo-erp.git] / SL / DATEV.pm
index 49e824b..60eb97f 100644 (file)
@@ -26,7 +26,8 @@
 
 package DATEV;
 
-use List::Util qw(max);
+use utf8;
+use strict;
 
 use SL::DBUtils;
 use SL::DATEV::KNEFile;
@@ -34,10 +35,9 @@ use SL::Taxkeys;
 
 use Data::Dumper;
 use File::Path;
+use List::Util qw(max);
 use Time::HiRes qw(gettimeofday);
 
-use strict;
-
 sub _get_export_path {
   $main::lxdebug->enter_sub();
 
@@ -58,7 +58,7 @@ sub get_path_for_download_token {
   my $path;
 
   if ($token =~ m|^(\d+)-(\d+)-(\d+)$|) {
-    $path = "${main::userspath}/datev-export-${1}-${2}-${3}";
+    $path = $::lx_office_conf{paths}->{userspath} . "/datev-export-${1}-${2}-${3}";
   }
 
   $main::lxdebug->leave_sub();
@@ -84,7 +84,7 @@ sub get_download_token_for_path {
 sub clean_temporary_directories {
   $main::lxdebug->enter_sub();
 
-  foreach my $path (glob "${main::userspath}/datev-export-*") {
+  foreach my $path (glob($::lx_office_conf{paths}->{userspath} . "/datev-export-*")) {
     next unless (-d $path);
 
     my $mtime = (stat($path))[9];
@@ -386,6 +386,7 @@ sub _get_transactions {
        ORDER BY trans_id, acc_trans_id|;
 
   my $sth = prepare_execute_query($form, $dbh, $query);
+  $form->{DATEV} = [];
 
   my $counter = 0;
   while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
@@ -405,7 +406,7 @@ sub _get_transactions {
 
       if ($ref2->{trans_id} != $trans->[0]->{trans_id}) {
         $form->error("Unbalanced ledger! old trans_id " . $trans->[0]->{trans_id} . " new trans_id " . $ref2->{trans_id} . " count $count");
-        exit 1;
+        ::end_of_request();
       }
 
       push @{ $trans }, $ref2;
@@ -776,14 +777,14 @@ sub kne_buchungsexport {
       my $taxkey         = 0;
       my $charttax       = 0;
       my ($haben, $soll);
-      my $iconv          = $main::locale->{iconv_iso8859};
-      my %umlaute = ($iconv->convert('ä') => 'ae',
-                     $iconv->convert('ö') => 'oe',
-                     $iconv->convert('ü') => 'ue',
-                     $iconv->convert('Ä') => 'Ae',
-                     $iconv->convert('Ö') => 'Oe',
-                     $iconv->convert('Ü') => 'Ue',
-                     $iconv->convert('ß') => 'sz');
+      my $iconv          = $::locale->{iconv_utf8};
+      my %umlaute = ($iconv->convert('ä') => 'ae',
+                     $iconv->convert('ö') => 'oe',
+                     $iconv->convert('ü') => 'ue',
+                     $iconv->convert('Ä') => 'Ae',
+                     $iconv->convert('Ö') => 'Oe',
+                     $iconv->convert('Ü') => 'Ue',
+                     $iconv->convert('ß') => 'sz');
       for (my $i = 0; $i < $trans_lines; $i++) {
         if ($trans_lines == 2) {
           if (abs($transaction->[$i]->{'amount'}) > abs($umsatz)) {