Revision dd1e5f3e
Von Moritz Bunkus vor fast 2 Jahren hinzugefügt
SL/Controller/FinancialOverview.pm | ||
---|---|---|
151 | 151 |
sub calculate_periodic_invoices { |
152 | 152 |
my ($self) = @_; |
153 | 153 |
|
154 |
my %billed_once_item_ids; |
|
154 | 155 |
my $start_date = DateTime->new(year => $self->year, month => 1, day => 1, time_zone => $::locale->get_local_time_zone); |
155 | 156 |
my $end_date = DateTime->new(year => $self->year, month => 12, day => 31, time_zone => $::locale->get_local_time_zone); |
156 | 157 |
|
157 |
$self->calculate_one_periodic_invoice(config => $_, start_date => $start_date, end_date => $end_date) for @{ $self->objects->{periodic_invoices_cfg} }; |
|
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 |
} |
|
158 | 166 |
} |
159 | 167 |
|
160 | 168 |
sub calculate_one_periodic_invoice { |
161 | 169 |
my ($self, %params) = @_; |
162 | 170 |
|
163 | 171 |
# Calculate sales order advance |
164 |
my $net = $params{config}->order->netamount * $params{config}->get_billing_period_length / $params{config}->get_order_value_period_length; |
|
165 | 172 |
my $sord = $self->data->{sales_orders}; |
166 | 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; |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
$net = $net * $params{config}->get_billing_period_length / $params{config}->get_order_value_period_length; |
|
193 |
|
|
167 | 194 |
foreach my $date ($params{config}->calculate_invoice_dates(start_date => $params{start_date}, end_date => $params{end_date}, past_dates => 1)) { |
168 |
$sord->{months }->[ $date->month - 1 ] += $net; |
|
169 |
$sord->{quarters}->[ $date->quarter - 1 ] += $net; |
|
170 |
$sord->{year} += $net; |
|
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; |
|
171 | 200 |
} |
172 | 201 |
|
173 | 202 |
# Calculate total sales order value |
Auch abrufbar als: Unified diff
Wiederkehrende Abrechnung Positionen: Finanzübersicht