X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fvk.pl;h=e871053a30cf39702e00dcd88c5a2df1a3b0d781;hb=8a2d9daf01083e1271cf6118591bb2c242734261;hp=f7335a3617a1fff81134a33eb5d1ec0eaf39afee;hpb=de0f9532013c861dae78aa01b9633284d1ceee7c;p=kivitendo-erp.git diff --git a/bin/mozilla/vk.pl b/bin/mozilla/vk.pl index f7335a361..e871053a3 100644 --- a/bin/mozilla/vk.pl +++ b/bin/mozilla/vk.pl @@ -54,7 +54,6 @@ sub search_invoice { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; my ($customer, $department); @@ -100,7 +99,7 @@ sub invoice_transactions { # Nichts führt, daher diese Zwischenlösung &check_name('customer', no_select => 1); - + # $form->{customer_id} wurde schon von check_name gesetzt $form->{customername} = $form->{customer}; }; @@ -295,10 +294,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;