From a7e58f7e19ca7548912f0ca59f1c6a78b0094db3 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 30 Apr 2013 14:09:17 +0200 Subject: [PATCH] =?utf8?q?Finanzcontrollingbericht:=20Seriennummern=20bei?= =?utf8?q?=20Berechnung=20ber=C3=BCcksichtigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/FinancialControllingReport.pm | 26 ++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/SL/Controller/FinancialControllingReport.pm b/SL/Controller/FinancialControllingReport.pm index 6a836e583..b306dcd0c 100644 --- a/SL/Controller/FinancialControllingReport.pm +++ b/SL/Controller/FinancialControllingReport.pm @@ -167,9 +167,12 @@ sub sum_items { my %vals; foreach my $item (@{ $params{obj}->items }) { - $vals{$item->parts_id} ||= { parts_id => $item->parts_id, amount => 0, base_qty => 0 }; - $vals{$item->parts_id}->{amount} += $item->qty * $item->sellprice * (1 - $item->discount) / (($item->price_factor * 1) || 1); - $vals{$item->parts_id}->{base_qty} += $item->qty * $item->unit_obj->base_factor; + my $key = $item->parts_id; + $key .= ':' . $item->serialnumber if $item->serialnumber; + + $vals{$key} ||= { parts_id => $item->parts_id, serialnumber => $item->serialnumber, amount => 0, base_qty => 0 }; + $vals{$key}->{amount} += $item->qty * $item->sellprice * (1 - $item->discount) / (($item->price_factor * 1) || 1); + $vals{$key}->{base_qty} += $item->qty * $item->unit_obj->base_factor; } return \%vals; @@ -183,12 +186,19 @@ sub sum_relevant_items { my $total = 0; foreach my $item (grep { $params{order}->{amounts_by_parts_id}->{ $_->{parts_id} } } values %{ $sums }) { - my $order_item = $params{order}->{amounts_by_parts_id}->{ $item->{parts_id} }; - if ($params{by_order} && $order_item->{base_qty}) { - $total += $order_item->{amount} * $item->{base_qty} / $order_item->{base_qty}; - } else { - $total += $item->{amount}; + my $key = $item->{parts_id}; + + if ($params{by_order}) { + $key .= ':' . $item->{serialnumber}; + my $order_item = $params{order}->{amounts_by_parts_id}->{ $key } || $params{order}->{amounts_by_parts_id}->{ $item->{parts_id} }; + + if ($order_item && $order_item->{base_qty}) { + $total += $order_item->{amount} * $item->{base_qty} / $order_item->{base_qty}; + next; + } } + + $total += $item->{amount}; } return $total; -- 2.20.1