4 |
4 |
use parent qw(SL::Controller::Base);
|
5 |
5 |
|
6 |
6 |
use List::MoreUtils qw(none);
|
|
7 |
use List::Util qw(min);
|
7 |
8 |
|
8 |
9 |
use SL::DB::Employee;
|
9 |
10 |
use SL::DB::Invoice;
|
... | ... | |
39 |
40 |
|
40 |
41 |
$self->report(SL::ReportGenerator->new(\%::myconfig, $::form));
|
41 |
42 |
|
42 |
|
my @columns = qw(year quarter month sales_quotations sales_orders sales_invoices requests_for_quotation purchase_orders purchase_invoices);
|
|
43 |
my @columns = (qw(year quarter month), @{ $self->types });
|
43 |
44 |
|
44 |
45 |
$self->number_columns([ grep { !m/^(?:month|year|quarter)$/ } @columns ]);
|
45 |
46 |
|
... | ... | |
48 |
49 |
year => { text => t8('Year') },
|
49 |
50 |
quarter => { text => t8('Quarter') },
|
50 |
51 |
sales_quotations => { text => t8('Sales Quotations') },
|
51 |
|
sales_orders => { text => t8('Sales Orders') },
|
|
52 |
sales_orders => { text => t8('Sales Orders Advance') },
|
|
53 |
sales_orders_per_inv => { text => t8('Total Sales Orders Value') },
|
52 |
54 |
sales_invoices => { text => t8('Invoices') },
|
53 |
55 |
requests_for_quotation => { text => t8('Requests for Quotation') },
|
54 |
56 |
purchase_orders => { text => t8('Purchase Orders') },
|
... | ... | |
87 |
89 |
$self->objects({
|
88 |
90 |
sales_quotations => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_quotation') ]]),
|
89 |
91 |
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) ]),
|
|
92 |
sales_orders_per_inv => [],
|
90 |
93 |
requests_for_quotation => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('request_quotation') ]]),
|
91 |
94 |
purchase_orders => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('purchase_order') ]]),
|
92 |
95 |
sales_invoices => SL::DB::Manager::Invoice->get_all( where => [ and => [ @f_date, @f_salesman, ]]),
|
... | ... | |
97 |
100 |
$self->objects->{sales_orders} = [ grep { !$_->periodic_invoices_config || !$_->periodic_invoices_config->active } @{ $self->objects->{sales_orders} } ];
|
98 |
101 |
}
|
99 |
102 |
|
100 |
|
sub init_types { [ qw(sales_quotations sales_orders sales_invoices requests_for_quotation purchase_orders purchase_invoices) ] }
|
|
103 |
sub init_types { [ qw(sales_quotations sales_orders sales_orders_per_inv sales_invoices requests_for_quotation purchase_orders purchase_invoices) ] }
|
101 |
104 |
|
102 |
105 |
sub init_data {
|
103 |
106 |
my ($self) = @_;
|
... | ... | |
122 |
125 |
my ($self) = @_;
|
123 |
126 |
|
124 |
127 |
foreach my $type (@{ $self->types }) {
|
125 |
|
foreach my $object (@{ $self->objects->{ $type } }) {
|
|
128 |
my $src_object_type = $type eq 'sales_orders_per_inv' ? 'sales_orders' : $type;
|
|
129 |
foreach my $object (@{ $self->objects->{ $src_object_type } }) {
|
126 |
130 |
my $month = $object->transdate->month - 1;
|
127 |
131 |
my $tdata = $self->data->{$type};
|
128 |
132 |
|
... | ... | |
145 |
149 |
sub calculate_one_periodic_invoice {
|
146 |
150 |
my ($self, %params) = @_;
|
147 |
151 |
|
148 |
|
return if $params{config}->start_date > $params{end_date};
|
|
152 |
# Calculate sales order advance
|
|
153 |
my $net = $params{config}->order->netamount * $params{config}->get_billing_period_length / $params{config}->get_order_value_period_length;
|
|
154 |
my $sord = $self->data->{sales_orders};
|
149 |
155 |
|
150 |
|
my $first_date = $params{config}->start_date->clone->set_year($self->year);
|
151 |
|
my $net = $params{config}->order->netamount * (12 / $params{config}->get_billing_period_length);
|
152 |
|
my $sord = $self->data->{sales_orders};
|
|
156 |
foreach my $date ($params{config}->calculate_invoice_dates(start_date => $params{start_date}, end_date => $params{end_date}, past_dates => 1)) {
|
|
157 |
$sord->{months }->[ $date->month - 1 ] += $net;
|
|
158 |
$sord->{quarters}->[ $date->quarter - 1 ] += $net;
|
|
159 |
$sord->{year} += $net;
|
|
160 |
}
|
|
161 |
|
|
162 |
# Calculate total sales order value
|
|
163 |
my $date = $params{config}->order->transdate;
|
|
164 |
return if $date->year != $params{start_date}->year;
|
153 |
165 |
|
154 |
|
$sord->{months }->[ $first_date->month - 1 ] += $net;
|
155 |
|
$sord->{quarters}->[ $first_date->quarter - 1 ] += $net;
|
156 |
|
$sord->{year} += $net;
|
|
166 |
$net = $params{config}->order->netamount;
|
|
167 |
$sord = $self->data->{sales_orders_per_inv};
|
|
168 |
$sord->{months }->[ $date->month - 1 ] += $net;
|
|
169 |
$sord->{quarters}->[ $date->quarter - 1 ] += $net;
|
|
170 |
$sord->{year} += $net;
|
157 |
171 |
}
|
158 |
172 |
|
159 |
173 |
sub list_data {
|
Finanzübersicht: Auftragswertperiodizität berücksichtigen