1 package SL::BackgroundJob::SetNumberRange;
5 use parent qw(SL::BackgroundJob::Base);
7 use SL::PrefixedNumber;
9 use DateTime::Format::Strptime;
12 $_[0]->create_standard_job('59 23 31 12 *'); # one minute before new year
17 my ($self, $db_obj) = @_;
18 my $data = $db_obj->data_as_hash;
20 if ($data->{digits_year} && !($data->{digits_year} == 2 || $data->{digits_year} == 4)) {
21 die "No valid input for digits_year should be 2 or 4.";
23 if ($data->{multiplier} && !($data->{multiplier} % 10 == 0)) {
24 die "No valid input for multiplier should be 10, 100, .., 1000000";
26 my $next_year = DateTime->today_local->truncate(to => 'year')->add(years => 1)->year();
27 $next_year = ($data->{digits_year} == 2) ? substr($next_year, 2, 2) : $next_year;
28 my $multiplier = $data->{multiplier} || 100;
30 my $defaults = SL::DB::Default->get;
32 foreach (qw(invnumber cnnumber sonumber ponumber sqnumber rfqnumber sdonumber pdonumber)) {
33 my $current_number = SL::PrefixedNumber->new(number => $defaults->{$_});
34 $current_number->set_to($next_year * $multiplier);
35 $defaults->{$_} = $current_number->get_current;
37 $defaults->save() || die "Could not change number ranges";
39 return exists $data->{result} ? $data->{result} : 1;