X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDATEV.pm;h=cd04053ba1b855c0ddf0fd5e447b3f83f48a98a3;hb=b498a3939d86fd9fd7c83e5174103250d8662ca7;hp=d0ca5b2a3850ce038fb5660b1521938dadf126da;hpb=05c6840d4fbb90cbe81e14427617793c45ba4714;p=kivitendo-erp.git diff --git a/SL/DATEV.pm b/SL/DATEV.pm index d0ca5b2a3..cd04053ba 100644 --- a/SL/DATEV.pm +++ b/SL/DATEV.pm @@ -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")) { @@ -398,8 +399,9 @@ sub _get_transactions { my $count = $ref->{amount}; my $firstrun = 1; + my $subcent = abs($count) < 0.02; - while (abs($count) > 0.01 || $firstrun) { + while (abs($count) > 0.01 || $firstrun || ($subcent && abs($count) > 0.005)) { my $ref2 = $sth->fetchrow_hashref("NAME_lc"); last unless ($ref2); @@ -424,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}; } } @@ -440,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; } @@ -866,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); @@ -878,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) { @@ -920,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); @@ -940,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 @@ -992,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) {