Revision e356439e
SL/BackgroundJob/SetNumberRange.pm | ||
---|---|---|
23 | 23 |
if ($data->{multiplier} && !($data->{multiplier} % 10 == 0)) { |
24 | 24 |
die "No valid input for multiplier should be 10, 100, .., 1000000"; |
25 | 25 |
} |
26 |
if ($data->{monthly} && $data->{monthly_strftime}) { |
|
27 |
DateTime->today_local->strftime($data->{monthly_strftime}) // die "No valid input for montly_strftime"; |
|
28 |
} |
|
26 | 29 |
|
30 |
# new year |
|
27 | 31 |
my $running_year = $data->{current_year} ? DateTime->today_local->truncate(to => 'year') |
28 | 32 |
: DateTime->today_local->truncate(to => 'year')->add(years => 1)->year(); |
29 | 33 |
|
... | ... | |
31 | 35 |
|
32 | 36 |
my $multiplier = $data->{multiplier} || 100; |
33 | 37 |
|
38 |
# or new month |
|
39 |
my $today_dt = DateTime->today_local; |
|
40 |
|
|
41 |
my $today = $data->{monthly_strftime} ? $today_dt->strftime($data->{monthly_strftime}) |
|
42 |
: $today_dt->strftime('%y-%m-'); |
|
43 |
|
|
44 |
$today = $data->{monthly_postfix} ? $today . $data->{monthly_postfix} : $today . '000'; |
|
45 |
|
|
34 | 46 |
my $defaults = SL::DB::Default->get; |
35 | 47 |
|
48 |
my $current_number; |
|
36 | 49 |
foreach (qw(invnumber cnnumber soinumber pqinumber sonumber ponumber pocnumber |
37 | 50 |
sqnumber rfqnumber sdonumber pdonumber sudonumber rdonumber |
38 | 51 |
s_reclamation_record_number p_reclamation_record_number )) { |
39 | 52 |
|
40 |
my $current_number = SL::PrefixedNumber->new(number => $defaults->{$_}); |
|
41 |
$current_number->set_to($running_year * $multiplier); |
|
53 |
|
|
54 |
if ($data->{monthly}) { |
|
55 |
$current_number = SL::PrefixedNumber->new(number => $today); |
|
56 |
} else { |
|
57 |
$current_number = SL::PrefixedNumber->new(number => $defaults->{$_}); |
|
58 |
$current_number->set_to($running_year * $multiplier); |
|
59 |
} |
|
42 | 60 |
$defaults->{$_} = $current_number->get_current; |
43 | 61 |
} |
44 | 62 |
$defaults->save() || die "Could not change number ranges"; |
... | ... | |
55 | 73 |
=head1 NAME |
56 | 74 |
|
57 | 75 |
SL::BackgroundJob::SetNumberRange — |
58 |
Background job for setting all kivitendo number ranges for a new year |
|
76 |
Background job for setting all kivitendo number ranges for a new year or a new month
|
|
59 | 77 |
|
60 | 78 |
=head1 SYNOPSIS |
61 | 79 |
|
62 |
The backgroud accepts the following optional json encoded parameters in the data field: |
|
80 |
The job can either be run annually or monthly and defaults to annually. |
|
81 |
|
|
82 |
The backgroud accepts the following optional json encoded parameters in the data for monthly mode: |
|
83 |
|
|
84 |
C<monthly>: If set to true the job assumes it is the first of a new month |
|
85 |
|
|
86 |
C<monthly_postfix>: A user postfix can be defined as a string for the new number. |
|
87 |
If nothing is set three zeros are added as a postfix string ('000'). |
|
88 |
|
|
89 |
C<monthly_strftime>: Year, month and day can be optional be defined as user input in the |
|
90 |
same way as the C strftime method. If nothing is set 'y%-m%' is the default. More options at the |
|
91 |
time of writing can be found here: https://metacpan.org/pod/DateTime#strftime-Patterns |
|
92 |
|
|
93 |
The backgroud accepts the following optional json encoded parameters in the data for the annually mode (default): |
|
63 | 94 |
|
64 | 95 |
C<multiplier>: Multiplier to set the number range (defaults to 100) |
65 | 96 |
|
Auch abrufbar als: Unified diff
BJ: SetNumberRange kann auch monatlich oder täglich geändert werden