Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / SL / DATEV.pm
index 775d4df..cd04053 100644 (file)
@@ -401,7 +401,7 @@ sub _get_transactions {
     my $firstrun = 1;
     my $subcent  = abs($count) < 0.02;
 
-    while (abs($count) > 0.01 || $firstrun || ($subcent && abs($count) > 0.001)) {
+    while (abs($count) > 0.01 || $firstrun || ($subcent && abs($count) > 0.005)) {
       my $ref2 = $sth->fetchrow_hashref("NAME_lc");
       last unless ($ref2);
 
@@ -426,10 +426,11 @@ sub _get_transactions {
         $ref->{is_tax} = 1;
       }
 
-      if (   !$ref->{invoice}
-          &&  $ref->{is_tax}
-          && !($prev_ref->{is_tax})
-          &&  (_sign($ref->{amount}) == _sign($prev_ref->{amount}))) {
+      if (   !$ref->{invoice}   # we have a non-invoice booking (=gl)
+          &&  $ref->{is_tax}    # that has "is_tax" set
+          && !($prev_ref->{is_tax})  # previous line wasn't is_tax
+          &&  (_sign($ref->{amount}) == _sign($prev_ref->{amount})))  # and sign same as previous sign
+          {
         $trans->[$i - 1]->{tax_amount} = $ref->{amount};
       }
     }
@@ -442,7 +443,10 @@ sub _get_transactions {
     }
 
     for my $j (0 .. (scalar(@{$trans}) - 1)) {
-      if (abs($trans->[$j]->{'amount'}) > abs($absumsatz)) {
+      # for gl-bookings no split is allowed and there is no AR/AP account, so we always use the maximum value as a reference
+      # for ap/ar bookings we can always search for AR/AP in link and use that
+      if ( ( not $trans->[$j]->{'invoice'} and abs($trans->[$j]->{'amount'}) > abs($absumsatz) )
+         or ($trans->[$j]->{'invoice'} and ($trans->[$j]->{'link'} eq 'AR' or $trans->[$j]->{'link'} eq 'AP'))) {
         $absumsatz     = $trans->[$j]->{'amount'};
         $notsplitindex = $j;
       }
@@ -868,7 +872,7 @@ sub kne_buchungsexport {
     $kne_file->add_block($mandantenendsumme);
     $kne_file->flush();
 
-    open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
+    open(ED, ">", $ed_filename) or die "can't open outputfile: $!\n";
     print(ED $kne_file->get_data());
     close(ED);
 
@@ -880,7 +884,7 @@ sub kne_buchungsexport {
   my $ev_header = &make_ev_header($form, $fileno);
   my $ev_filename = $export_path . $evfile;
   push(@filenames, $evfile);
-  open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
+  open(EV, ">", $ev_filename) or die "can't open outputfile: EV01\n";
   print(EV $ev_header);
 
   foreach my $file (@ed_versionset) {
@@ -922,7 +926,7 @@ sub kne_stammdatenexport {
   $filename++;
   my $ed_filename = $export_path . $filename;
   push(@filenames, $filename);
-  open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
+  open(ED, ">", $ed_filename) or die "can't open outputfile: $!\n";
   my $header = &make_kne_data_header($myconfig, $form, "");
   $remaining_bytes -= length($header);
 
@@ -942,7 +946,7 @@ sub kne_stammdatenexport {
     push @values, $form->{accnoto};
   }
 
-  my $where_str = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (scalar @where);
+  my $where_str = @where ? ' WHERE ' . join(' AND ', map { "($_)" } @where) : '';
 
   my $query     = qq|SELECT c.accno, c.description
                      FROM chart c
@@ -994,7 +998,7 @@ sub kne_stammdatenexport {
   my $ev_header = &make_ev_header($form, $fileno);
   my $ev_filename = $export_path . $evfile;
   push(@filenames, $evfile);
-  open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
+  open(EV, ">", $ev_filename) or die "can't open outputfile: EV01\n";
   print(EV $ev_header);
 
   foreach my $file (@ed_versionset) {