From 2459723286f701a341062b054a215a266df74e01 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 16 Oct 2013 12:32:33 +0200 Subject: [PATCH] =?utf8?q?Finanzcontrollingbericht:=20wiederkehrende=20Rec?= =?utf8?q?hnungen=20ber=C3=BCcksichtigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/FinancialControllingReport.pm | 31 +++++++++++++++++---- SL/DB/PeriodicInvoicesConfig.pm | 7 +++-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/SL/Controller/FinancialControllingReport.pm b/SL/Controller/FinancialControllingReport.pm index bedc7623f..675f24b4f 100644 --- a/SL/Controller/FinancialControllingReport.pm +++ b/SL/Controller/FinancialControllingReport.pm @@ -24,7 +24,6 @@ my %sort_columns = ( transaction_description => t8('Transaction description'), globalprojectnumber => t8('Project'), globalproject_type => t8('Project Type'), - netamount => t8('Order amount'), ); sub action_list { @@ -51,13 +50,13 @@ sub prepare_report { my $report = SL::ReportGenerator->new(\%::myconfig, $::form); $self->{report} = $report; - my @columns = qw(customer globalprojectnumber globalproject_type ordnumber netamount delivered_amount delivered_amount_p billed_amount billed_amount_p paid_amount paid_amount_p + my @columns = qw(customer globalprojectnumber globalproject_type ordnumber net_amount delivered_amount delivered_amount_p billed_amount billed_amount_p paid_amount paid_amount_p billable_amount billable_amount_p other_amount); - my @sortable = qw(ordnumber transdate customer netamount globalprojectnumber globalproject_type); - $self->{number_columns} = [ qw(netamount billed_amount billed_amount_p delivered_amount delivered_amount_p paid_amount paid_amount_p other_amount billable_amount billable_amount_p) ]; + my @sortable = qw(ordnumber transdate customer globalprojectnumber globalproject_type); + $self->{number_columns} = [ qw(net_amount billed_amount billed_amount_p delivered_amount delivered_amount_p paid_amount paid_amount_p other_amount billable_amount billable_amount_p) ]; my %column_defs = ( - netamount => { }, + net_amount => { text => $::locale->text('Order amount') }, billed_amount => { text => $::locale->text('Billed amount') }, billed_amount_p => { text => $::locale->text('%') }, delivered_amount => { text => $::locale->text('Delivered amount') }, @@ -120,8 +119,16 @@ sub calculate_data { $order->{other_amount} = $billed_amount - $order->{billed_amount}; $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 => $order->periodic_invoices_config->end_date || DateTime->today_local); + $order->{net_amount} = $order->netamount * scalar(@dates); + + } else { + $order->{net_amount} = $order->netamount; + } + foreach (qw(delivered billed paid billable)) { - $order->{"${_}_amount_p"} = $order->netamount * 1 ? $order->{"${_}_amount"} * 100 / $order->netamount : undef; + $order->{"${_}_amount_p"} = $order->{net_amount} * 1 ? $order->{"${_}_amount"} * 100 / $order->{net_amount} : undef; } } } @@ -219,6 +226,18 @@ sub init_models { 'globalproject.active' => 1, 'globalproject.valid' => 1, ]], + # keine WR + # oder aber (WR aktiv und (kein enddatum oder enddatum noch nicht überschritten)) + or => [ + 'periodic_invoices_config.id' => undef, + # and => [ + 'periodic_invoices_config.active' => 1, + # or => [ + # 'periodic_invoices_config.end_date' => undef, + # 'periodic_invoices_config.end_date' => { le => DateTime->today_local }, + # ] + # ] + ], ], with_objects => [ 'customer', 'globalproject', 'globalproject.project_type' ], ); diff --git a/SL/DB/PeriodicInvoicesConfig.pm b/SL/DB/PeriodicInvoicesConfig.pm index 7270c8f42..45536752c 100644 --- a/SL/DB/PeriodicInvoicesConfig.pm +++ b/SL/DB/PeriodicInvoicesConfig.pm @@ -79,17 +79,18 @@ SQL sub calculate_invoice_dates { my ($self, %params) = @_; + my $period_len = $self->get_period_length; my $cur_date = $self->first_billing_date || $self->start_date; - my $start_date = $self->get_previous_invoice_date || DateTime->new(year => 1970, month => 1, day => 1); my $end_date = $self->end_date || DateTime->today_local->add(years => 10); - my $period_len = $self->get_period_length; + my $start_date = $params{past_dates} ? undef : $self->get_previous_invoice_date; + $start_date ||= $cur_date->clone->subtract(days => 1); $start_date = max($start_date, $params{start_date}) if $params{start_date}; $end_date = min($end_date, $params{end_date}) if $params{end_date}; my @dates; - while ($cur_date < $end_date) { + while ($cur_date <= $end_date) { push @dates, $cur_date->clone if $cur_date > $start_date; $cur_date->add(months => $period_len); -- 2.20.1