X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDATEV.pm;h=28fc018e60c075d88367dc4b324a5898b962f671;hb=a143b82a56e889cfda60c2d42fe7d0bdaf73aa83;hp=c2549dc7f2e4f869d76daa4ebde77fa7c7ce6aac;hpb=43550a3d3b924a75703d06ab297d05109c06cb37;p=kivitendo-erp.git
diff --git a/SL/DATEV.pm b/SL/DATEV.pm
index c2549dc7f..28fc018e6 100644
--- a/SL/DATEV.pm
+++ b/SL/DATEV.pm
@@ -83,17 +83,17 @@ sub kne_export {
$main::lxdebug->enter_sub();
my ($self, $myconfig, $form) = @_;
- my $rc;
+ my @rc;
if ($form->{exporttype} == 0) {
- $rc = &kne_buchungsexport($myconfig, $form);
+ @rc = &kne_buchungsexport($myconfig, $form);
} else {
- $rc = &kne_stammdatenexport($myconfig, $form);
+ @rc = &kne_stammdatenexport($myconfig, $form);
}
$main::lxdebug->leave_sub();
- return $rc;
+ return @rc;
}
sub obe_export {
@@ -224,30 +224,30 @@ sub get_transactions {
$fromto =~ s/transdate/ac\.transdate/g;
- $query = qq|SELECT taxkey, rate FROM tax|;
+ $query = qq|SELECT id, taxkey, rate FROM tax|;
$sth = $dbh->prepare($query);
$sth->execute || $form->dberror($query);
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- $taxes{ $ref->{taxkey} } = $ref->{rate};
+ $taxes{ $ref->{id} } = $ref->{rate};
}
$sth->finish();
$query =
qq|SELECT ac.oid, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey, ar.invnumber, ar.duedate, ar.amount as umsatz,
- ct.name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate FROM acc_trans ac,ar ar, customer ct,
+ ct.name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac,ar ar, customer ct,
chart c LEFT JOIN tax t ON
(t.chart_id=c.id)WHERE $fromto AND ac.trans_id=ar.id AND ac.trans_id=ar.id
AND ar.customer_id=ct.id AND ac.chart_id=c.id
UNION ALL
SELECT ac.oid, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey, ap.invnumber, ap.duedate, ap.amount as umsatz,
- ct.name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate FROM acc_trans ac, ap ap, vendor ct, chart c LEFT JOIN tax t ON
+ ct.name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac, ap ap, vendor ct, chart c LEFT JOIN tax t ON
(t.chart_id=c.id)
WHERE $fromto AND ac.trans_id=ap.id AND ap.vendor_id=ct.id AND ac.chart_id=c.id
UNION ALL
SELECT ac.oid, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey, gl.reference AS invnumber, gl.transdate AS duedate, ac.amount as umsatz,
- gl.description AS name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate FROM acc_trans ac, gl gl,
+ gl.description AS name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac, gl gl,
chart c LEFT JOIN tax t ON
(t.chart_id=c.id) WHERE $fromto AND ac.trans_id=gl.id AND ac.chart_id=c.id
ORDER BY trans_id, oid|;
@@ -275,6 +275,7 @@ sub get_transactions {
push @{$i}, $ref2;
$firstrun = 0;
}
+ my %taxid_taxkeys = ();
$absumsatz = 0;
if (scalar(@{$i}) > 2) {
for my $j (0 .. (scalar(@{$i}) - 1)) {
@@ -282,6 +283,9 @@ sub get_transactions {
$absumsatz = $i->[$j]->{'amount'};
$notsplitindex = $j;
}
+ if (($i->[$j]->{'taxtaxkey'}) && ($i->[$j]->{'taxid'})) {
+ $taxid_taxkeys{$i->[$j]->{'taxtaxkey'}} = $i->[$j]->{'taxid'};
+ }
}
$ml = ($i->[0]->{'umsatz'} > 0) ? 1 : -1;
for my $j (0 .. (scalar(@{$i}) - 1)) {
@@ -306,24 +310,20 @@ sub get_transactions {
$g++;
} elsif (($j != $notsplitindex) && ($i->[$j]->{'chart_id'} eq "")) {
$absumsatz +=
- ($i->[$j]->{'amount'} * (1 + $taxes{ $i->[$j]->{'taxkey'} }));
+ ($i->[$j]->{'amount'} * (1 + $taxes{ $taxid_taxkeys{$i->[$j]->{'taxkey'}} }));
my %blubb = {};
map({ $blubb{$_} = $i->[$notsplitindex]->{$_}; }
keys(%{ $i->[$notsplitindex] }));
- $test = 1 + $taxes{ $i->[$j]->{'taxkey'} };
+ $test = 1 + $taxes{ $taxid_taxkeys{$i->[$j]->{'taxkey'}} };
$blubb{'amount'} =
$form->round_amount(($i->[$j]->{'amount'} * $test * -1), 2);
- #print(STDERR $test, " Taxrate\n\n");
$blubb{'umsatz'} =
abs($form->round_amount(($i->[$j]->{'amount'} * $test), 2)) * $ml;
$i->[$j]->{'umsatz'} =
abs($form->round_amount(($i->[$j]->{'amount'} * $test), 2)) * $ml;
- #print(STDERR $i->[$j]->{'umsatz'}, " Steuer Umsatz\n");
- #print(STDERR $i->[$j]->{'amount'}, " Steuer Betrag\n");
- #print(STDERR $blubb{'umsatz'}, " Umsatz NOTSPLIT\n");
push @{ $splits[$g] }, \%blubb;
push @{ $splits[$g] }, $i->[$j];
push @{ $form->{DATEV} }, \@{ $splits[$g] };
@@ -333,8 +333,7 @@ sub get_transactions {
}
}
if (abs($absumsatz) > 0.01) {
- print(STDERR $absumsatz, "ABSAUMSATZ\n");
- $form->error("Datev-Export fehlgeschlagen!");
+ $form->error("Datev-Export fehlgeschlagen! Bei Transaktion $i->[0]->{trans_id} $absumsatz\n");
}
} else {
push @{ $form->{DATEV} }, \@{$i};
@@ -396,7 +395,7 @@ sub make_kne_data_header {
$to =~ s/ //g;
if ($from ne "") {
- my ($fday, $fmonth, $fyear) = split /\./, $from;
+ my ($fday, $fmonth, $fyear) = split(/\./, $from);
if (length($fmonth) < 2) {
$fmonth = "0" . $fmonth;
}
@@ -411,7 +410,7 @@ sub make_kne_data_header {
$header .= $from;
if ($to ne "") {
- my ($tday, $tmonth, $tyear) = split /\./, $to;
+ my ($tday, $tmonth, $tyear) = split(/\./, $to);
if (length($tmonth) < 2) {
$tmonth = "0" . $tmonth;
}
@@ -475,7 +474,7 @@ sub datetofour {
my ($date, $six) = @_;
- ($day, $month, $year) = split /\./, $date;
+ ($day, $month, $year) = split(/\./, $date);
if ($day =~ /^0/) {
$day = substr($day, 1, 1);
@@ -504,7 +503,7 @@ sub formatumsatz {
my ($umsatz, $stellen) = @_;
$umsatz =~ s/-//;
- ($vorkomma, $nachkomma) = split /\./, $umsatz;
+ ($vorkomma, $nachkomma) = split(/\./, $umsatz);
$umsatz = "";
if ($stellen > 0) {
for ($i = $stellen; $i >= $stellen + 2 - length($vorkomma); $i--) {
@@ -588,12 +587,14 @@ sub kne_buchungsexport {
my ($myconfig, $form) = @_;
- my $export_path = "datev/";
+ my @filenames;
+
+ my $export_path = $main::userspath . "/";
my $filename = "ED00000";
my $evfile = "EV01";
my @ed_versionsets;
my $fileno = 0;
-
+
$form->header;
print qq|
@@ -616,13 +617,14 @@ sub kne_buchungsexport {
my $buchungssatz = "";
$filename++;
my $ed_filename = $export_path . $filename;
+ push(@filenames, $filename);
open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
$header = &make_kne_data_header($myconfig, $form, $fromto);
$remaining_bytes -= length($header);
while (scalar(@{ $form->{DATEV} }) > 0) {
- $transaction = shift @{ $form->{DATEV} };
- $trans_lines = scalar(@{$transaction});
+ $transaction = shift @{ $form->{DATEV} };
+ $trans_lines = scalar(@{$transaction});
$counter++;
if (($counter % 500) == 0) {
print("$counter ");
@@ -648,8 +650,14 @@ sub kne_buchungsexport {
'ß' => 'sz');
for (my $i = 0; $i < $trans_lines; $i++) {
- if (abs($transaction->[$i]->{'umsatz'}) > abs($umsatz)) {
- $umsatz = $transaction->[$i]->{'umsatz'};
+ if ($trans_lines == 2) {
+ if (abs($transaction->[$i]->{'amount'}) > abs($umsatz)) {
+ $umsatz = $transaction->[$i]->{'amount'};
+ }
+ } else {
+ if (abs($transaction->[$i]->{'umsatz'}) > abs($umsatz)) {
+ $umsatz = $transaction->[$i]->{'umsatz'};
+ }
}
if ($transaction->[$i]->{'datevautomatik'}) {
$datevautomatik = 1;
@@ -821,6 +829,7 @@ sub kne_buchungsexport {
#Make EV Verwaltungsdatei
$ev_header = &make_ev_header($form, $fileno);
$ev_filename = $export_path . $evfile;
+ push(@filenames, $evfile);
open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
print(EV $ev_header);
@@ -828,11 +837,12 @@ sub kne_buchungsexport {
print(EV $ed_versionset[$file]);
}
close(EV);
-print qq|
Done.
-