Revision ea711360
Von Moritz Bunkus vor mehr als 16 Jahren hinzugefügt
SL/DATEV.pm | ||
---|---|---|
return $fromto;
|
||
}
|
||
|
||
sub get_transactions {
|
||
sub _get_transactions {
|
||
$main::lxdebug->enter_sub();
|
||
|
||
my $dbh = $form->get_standard_dbh($myconfig);
|
||
my $fromto = shift;
|
||
|
||
$fromto =~ s/transdate/ac\.transdate/g;
|
||
my $myconfig = \%main::myconfig;
|
||
my $form = $main::form;
|
||
|
||
my %taxes = selectall_as_map($form, $dbh, qq|SELECT id, rate FROM tax|, 'id', 'rate');
|
||
my $dbh = $form->get_standard_dbh($myconfig);
|
||
|
||
my $query =
|
||
$fromto =~ s/transdate/ac\.transdate/g;
|
||
|
||
my %taxes = selectall_as_map($form, $dbh, qq|SELECT id, rate FROM tax|, 'id', 'rate');
|
||
|
||
my $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,
|
||
... | ... | |
|
||
ORDER BY trans_id, oid|;
|
||
|
||
my $sth = prepare_execute_query($form, $dbh, $query);
|
||
my $sth = prepare_execute_query($form, $dbh, $query);
|
||
|
||
$i = 0;
|
||
$g = 0;
|
||
my $g = 0;
|
||
my $counter = 0;
|
||
my @splits;
|
||
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
|
||
$count = 0;
|
||
$firstrun = 1;
|
||
$counter++;
|
||
if (($counter % 500) == 0) {
|
||
print("$counter ");
|
||
}
|
||
|
||
$count += $ref->{amount};
|
||
push @{$i}, $ref;
|
||
my $i = [ $ref ];
|
||
|
||
my $count = $ref->{amount};
|
||
my $firstrun = 1;
|
||
|
||
while (abs($count) > 0.01 || $firstrun) {
|
||
$ref2 = $sth->fetchrow_hashref(NAME_lc);
|
||
my $ref2 = $sth->fetchrow_hashref(NAME_lc);
|
||
last unless ($ref2);
|
||
$count += $ref2->{amount};
|
||
|
||
push @{$i}, $ref2;
|
||
$firstrun = 0;
|
||
|
||
$count += $ref2->{amount};
|
||
$firstrun = 0;
|
||
}
|
||
|
||
my %taxid_taxkeys = ();
|
||
$absumsatz = 0;
|
||
if (scalar(@{$i}) > 2) {
|
||
for my $j (0 .. (scalar(@{$i}) - 1)) {
|
||
if (abs($i->[$j]->{'amount'}) > abs($absumsatz)) {
|
||
$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)) {
|
||
if ( ($j != $notsplitindex)
|
||
&& ($i->[$j]->{'chart_id'} eq "")
|
||
&& ( $i->[$j]->{'taxkey'} eq ""
|
||
|| $i->[$j]->{'taxkey'} eq "0"
|
||
|| $i->[$j]->{'taxkey'} eq "1"
|
||
|| $i->[$j]->{'taxkey'} eq "10"
|
||
|| $i->[$j]->{'taxkey'} eq "11")) {
|
||
my %blubb = {};
|
||
map({ $blubb{$_} = $i->[$notsplitindex]->{$_}; } keys(%{ $i->[$notsplitindex] }));
|
||
|
||
$absumsatz += $i->[$j]->{'amount'};
|
||
$blubb{'amount'} = $i->[$j]->{'amount'} * (-1);
|
||
$blubb{'umsatz'} = abs($i->[$j]->{'amount'}) * $ml;
|
||
$i->[$j]->{'umsatz'} = abs($i->[$j]->{'amount'}) * $ml;
|
||
|
||
push @{ $splits[$g] }, \%blubb; #$i->[$notsplitindex];
|
||
push @{ $splits[$g] }, $i->[$j];
|
||
push @{ $form->{DATEV} }, \@{ $splits[$g] };
|
||
|
||
$g++;
|
||
|
||
} elsif (($j != $notsplitindex) && ($i->[$j]->{'chart_id'} eq "")) {
|
||
$absumsatz += ($i->[$j]->{'amount'} * (1 + $taxes{ $taxid_taxkeys{$i->[$j]->{'taxkey'}} }));
|
||
|
||
my %blubb = {};
|
||
map({ $blubb{$_} = $i->[$notsplitindex]->{$_}; } keys(%{ $i->[$notsplitindex] }));
|
||
|
||
$test = 1 + $taxes{ $taxid_taxkeys{$i->[$j]->{'taxkey'}} };
|
||
$blubb{'amount'} = $form->round_amount(($i->[$j]->{'amount'} * $test * -1), 2);
|
||
$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;
|
||
|
||
push @{ $splits[$g] }, \%blubb;
|
||
push @{ $splits[$g] }, $i->[$j];
|
||
push @{ $form->{DATEV} }, \@{ $splits[$g] };
|
||
$g++;
|
||
my $absumsatz = 0;
|
||
if (scalar(@{$i}) <= 2) {
|
||
push @{ $form->{DATEV} }, \@{$i};
|
||
next;
|
||
}
|
||
|
||
} else {
|
||
next;
|
||
}
|
||
for my $j (0 .. (scalar(@{$i}) - 1)) {
|
||
if (abs($i->[$j]->{'amount'}) > abs($absumsatz)) {
|
||
$absumsatz = $i->[$j]->{'amount'};
|
||
$notsplitindex = $j;
|
||
}
|
||
if (abs($absumsatz) > 0.01) {
|
||
$form->error("Datev-Export fehlgeschlagen! Bei Transaktion $i->[0]->{trans_id} $absumsatz\n");
|
||
if (($i->[$j]->{'taxtaxkey'}) && ($i->[$j]->{'taxid'})) {
|
||
$taxid_taxkeys{$i->[$j]->{'taxtaxkey'}} = $i->[$j]->{'taxid'};
|
||
}
|
||
} else {
|
||
push @{ $form->{DATEV} }, \@{$i};
|
||
}
|
||
$i++;
|
||
$ml = ($i->[0]->{'umsatz'} > 0) ? 1 : -1;
|
||
for my $j (0 .. (scalar(@{$i}) - 1)) {
|
||
if ( ($j != $notsplitindex)
|
||
&& ($i->[$j]->{'chart_id'} eq "")
|
||
&& ( $i->[$j]->{'taxkey'} eq ""
|
||
|| $i->[$j]->{'taxkey'} eq "0"
|
||
|| $i->[$j]->{'taxkey'} eq "1"
|
||
|| $i->[$j]->{'taxkey'} eq "10"
|
||
|| $i->[$j]->{'taxkey'} eq "11")) {
|
||
my %blubb = {};
|
||
map({ $blubb{$_} = $i->[$notsplitindex]->{$_}; } keys(%{ $i->[$notsplitindex] }));
|
||
|
||
$absumsatz += $i->[$j]->{'amount'};
|
||
$blubb{'amount'} = $i->[$j]->{'amount'} * (-1);
|
||
$blubb{'umsatz'} = abs($i->[$j]->{'amount'}) * $ml;
|
||
$i->[$j]->{'umsatz'} = abs($i->[$j]->{'amount'}) * $ml;
|
||
|
||
push @{ $splits[$g] }, \%blubb; #$i->[$notsplitindex];
|
||
push @{ $splits[$g] }, $i->[$j];
|
||
push @{ $form->{DATEV} }, \@{ $splits[$g] };
|
||
|
||
$g++;
|
||
|
||
} elsif (($j != $notsplitindex) && ($i->[$j]->{'chart_id'} eq "")) {
|
||
$absumsatz += ($i->[$j]->{'amount'} * (1 + $taxes{ $taxid_taxkeys{$i->[$j]->{'taxkey'}} }));
|
||
|
||
my %blubb = {};
|
||
map({ $blubb{$_} = $i->[$notsplitindex]->{$_}; } keys(%{ $i->[$notsplitindex] }));
|
||
|
||
$test = 1 + $taxes{ $taxid_taxkeys{$i->[$j]->{'taxkey'}} };
|
||
$blubb{'amount'} = $form->round_amount(($i->[$j]->{'amount'} * $test * -1), 2);
|
||
$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;
|
||
|
||
push @{ $splits[$g] }, \%blubb;
|
||
push @{ $splits[$g] }, $i->[$j];
|
||
push @{ $form->{DATEV} }, \@{ $splits[$g] };
|
||
$g++;
|
||
}
|
||
}
|
||
|
||
if (abs($absumsatz) > 0.01) {
|
||
$form->error("Datev-Export fehlgeschlagen! Bei Transaktion $i->[0]->{trans_id} $absumsatz\n");
|
||
}
|
||
}
|
||
$sth->finish;
|
||
$dbh->disconnect;
|
||
... | ... | |
&get_dates($form->{zeitraum}, $form->{monat},
|
||
$form->{quartal}, $form->{transdatefrom},
|
||
$form->{transdateto});
|
||
&get_transactions($myconfig, $form, $fromto);
|
||
_get_transactions($fromto);
|
||
my $counter = 0;
|
||
print qq|<br>2. Durchlauf:|;
|
||
while (scalar(@{ $form->{DATEV} })) {
|
Auch abrufbar als: Unified diff
Kosmetik; Variablen lokal deklarieren.