X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAP.pm;h=66020933c16499773f1e88bb0b77c618bbf6f9b1;hb=6f2050063ffa5417ab4495af84625385c766bc2d;hp=edd42c033ac65d9d5bbd5dd8b95655fa6cd9765d;hpb=2b3f8b3a8e518497566e3281dae387db2d98500a;p=kivitendo-erp.git diff --git a/SL/AP.pm b/SL/AP.pm index edd42c033..66020933c 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -765,7 +765,7 @@ sub storno { $storno_row->{invnumber} = 'Storno-' . $storno_row->{invnumber}; $storno_row->{amount} *= -1; $storno_row->{netamount} *= -1; - $storno_row->{paid} = $storno_amount->{amount}; + $storno_row->{paid} = $storno_row->{amount}; delete @$storno_row{qw(itime mtime)}; @@ -776,9 +776,16 @@ sub storno { do_query($form, $dbh, $query, $id); # now copy acc_trans entries - $query = qq|SELECT * FROM acc_trans WHERE trans_id = ?|; - for my $row (@{ selectall_hashref_query($form, $dbh, $query, $id) }) { - delete @$row{qw(itime mtime)}; + $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.oid|; + my $rowref = selectall_hashref_query($form, $dbh, $query, $id); + + # kill all entries containing payments, which are the last 2n rows, of which the last has link =~ /paid/ + while ($rowref->[-1]{link} =~ /paid/) { + splice(@$rowref, -2); + } + + for my $row (@$rowref) { + delete @$row{qw(itime mtime link)}; $query = sprintf 'INSERT INTO acc_trans (%s) VALUES (%s)', join(', ', keys %$row), join(', ', map '?', values %$row); $row->{trans_id} = $new_id; $row->{amount} *= -1;