From 56d540df9d79d434d5a2e2759f1ffe3bcaf2226b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 6 Feb 2015 15:29:08 +0100 Subject: [PATCH] =?utf8?q?Finanz=C3=BCbersicht:=20Auftragswertperiodizit?= =?utf8?q?=C3=A4t=20ber=C3=BCcksichtigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/FinancialOverview.pm | 36 +++++++++++++++++++++--------- locale/de/all | 2 ++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/SL/Controller/FinancialOverview.pm b/SL/Controller/FinancialOverview.pm index 6b2889932..a8a1c3e16 100644 --- a/SL/Controller/FinancialOverview.pm +++ b/SL/Controller/FinancialOverview.pm @@ -4,6 +4,7 @@ use strict; use parent qw(SL::Controller::Base); use List::MoreUtils qw(none); +use List::Util qw(min); use SL::DB::Employee; use SL::DB::Invoice; @@ -39,7 +40,7 @@ sub prepare_report { $self->report(SL::ReportGenerator->new(\%::myconfig, $::form)); - my @columns = qw(year quarter month sales_quotations sales_orders sales_invoices requests_for_quotation purchase_orders purchase_invoices); + my @columns = (qw(year quarter month), @{ $self->types }); $self->number_columns([ grep { !m/^(?:month|year|quarter)$/ } @columns ]); @@ -48,7 +49,8 @@ sub prepare_report { year => { text => t8('Year') }, quarter => { text => t8('Quarter') }, sales_quotations => { text => t8('Sales Quotations') }, - sales_orders => { text => t8('Sales Orders') }, + sales_orders => { text => t8('Sales Orders Advance') }, + sales_orders_per_inv => { text => t8('Total Sales Orders Value') }, sales_invoices => { text => t8('Invoices') }, requests_for_quotation => { text => t8('Requests for Quotation') }, purchase_orders => { text => t8('Purchase Orders') }, @@ -87,6 +89,7 @@ sub get_objects { $self->objects({ sales_quotations => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_quotation') ]]), sales_orders => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_order') ]], with_objects => [ qw(periodic_invoices_config) ]), + sales_orders_per_inv => [], requests_for_quotation => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('request_quotation') ]]), purchase_orders => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('purchase_order') ]]), sales_invoices => SL::DB::Manager::Invoice->get_all( where => [ and => [ @f_date, @f_salesman, ]]), @@ -97,7 +100,7 @@ sub get_objects { $self->objects->{sales_orders} = [ grep { !$_->periodic_invoices_config || !$_->periodic_invoices_config->active } @{ $self->objects->{sales_orders} } ]; } -sub init_types { [ qw(sales_quotations sales_orders sales_invoices requests_for_quotation purchase_orders purchase_invoices) ] } +sub init_types { [ qw(sales_quotations sales_orders sales_orders_per_inv sales_invoices requests_for_quotation purchase_orders purchase_invoices) ] } sub init_data { my ($self) = @_; @@ -122,7 +125,8 @@ sub calculate_one_time_data { my ($self) = @_; foreach my $type (@{ $self->types }) { - foreach my $object (@{ $self->objects->{ $type } }) { + my $src_object_type = $type eq 'sales_orders_per_inv' ? 'sales_orders' : $type; + foreach my $object (@{ $self->objects->{ $src_object_type } }) { my $month = $object->transdate->month - 1; my $tdata = $self->data->{$type}; @@ -145,15 +149,25 @@ sub calculate_periodic_invoices { sub calculate_one_periodic_invoice { my ($self, %params) = @_; - return if $params{config}->start_date > $params{end_date}; + # Calculate sales order advance + my $net = $params{config}->order->netamount * $params{config}->get_billing_period_length / $params{config}->get_order_value_period_length; + my $sord = $self->data->{sales_orders}; - my $first_date = $params{config}->start_date->clone->set_year($self->year); - my $net = $params{config}->order->netamount * (12 / $params{config}->get_billing_period_length); - my $sord = $self->data->{sales_orders}; + foreach my $date ($params{config}->calculate_invoice_dates(start_date => $params{start_date}, end_date => $params{end_date}, past_dates => 1)) { + $sord->{months }->[ $date->month - 1 ] += $net; + $sord->{quarters}->[ $date->quarter - 1 ] += $net; + $sord->{year} += $net; + } + + # Calculate total sales order value + my $date = $params{config}->order->transdate; + return if $date->year != $params{start_date}->year; - $sord->{months }->[ $first_date->month - 1 ] += $net; - $sord->{quarters}->[ $first_date->quarter - 1 ] += $net; - $sord->{year} += $net; + $net = $params{config}->order->netamount; + $sord = $self->data->{sales_orders_per_inv}; + $sord->{months }->[ $date->month - 1 ] += $net; + $sord->{quarters}->[ $date->quarter - 1 ] += $net; + $sord->{year} += $net; } sub list_data { diff --git a/locale/de/all b/locale/de/all index 3f8177e72..ffd4375a4 100755 --- a/locale/de/all +++ b/locale/de/all @@ -2140,6 +2140,7 @@ $self->{texts} = { 'Sales Invoices' => 'Kundenrechnungen', 'Sales Order' => 'Kundenauftrag', 'Sales Orders' => 'Aufträge', + 'Sales Orders Advance' => 'Auftragsvorlauf', 'Sales Orders deleteable' => 'Kundenaufträge löschbar', 'Sales Price Rules' => 'Preisregeln Verkauf', 'Sales Price Rules ' => 'Preisregeln (Verkauf)', @@ -2818,6 +2819,7 @@ $self->{texts} = { 'Top Level Designation only' => 'Nur Hauptartikelbezeichnung', 'Total' => 'Summe', 'Total Fees' => 'Kumulierte Gebühren', + 'Total Sales Orders Value' => 'Auftragseingang', 'Total stock value' => 'Gesamter Bestandswert', 'Total sum' => 'Gesamtsumme', 'Total weight' => 'Gesamtgewicht', -- 2.20.1