X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/2b3f8b3a8e518497566e3281dae387db2d98500a..ab96e204a2beec2302b1850df50f45a6e67a13c4:/SL/AP.pm diff --git a/SL/AP.pm b/SL/AP.pm index edd42c033..b5e252096 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -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;