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 ]);
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;
}
}
}
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