- push @splits, [ \%new_trans, $trans->[$j] ];
- push @{ $form->{DATEV} }, $splits[-1];
+ } else {
+ my $unrounded = $trans->[$j]->{'amount'} * (1 + $tax_rate) * -1 + $rounding_error;
+ my $rounded = $form->round_amount($unrounded, 2);
+
+ $rounding_error = $unrounded - $rounded;
+ $new_trans{'amount'} = $rounded;
+ $new_trans{'umsatz'} = abs($rounded) * $ml;
+ $trans->[$j]->{'umsatz'} = $new_trans{umsatz};
+ $absumsatz -= $rounded;
+ }
+
+ push @{ $form->{DATEV} }, [ \%new_trans, $trans->[$j] ];
+ push @taxed, $form->{DATEV}->[-1];
+ }
+ }
+
+ my $idx = 0;
+ my $correction = 0;
+ while ((abs($absumsatz) >= 0.01) && (abs($absumsatz) < 1.00)) {
+ if ($idx >= scalar @taxed) {
+ last if (!$correction);
+
+ $correction = 0;
+ $idx = 0;
+ }
+
+ my $transaction = $taxed[$idx]->[0];
+
+ my $old_amount = $transaction->{amount};
+ my $old_correction = $correction;
+ my @possible_diffs;
+
+ if (!$transaction->{diff}) {
+ @possible_diffs = (0.01, -0.01);
+ } else {
+ @possible_diffs = ($transaction->{diff});