X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/1ae70a98a8bcff7609e7fff67fb24015d462da23..aaf1cc99f5da2a694b5cbbf2eeb13e8e29dbc334:/SL/AR.pm diff --git a/SL/AR.pm b/SL/AR.pm index 926a1b69e..0aa4ff372 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -411,14 +411,17 @@ sub ar_transactions { qq|SELECT a.id, a.invnumber, a.ordnumber, a.transdate, | . qq| a.duedate, a.netamount, a.amount, a.paid, | . qq| a.invoice, a.datepaid, a.terms, a.notes, a.shipvia, | . - qq| a.shippingpoint, a.storno, a.globalproject_id, | . + qq| a.shippingpoint, a.storno, a.storno_id, a.globalproject_id, | . + qq| a.marge_total, a.marge_percent, | . qq| a.transaction_description, | . qq| pr.projectnumber AS globalprojectnumber, | . qq| c.name, | . - qq| e.name AS employee | . + qq| e.name AS employee, | . + qq| e2.name AS salesman | . qq|FROM ar a | . qq|JOIN customer c ON (a.customer_id = c.id) | . qq|LEFT JOIN employee e ON (a.employee_id = e.id) | . + qq|LEFT JOIN employee e2 ON (a.salesman_id = e2.id) | . qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id)|; my $where = "1 = 1"; @@ -634,7 +637,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)}; @@ -645,9 +648,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;