1 package SL::BackgroundJob::SetClosedTo;
5 use parent qw(SL::BackgroundJob::Base);
7 use SL::Helper::DateTime;
10 $_[0]->create_standard_job('1 0 10 * *'); # always the 10th of the month
15 my ($self, $db_obj) = @_;
16 my $data = $db_obj->data_as_hash;
18 my $subtract_month = $data->{subtract_month} || 1;
19 my $subtract_days = $data->{subtract_days} || 10;
21 die "No integer number for days or month" unless ($subtract_month =~ m/^\d+\z/
22 && $subtract_days =~ m/^\d+\z/);
25 my $new_closedto = DateTime->now_local->subtract(months => $subtract_month, days => $subtract_days);
27 my $defaults = SL::DB::Default->get;
29 # dont accidently open the books
30 return 1 if ($defaults->closedto && $defaults->closedto >= $new_closedto);
32 $defaults->closedto($new_closedto);
33 $defaults->save || die "Cannot save closedto!";
46 SL::BackgroundJob::SetClosedTo - Background job for
47 periodically setting closedto (books closed until).
48 Defaults to the end of the second last month.