From 7b9e6d68fbedc342504cf2f70a4ee5ed04e085a2 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Tue, 6 Sep 2011 14:04:44 +0200 Subject: [PATCH] =?utf8?q?Verkaufsbericht:=20Komplett=20gutgeschriebene=20?= =?utf8?q?Artikel=20ber=C3=BCcksichtigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Spezialfall wo qty innerhalb einer Subtotal 0 ist, wenn es zu allen Positionen eine Gutschrift gibt. In diesem Fall wird der Gesamt-VK und Gesamt-EK auf 0 gesetzt, dies wurde bisher falsch berechnet. --- bin/mozilla/vk.pl | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/mozilla/vk.pl b/bin/mozilla/vk.pl index f7335a361..1327b2161 100644 --- a/bin/mozilla/vk.pl +++ b/bin/mozilla/vk.pl @@ -295,10 +295,28 @@ sub invoice_transactions { map { $totals{$_} += $ar->{$_} } @total_columns; - $subtotals2{sellprice} = $subtotals2{sellprice_total} / $subtotals2{qty} if $subtotals2{qty} != 0; - $subtotals1{sellprice} = $subtotals1{sellprice_total} / $subtotals1{qty} if $subtotals1{qty} != 0; - $subtotals2{lastcost} = $subtotals2{lastcost_total} / $subtotals2{qty} if $subtotals2{qty} != 0; - $subtotals1{lastcost} = $subtotals1{lastcost_total} / $subtotals1{qty} if $subtotals1{qty} != 0; + if ( $subtotals1{qty} != 0 ) { + # calculate averages for subtotals1 and subtotals2 + # credited positions reduce both total and qty and thus don't influence average prices + $subtotals1{sellprice} = $subtotals1{sellprice_total} / $subtotals1{qty}; + $subtotals1{lastcost} = $subtotals1{lastcost_total} / $subtotals1{qty}; + } else { + # qty is zero, so we have a special case where each position in subtotal + # group has a corresponding credit note so that the total qty is zero in + # this case we also want the total amounts to be zero, so overwrite them, + # rather than leaving the last value in sellprice/lastcost + + $subtotals1{sellprice} = 0; + $subtotals1{lastcost} = 0; + }; + + if ( $subtotals2{qty} != 0 ) { + $subtotals2{sellprice} = $subtotals2{sellprice_total} / $subtotals2{qty}; + $subtotals2{lastcost} = $subtotals2{lastcost_total} / $subtotals2{qty}; + } else { + $subtotals2{sellprice} = 0; + $subtotals2{lastcost} = 0; + }; # Ertrag prozentual in den Summen: (summe VK - summe Ertrag) / summe VK $subtotals1{marge_percent} = $subtotals1{sellprice_total} ? (($subtotals1{sellprice_total} - $subtotals1{lastcost_total}) / $subtotals1{sellprice_total}) : 0; -- 2.20.1