From 15b8d4bbc30aaed01468cc32044f6769130addd6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Thu, 31 Oct 2019 14:32:03 +0100 Subject: [PATCH] =?utf8?q?SetNumberRange:=20Background-Job=20um=20Jahresza?= =?utf8?q?hlen=20im=20Nummernkreis=20zu=20erh=C3=B6hen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Nimmt die vierstellige Zahl des nächsten Jahres und multipliziert diese mit 1 oder einem anderen Faktor. Präfixe und Länge des Nummernkreis bleibt erhalten. Bspw.: Letzte Rechnungsnummer: RE201900009 --> RE202000000 Folgende Werte: multiplier: 100000 digits_year: 4 multiplier: beliebiger Wert (empfohlen: 1, 10, 100, 1000, default 1) digits_year: 4 || 2 (Falls keine 2 gesetzt ist, wird 4 verwendet) 2019 || 19 --- SL/BackgroundJob/SetNumberRange.pm | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 SL/BackgroundJob/SetNumberRange.pm diff --git a/SL/BackgroundJob/SetNumberRange.pm b/SL/BackgroundJob/SetNumberRange.pm new file mode 100644 index 000000000..e317730f3 --- /dev/null +++ b/SL/BackgroundJob/SetNumberRange.pm @@ -0,0 +1,36 @@ +package SL::BackgroundJob::SetNumberRange; + +use strict; + +use parent qw(SL::BackgroundJob::Base); + +use SL::PrefixedNumber; + +use DateTime::Format::Strptime; + +sub create_job { + $_[0]->create_standard_job('59 23 31 12 *'); # one minute before new year +} + + +sub run { + my ($self, $db_obj) = @_; + my $data = $db_obj->data_as_hash; + + my $next_year = DateTime->today_local->truncate(to => 'year')->add(years => 1)->year(); + $next_year = ($data->{digits_year} == 2) ? substr($next_year, 2, 2) : $next_year; + my $multiplier = $data->{multiplier} || 1; + + my $defaults = SL::DB::Default->get; + + foreach (qw(invnumber cnnumber sonumber ponumber sqnumber rfqnumber sdonumber pdonumber)) { + my $current_number = SL::PrefixedNumber->new(number => $defaults->{$_}); + $current_number->set_to($next_year * $multiplier); + $defaults->{$_} = $current_number->get_current; + } + $defaults->save() || die "Could not change number ranges"; + + return exists $data->{result} ? $data->{result} : 1; +} + +1; -- 2.20.1