From: Moritz Bunkus Date: Thu, 31 Jan 2013 11:34:02 +0000 (+0100) Subject: Finanzcontrollingbericht: Stornorechnungen berücksichtigen X-Git-Tag: release-3.1.0beta1~22^2~76 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7f82c68cb99dc3aa01c7fee0d674607d22e17beb;p=kivitendo-erp.git Finanzcontrollingbericht: Stornorechnungen berücksichtigen --- 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};