From 0a02b827a5c14cdd46a1faa13cb7fdda832a6aa2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 14 Jun 2007 14:51:14 +0000 Subject: [PATCH] Storno Fix nr. 29283574983745 Es werden beim Storno jetzt nur noch die urspruenglichen acc_trans Eintraege storniert, nachtraegliche Zahlungseingaenge bleiben unberuehrt. --- SL/AP.pm | 13 ++++++++++--- SL/AR.pm | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/SL/AP.pm b/SL/AP.pm index edd42c033..2da4eca6c 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 = ?|; + 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; diff --git a/SL/AR.pm b/SL/AR.pm index 926a1b69e..96547c566 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -645,9 +645,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 = ?|; + 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; -- 2.20.1