Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1334ac8e

Von Jan Büren vor etwa 2 Monaten hinzugefügt

  • ID 1334ac8e1042fe691d7f9730c793e60d33a3285b
  • Vorgänger 43d75428
  • Nachfolger 67e83af0

BJ: SetNumberRange kann auch monatlich oder täglich geändert werden

Unterschiede anzeigen:

SL/BackgroundJob/SetNumberRange.pm
if ($data->{multiplier} && !($data->{multiplier} % 10 == 0)) {
die "No valid input for multiplier should be 10, 100, .., 1000000";
}
if ($data->{monthly} && $data->{monthly_strftime}) {
DateTime->today_local->strftime($data->{monthly_strftime}) // die "No valid input for montly_strftime";
}
# new year
my $running_year = $data->{current_year} ? DateTime->today_local->truncate(to => 'year')
: DateTime->today_local->truncate(to => 'year')->add(years => 1)->year();
......
my $multiplier = $data->{multiplier} || 100;
# or new month
my $today_dt = DateTime->today_local;
my $today = $data->{monthly_strftime} ? $today_dt->strftime($data->{monthly_strftime})
: $today_dt->strftime('%y-%m-');
$today = $data->{monthly_postfix} ? $today . $data->{monthly_postfix} : $today . '000';
my $defaults = SL::DB::Default->get;
my $current_number;
foreach (qw(invnumber cnnumber soinumber pqinumber sonumber ponumber pocnumber
sqnumber rfqnumber sdonumber pdonumber sudonumber rdonumber
s_reclamation_record_number p_reclamation_record_number )) {
my $current_number = SL::PrefixedNumber->new(number => $defaults->{$_});
$current_number->set_to($running_year * $multiplier);
if ($data->{monthly}) {
$current_number = SL::PrefixedNumber->new(number => $today);
} else {
$current_number = SL::PrefixedNumber->new(number => $defaults->{$_});
$current_number->set_to($running_year * $multiplier);
}
$defaults->{$_} = $current_number->get_current;
}
$defaults->save() || die "Could not change number ranges";
......
=head1 NAME
SL::BackgroundJob::SetNumberRange —
Background job for setting all kivitendo number ranges for a new year
Background job for setting all kivitendo number ranges for a new year or a new month
=head1 SYNOPSIS
The backgroud accepts the following optional json encoded parameters in the data field:
The job can either be run annually or monthly and defaults to annually.
The backgroud accepts the following optional json encoded parameters in the data for monthly mode:
C<monthly>: If set to true the job assumes it is the first of a new month
C<monthly_postfix>: A user postfix can be defined as a string for the new number.
If nothing is set three zeros are added as a postfix string ('000').
C<monthly_strftime>: Year, month and day can be optional be defined as user input in the
same way as the C strftime method. If nothing is set 'y%-m%' is the default. More options at the
time of writing can be found here: https://metacpan.org/pod/DateTime#strftime-Patterns
The backgroud accepts the following optional json encoded parameters in the data for the annually mode (default):
C<multiplier>: Multiplier to set the number range (defaults to 100)

Auch abrufbar als: Unified diff