X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/a2d4ad4c41a19e9323242c29b0dad2c63e7d0e88..d8be5cc409de5b3bc34439599b1481201a5a1c2e:/SL/Controller/FinancialOverview.pm diff --git a/SL/Controller/FinancialOverview.pm b/SL/Controller/FinancialOverview.pm index c0c7d183c..edfe33da4 100644 --- a/SL/Controller/FinancialOverview.pm +++ b/SL/Controller/FinancialOverview.pm @@ -41,7 +41,7 @@ sub prepare_report { my ($self) = @_; $self->report(SL::ReportGenerator->new(\%::myconfig, $::form)); - + $self->report->{title} =t8('Financial Overview'); my @columns = (qw(year quarter month), @{ $self->types }); $self->number_columns([ grep { !m/^(?:month|year|quarter)$/ } @columns ]); @@ -141,9 +141,9 @@ sub calculate_one_time_data { my $month = $object->transdate->month - 1; my $tdata = $self->data->{$type}; - $tdata->{months}->[$month] += $object->netamount; - $tdata->{quarters}->[int($month / 3)] += $object->netamount; - $tdata->{year} += $object->netamount; + $tdata->{months}->[$month] += $object->netamount_base_currency; + $tdata->{quarters}->[int($month / 3)] += $object->netamount_base_currency; + $tdata->{year} += $object->netamount_base_currency; } } } @@ -151,23 +151,52 @@ sub calculate_one_time_data { sub calculate_periodic_invoices { my ($self) = @_; + my %billed_once_item_ids; my $start_date = DateTime->new(year => $self->year, month => 1, day => 1, time_zone => $::locale->get_local_time_zone); my $end_date = DateTime->new(year => $self->year, month => 12, day => 31, time_zone => $::locale->get_local_time_zone); - $self->calculate_one_periodic_invoice(config => $_, start_date => $start_date, end_date => $end_date) for @{ $self->objects->{periodic_invoices_cfg} }; + foreach my $config (@{ $self->objects->{periodic_invoices_cfg} }) { + $self->calculate_one_periodic_invoice( + config => $config, + start_date => $start_date, + end_date => $end_date, + billed_once_item_ids => \%billed_once_item_ids, + ); + } } sub calculate_one_periodic_invoice { my ($self, %params) = @_; # 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 ($net, $net_once) = (0, 0); + + foreach my $item (@{ $params{config}->order->orderitems }) { + next if $item->recurring_billing_mode eq 'never'; + + my $item_net = $item->qty * (1 - $item->discount) * $item->sellprice; + + if ($item->recurring_billing_mode eq 'once') { + next if $item->recurring_billing_invoice_id || $params{billed_once_invoice_id}->{$item->id}; + + $params{billed_once_invoice_id}->{$item->id} = 1; + $net_once += $item_net; + + } else { + $net += $item_net; + } + } + + $net = $net * $params{config}->get_billing_period_length / $params{config}->get_order_value_period_length; + 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; + $sord->{months }->[ $date->month - 1 ] += $net + $net_once; + $sord->{quarters}->[ $date->quarter - 1 ] += $net + $net_once; + $sord->{year} += $net + $net_once; + + $net_once = 0; } # Calculate total sales order value