From bdb4582b57fcb6b7a8a1a966f3241cce48163f46 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 24 Sep 2014 10:10:52 +0200 Subject: [PATCH] =?utf8?q?Finanzcontrolling:=20Auftr=C3=A4ge=20mit=20wiedR?= =?utf8?q?ech=20f=C3=BCr=20jedes=20angefangene=20Jahr=20berechnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/FinancialControllingReport.pm | 23 ++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/SL/Controller/FinancialControllingReport.pm b/SL/Controller/FinancialControllingReport.pm index 79bb8d072..c10c09dbe 100644 --- a/SL/Controller/FinancialControllingReport.pm +++ b/SL/Controller/FinancialControllingReport.pm @@ -3,7 +3,7 @@ package SL::Controller::FinancialControllingReport; use strict; use parent qw(SL::Controller::Base); -use List::Util qw(sum); +use List::Util qw(min sum); use SL::DB::Order; use SL::DB::ProjectType; @@ -121,8 +121,7 @@ sub calculate_data { $order->{billable_amount} = $order->{delivered_amount} - $order->{billed_amount}; if ($order->periodic_invoices_config) { - my @dates = $order->periodic_invoices_config->calculate_invoice_dates(past_dates => 1, end_date => DateTime->today_local); - $order->{net_amount} = $order->netamount * (12 / $order->periodic_invoices_config->get_period_length); + $order->{net_amount} = $self->calculate_periodic_invoices_order_netamount($order); } else { $order->{net_amount} = $order->netamount; @@ -134,6 +133,24 @@ sub calculate_data { } } +sub calculate_periodic_invoices_order_netamount { + my ($self, $order) = @_; + + my $cfg = $order->periodic_invoices_config; + my $num_years = 0; + my $cur_date = $cfg->start_date->clone; + my $end_date = $cfg->terminated ? $self->end_date : undef; + $end_date //= DateTime->today_local; + $end_date = min($end_date, DateTime->today_local); + + while ($cur_date <= $end_date) { + $num_years++; + $cur_date->add(years => 1); + } + + return $num_years * $order->netamount * (12 / $order->periodic_invoices_config->get_period_length); +} + sub sum_items { my ($self, %params) = @_; -- 2.20.1