Revision bd1f6060
Von Tamino Steinert vor 5 Monaten hinzugefügt
SL/Controller/FinancialOverview.pm | ||
---|---|---|
156 | 156 |
my $end_date = DateTime->new(year => $self->year, month => 12, day => 31, time_zone => $::locale->get_local_time_zone); |
157 | 157 |
|
158 | 158 |
foreach my $config (@{ $self->objects->{periodic_invoices_cfg} }) { |
159 |
$self->calculate_one_periodic_invoice( |
|
160 |
config => $config, |
|
161 |
start_date => $start_date, |
|
162 |
end_date => $end_date, |
|
163 |
billed_once_item_ids => \%billed_once_item_ids, |
|
164 |
); |
|
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
sub calculate_one_periodic_invoice { |
|
169 |
my ($self, %params) = @_; |
|
170 |
|
|
171 |
# Calculate sales order advance |
|
172 |
my $sord = $self->data->{sales_orders}; |
|
173 |
|
|
174 |
my ($net, $net_once) = (0, 0); |
|
175 |
|
|
176 |
foreach my $item (@{ $params{config}->order->orderitems }) { |
|
177 |
next if $item->recurring_billing_mode eq 'never'; |
|
178 |
|
|
179 |
my $item_net = $item->qty * (1 - $item->discount) * $item->sellprice; |
|
180 |
|
|
181 |
if ($item->recurring_billing_mode eq 'once') { |
|
182 |
next if $item->recurring_billing_invoice_id || $params{billed_once_invoice_id}->{$item->id}; |
|
183 |
|
|
184 |
$params{billed_once_invoice_id}->{$item->id} = 1; |
|
185 |
$net_once += $item_net; |
|
186 |
|
|
187 |
} else { |
|
188 |
$net += $item_net; |
|
159 |
foreach my $order (@{ |
|
160 |
$config->get_open_orders_for_period( |
|
161 |
start_date => $start_date, end_date => $end_date |
|
162 |
) }) { |
|
163 |
|
|
164 |
my $sord = $self->data->{sales_orders}; |
|
165 |
my $reqdate = $order->reqdate(); |
|
166 |
my $net = $order->netamount(); |
|
167 |
$sord->{months }->[ $reqdate->month - 1 ] += $net; |
|
168 |
$sord->{quarters}->[ $reqdate->quarter - 1 ] += $net; |
|
169 |
$sord->{year} += $net; |
|
189 | 170 |
} |
190 |
} |
|
191 | 171 |
|
192 |
$net = $net * $params{config}->get_billing_period_length / $params{config}->get_order_value_period_length; |
|
193 |
|
|
194 |
foreach my $date ($params{config}->calculate_invoice_dates(start_date => $params{start_date}, end_date => $params{end_date}, past_dates => 1)) { |
|
195 |
$sord->{months }->[ $date->month - 1 ] += $net + $net_once; |
|
196 |
$sord->{quarters}->[ $date->quarter - 1 ] += $net + $net_once; |
|
197 |
$sord->{year} += $net + $net_once; |
|
198 |
|
|
199 |
$net_once = 0; |
|
172 |
my $transdate = $config->order->transdate(); |
|
173 |
next if $transdate->year != $start_date->year; |
|
174 |
my $net = $config->order->netamount(); |
|
175 |
my $sinv = $self->data->{sales_orders_per_inv}; |
|
176 |
$sinv->{months }->[ $transdate->month - 1 ] += $net; |
|
177 |
$sinv->{quarters}->[ $transdate->quarter - 1 ] += $net; |
|
178 |
$sinv->{year} += $net; |
|
200 | 179 |
} |
201 |
|
|
202 |
# Calculate total sales order value |
|
203 |
my $date = $params{config}->order->transdate; |
|
204 |
return if $date->year != $params{start_date}->year; |
|
205 |
|
|
206 |
$net = $params{config}->order->netamount; |
|
207 |
$sord = $self->data->{sales_orders_per_inv}; |
|
208 |
$sord->{months }->[ $date->month - 1 ] += $net; |
|
209 |
$sord->{quarters}->[ $date->quarter - 1 ] += $net; |
|
210 |
$sord->{year} += $net; |
|
211 | 180 |
} |
212 | 181 |
|
213 | 182 |
sub calculate_costs { |
t/controllers/financial_overview/sales_orders.t | ||
---|---|---|
118 | 118 |
for qw(purchase_invoices purchase_orders requests_for_quotation sales_invoices sales_quotations); |
119 | 119 |
|
120 | 120 |
is_deeply($ctrl->data->{sales_orders}, |
121 |
{ months => [ 0, 0, 0, 0, 27.7775, 27.7775, 27.7775, 27.7775, 27.7775, 27.7775, 27.7775, 27.7775 ], quarters => [ 0, 55.555, 83.3325, 83.3325 ], year => 222.22 },
|
|
121 |
{ months => [ 0, 0, 0, 0, 27.78, 27.78, 27.78, 27.78, 27.78, 27.78, 27.78, 27.78 ], quarters => [ 0, 55.56, 83.34, 83.34 ], year => 222.24 },
|
|
122 | 122 |
"periodic conf p=m ovp=y, no invoices, data for sales_orders"); |
123 | 123 |
is_deeply($ctrl->data->{sales_orders_per_inv}, |
124 | 124 |
{ months => [ 0, 0, 333.33, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], quarters => [ 333.33, 0, 0, 0 ], year => 333.33 }, |
... | ... | |
140 | 140 |
for qw(purchase_invoices purchase_orders requests_for_quotation sales_invoices sales_quotations); |
141 | 141 |
|
142 | 142 |
is_deeply($ctrl->data->{sales_orders}, |
143 |
{ months => [ 0, 83.3325, 0, 0, 83.3325, 0, 0, 83.3325, 0, 0, 83.3325, 0 ], quarters => [ 83.3325, 83.3325, 83.3325, 83.3325 ], year => 333.33 },
|
|
143 |
{ months => [ 0, 83.34, 0, 0, 83.33, 0, 0, 83.33, 0, 0, 83.33, 0 ], quarters => [ 83.34, 83.33, 83.33, 83.33 ], year => 333.33 },
|
|
144 | 144 |
"periodic conf p=q ovp=y, no invoices, starting previous year, data for sales_orders"); |
145 | 145 |
is_deeply($ctrl->data->{sales_orders_per_inv}, |
146 | 146 |
{ months => [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], quarters => [ 0, 0, 0, 0 ], year => 0 }, |
... | ... | |
164 | 164 |
for qw(purchase_invoices purchase_orders requests_for_quotation sales_invoices sales_quotations); |
165 | 165 |
|
166 | 166 |
is_deeply($ctrl->data->{sales_orders}, |
167 |
{ months => [ 0, 83.3325, 0, 0, 83.3325, 0, 0, 83.3325, 0, 0, 0, 0 ], quarters => [ 83.3325, 83.3325, 83.3325, 0 ], year => 249.9975 },
|
|
167 |
{ months => [ 0, 83.34, 0, 0, 83.33, 0, 0, 83.33, 0, 0, 0, 0 ], quarters => [ 83.34, 83.33, 83.33, 0 ], year => 250 },
|
|
168 | 168 |
"periodic conf p=q ovp=y, no invoices, starting previous year, ending middle of year, data for sales_orders"); |
169 | 169 |
is_deeply($ctrl->data->{sales_orders_per_inv}, |
170 | 170 |
{ months => [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], quarters => [ 0, 0, 0, 0 ], year => 0 }, |
Auch abrufbar als: Unified diff
S:C:FinancialOverview: Nutze Helferfunktion zum Berechnen von Wied. Rech.