From 7f82c68cb99dc3aa01c7fee0d674607d22e17beb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 31 Jan 2013 12:34:02 +0100 Subject: [PATCH] =?utf8?q?Finanzcontrollingbericht:=20Stornorechnungen=20b?= =?utf8?q?er=C3=BCcksichtigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/FinancialControllingReport.pm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/SL/Controller/FinancialControllingReport.pm b/SL/Controller/FinancialControllingReport.pm index 58df26b61..2e62e0f7e 100644 --- a/SL/Controller/FinancialControllingReport.pm +++ b/SL/Controller/FinancialControllingReport.pm @@ -138,13 +138,18 @@ sub calculate_data { my ($self) = @_; foreach my $order (@{ $self->{orders} }) { - my $delivery_orders = $order->linked_records(direction => 'to', to => 'DeliveryOrder', via => 'Order', query => [ '!customer_id' => undef ]); - my $invoices = $order->linked_records(direction => 'to', to => 'Invoice', via => [ 'Order', 'DeliveryOrder' ]); - - $order->{delivered_amount} = sum map { $self->sum_relevant_items(order => $order, other => $_, by_order => 1) } @{ $delivery_orders }; - $order->{billed_amount} = sum map { $self->sum_relevant_items(order => $order, other => $_) } @{ $invoices }; - $order->{paid_amount} = sum map { $_->paid } @{ $invoices }; - my $billed_amount = sum map { $_->netamount } @{ $invoices }; + my @delivery_orders = @{ $order->linked_records(direction => 'to', to => 'DeliveryOrder', via => 'Order', query => [ '!customer_id' => undef ]) }; + my @invoices = @{ $order->linked_records(direction => 'to', to => 'Invoice', via => [ 'Order', 'DeliveryOrder' ]) }; + + @invoices = ( + grep({ !$_->storno_id } @invoices), + map({ @{ $_->storno_invoices } } grep { $_->storno && !$_->storno_id } @invoices), + ); + + $order->{delivered_amount} = sum map { $self->sum_relevant_items(order => $order, other => $_, by_order => 1) } @delivery_orders; + $order->{billed_amount} = sum map { $self->sum_relevant_items(order => $order, other => $_) } @invoices; + $order->{paid_amount} = sum map { $_->paid } @invoices; + my $billed_amount = sum map { $_->netamount } @invoices; $order->{other_amount} = $billed_amount - $order->{billed_amount}; $order->{billable_amount} = $order->{delivered_amount} - $order->{billed_amount}; -- 2.20.1