Merge branch 'master' into bug1640
authorBernd Blessmann <bibi@online.de>
Wed, 7 Sep 2011 11:35:06 +0000 (13:35 +0200)
committerBernd Blessmann <bibi@online.de>
Wed, 7 Sep 2011 11:35:06 +0000 (13:35 +0200)
bin/mozilla/io.pl
bin/mozilla/vk.pl

index 9dd8e8c..37fdda8 100644 (file)
@@ -350,7 +350,7 @@ sub display_row {
                    $marge_color, $locale->text('Ertrag'),$form->{"marge_absolut_$i"}, $form->{"marge_percent_$i"},
                    $locale->text('LP'), $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2),
                    $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) }
-      if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ ||  $form->{type} =~ /invoice/) && !$is_delivery_order;
+      if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ ||  $form->{type} =~ /invoice/ || $form->{type} =~ /^credit_note$/ ) && !$is_delivery_order;
 
     $form->{"listprice_$i"} = $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2)
       if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ ||  $form->{type} =~ /invoice/) ;
index f7335a3..1327b21 100644 (file)
@@ -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;