Revision fde528b6
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/BackgroundJob/CreatePeriodicInvoices.pm | ||
---|---|---|
188 | 188 |
} |
189 | 189 |
|
190 | 190 |
sub _calculate_dates { |
191 |
my $config = shift; |
|
192 |
|
|
193 |
my $cur_date = $config->first_billing_date || $config->start_date; |
|
194 |
my $start_date = $config->get_previous_invoice_date || DateTime->new(year => 1970, month => 1, day => 1); |
|
195 |
my $end_date = $config->end_date || DateTime->new(year => 2100, month => 1, day => 1); |
|
196 |
my $tomorrow = DateTime->today_local->add(days => 1); |
|
197 |
my $period_len = $config->get_period_length; |
|
198 |
|
|
199 |
$end_date = $tomorrow if $end_date > $tomorrow; |
|
200 |
|
|
201 |
my @dates; |
|
202 |
|
|
203 |
while (1) { |
|
204 |
last if $cur_date >= $end_date; |
|
205 |
|
|
206 |
push @dates, $cur_date->clone if $cur_date > $start_date; |
|
207 |
|
|
208 |
$cur_date->add(months => $period_len); |
|
209 |
} |
|
210 |
|
|
211 |
return @dates; |
|
191 |
my ($config) = @_; |
|
192 |
return $config->calculate_invoice_dates(end_date => DateTime->today_local->add(days => 1)); |
|
212 | 193 |
} |
213 | 194 |
|
214 | 195 |
sub _send_email { |
SL/DB/PeriodicInvoicesConfig.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use SL::DB::MetaSetup::PeriodicInvoicesConfig; |
6 | 6 |
|
7 |
use List::Util qw(max min); |
|
8 |
|
|
7 | 9 |
__PACKAGE__->meta->initialize; |
8 | 10 |
|
9 | 11 |
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. |
... | ... | |
74 | 76 |
return ref $max_transdate ? $max_transdate : $self->db->parse_date($max_transdate); |
75 | 77 |
} |
76 | 78 |
|
79 |
sub calculate_invoice_dates { |
|
80 |
my ($self, %params) = @_; |
|
81 |
|
|
82 |
my $cur_date = $self->first_billing_date || $self->start_date; |
|
83 |
my $start_date = $self->get_previous_invoice_date || DateTime->new(year => 1970, month => 1, day => 1); |
|
84 |
my $end_date = $self->end_date || DateTime->today_local->add(years => 10); |
|
85 |
my $period_len = $self->get_period_length; |
|
86 |
|
|
87 |
$start_date = max($start_date, $params{start_date}) if $params{start_date}; |
|
88 |
$end_date = min($end_date, $params{end_date}) if $params{end_date}; |
|
89 |
|
|
90 |
my @dates; |
|
91 |
|
|
92 |
while ($cur_date < $end_date) { |
|
93 |
push @dates, $cur_date->clone if $cur_date > $start_date; |
|
94 |
|
|
95 |
$cur_date->add(months => $period_len); |
|
96 |
} |
|
97 |
|
|
98 |
return @dates; |
|
99 |
} |
|
100 |
|
|
77 | 101 |
1; |
Auch abrufbar als: Unified diff
SL::DB::PeriodicInvoicesConfig: Datumsberechnung aus Backgroundjob verschoben