X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FFinancialOverview.pm;h=19ae441036cc4c5fafefbe346cb7ee11da8f315f;hb=3e988f3db569f269c7f1a4040f5dd4c9c5ebf2e6;hp=49c04698ce6638a9eb304a38d3f913cb095f0842;hpb=58f2f2f46640e98ea43f1d7701c7e2f4b635784d;p=kivitendo-erp.git diff --git a/SL/Controller/FinancialOverview.pm b/SL/Controller/FinancialOverview.pm index 49c04698c..19ae44103 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,20 +49,21 @@ 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') }, purchase_invoices => { text => t8('Purchase Invoices') }, ); - map { $column_defs{$_}->{align} = 'right' } @columns; + $column_defs{$_}->{align} = 'right' for @columns; $self->report->set_options( std_column_visibility => 1, controller_class => 'FinancialOverview', output_format => 'HTML', - raw_top_info_text => $self->render('financial_overview/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(2000..$self->current_year) ]), + raw_top_info_text => $self->render('financial_overview/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(($self->current_year - 10)..($self->current_year + 5)) ]), title => t8('Financial overview for #1', $self->year), allow_pdf_export => 1, allow_csv_export => 1, @@ -87,17 +89,18 @@ 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, ]]), purchase_invoices => SL::DB::Manager::PurchaseInvoice->get_all(where => [ and => \@f_date ]), - periodic_invoices_cfg => SL::DB::Manager::PeriodicInvoicesConfig->get_all(where => [ active => 1 ]), + periodic_invoices_cfg => SL::DB::Manager::PeriodicInvoicesConfig->get_all(where => [ active => 1, $self->salesman_id ? ('order.salesman_id' => $self->salesman_id) : () ], with_objects => [ qw(order) ]), }); $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,17 +149,25 @@ sub calculate_periodic_invoices { sub calculate_one_periodic_invoice { my ($self, %params) = @_; - my @dates = $params{config}->calculate_invoice_dates(start_date => $params{start_date}, end_date => $params{end_date}, past_dates => 1); - my $first_date = $dates[0]; + # 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}; - return if !$first_date; + 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; + } - my $net = $params{config}->order->netamount * scalar(@dates); - my $sord = $self->data->{sales_orders}; + # 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 {