Revision 5d90b614
Von Tamino Steinert vor 3 Monaten hinzugefügt
SL/DB/PeriodicInvoicesConfig.pm | ||
---|---|---|
194 | 194 |
|
195 | 195 |
my $last_created_on_date = $self->get_previous_billed_period_start_date; |
196 | 196 |
|
197 |
my @start_dates; |
|
198 |
my $first_period_start_date = $self->first_billing_date || $self->start_date; |
|
197 |
my $first_invoice_date = $self->first_billing_date || $self->start_date; |
|
198 |
$first_invoice_date = $self->add_months( |
|
199 |
$first_invoice_date, $self->get_billing_period_length || 1 |
|
200 |
) while $first_invoice_date < $self->start_date; |
|
201 |
|
|
202 |
my @invoice_dates; |
|
199 | 203 |
if ($self->periodicity ne 'o') { |
200 | 204 |
my $billing_period_length = $self->get_billing_period_length; |
201 |
my $months_first_period =
|
|
202 |
$first_period_start_date->year * 12 + $first_period_start_date->month;
|
|
205 |
my $months_first_invoice_date =
|
|
206 |
$first_invoice_date->year * 12 + $first_invoice_date->month;
|
|
203 | 207 |
|
204 |
my $month_to_start = $start_date->year * 12 + $start_date->month - $months_first_period;
|
|
205 |
$month_to_start += 1
|
|
206 |
if $self->add_months($first_period_start_date, $month_to_start) < $start_date;
|
|
208 |
my $month_to_start = $start_date->year * 12 + $start_date->month - $months_first_invoice_date;
|
|
209 |
$month_to_start++
|
|
210 |
if $self->add_months($first_invoice_date, $month_to_start) < $start_date;
|
|
207 | 211 |
|
208 | 212 |
my $month_after_last_created = 0; |
209 | 213 |
if ($last_created_on_date) { |
210 | 214 |
$month_after_last_created = |
211 |
$last_created_on_date->year * 12 + $last_created_on_date->month - $months_first_period;
|
|
215 |
$last_created_on_date->year * 12 + $last_created_on_date->month - $months_first_invoice_date;
|
|
212 | 216 |
$month_after_last_created += 1 |
213 |
if $self->add_months($first_period_start_date, $month_after_last_created) <= $last_created_on_date;
|
|
217 |
if $self->add_months($first_invoice_date, $month_after_last_created) <= $last_created_on_date;
|
|
214 | 218 |
} |
215 | 219 |
|
216 | 220 |
my $months_from_period_start = max( |
... | ... | |
221 | 225 |
my $period_count = int($months_from_period_start / $billing_period_length); # floor |
222 | 226 |
$period_count += $months_from_period_start % $billing_period_length != 0 ? 1 : 0; # ceil |
223 | 227 |
|
224 |
my $next_period_start_date = $self->add_months($first_period_start_date, $period_count * $billing_period_length);
|
|
228 |
my $next_period_start_date = $self->add_months($first_invoice_date, $period_count * $billing_period_length);
|
|
225 | 229 |
while ($next_period_start_date <= $end_date) { |
226 |
push @start_dates, $next_period_start_date;
|
|
230 |
push @invoice_dates, $next_period_start_date;
|
|
227 | 231 |
$period_count++; |
228 |
$next_period_start_date = $self->add_months($first_period_start_date, $period_count * $billing_period_length);
|
|
232 |
$next_period_start_date = $self->add_months($first_invoice_date, $period_count * $billing_period_length);
|
|
229 | 233 |
} |
230 | 234 |
} else { # single |
231 |
push @start_dates, $first_period_start_date
|
|
235 |
push @invoice_dates, $first_invoice_date
|
|
232 | 236 |
unless $last_created_on_date |
233 |
|| $first_period_start_date < $start_date
|
|
234 |
|| $first_period_start_date > $end_date;
|
|
237 |
|| $first_invoice_date < $start_date
|
|
238 |
|| $first_invoice_date > $end_date;
|
|
235 | 239 |
} |
236 | 240 |
|
237 |
return @start_dates;
|
|
241 |
return @invoice_dates;
|
|
238 | 242 |
} |
239 | 243 |
|
240 | 244 |
sub last_end_date { |
... | ... | |
461 | 465 |
|
462 | 466 |
=item C<calculate_invoice_dates %params> |
463 | 467 |
|
464 |
Calculates dates for which invoices will have to be created. Returns a |
|
465 |
list of L<DateTime> objects. |
|
468 |
Calculates dates for which invoices will have to be created in the period given |
|
469 |
by the parameters C<start_date> and C<end_date>. Returns a list of L<DateTime> |
|
470 |
objects. |
|
466 | 471 |
|
467 | 472 |
This function looks at the configuration settings and at the list of |
468 | 473 |
invoices that have already been created for this configuration. The |
... | ... | |
472 | 477 |
=over 2 |
473 | 478 |
|
474 | 479 |
=item * The properties C<first_billing_date> and C<start_date> |
475 |
determine the start date. |
|
476 |
|
|
477 |
=item * The properties C<end_date> and C<terminated> determine the end |
|
478 |
date. |
|
480 |
determine the first invoice date. |
|
479 | 481 |
|
480 |
=item * The optional parameter C<past_dates> determines whether or not |
|
481 |
dates for which invoices have already been created will be included in |
|
482 |
the list. The default is not to include them. |
|
482 |
=item * The properties C<end_date>, C<terminated> and C<extend_automatically_by> |
|
483 |
determine the end date. |
|
483 | 484 |
|
484 |
=item * The optional parameters C<start_date> and C<end_date> override
|
|
485 |
the start and end dates from the configuration.
|
|
485 |
=item * The parameter C<start_date> of the period defaults to the start date
|
|
486 |
from the configuration. |
|
486 | 487 |
|
487 |
=item * If no end date is set or implied via the configuration and no |
|
488 |
C<end_date> parameter is given then the function will use 100 years |
|
489 |
in the future as the end date. |
|
488 |
=item * The parameter C<end_date> defaults to current date. |
|
490 | 489 |
|
491 | 490 |
=back |
492 | 491 |
|
Auch abrufbar als: Unified diff
S:D:PeriodicInvoicesConfig: FIX: calculate_invoice_dates angepasst