From 15424f9b2f0b938aa507f45df1120ba8ab9e3b01 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 22 Dec 2023 18:20:09 +0000 Subject: [PATCH] Bug 35646: Allow use of publication date fields in serial numbering pattern This patch extends the numbering pattern field to accept subsititutions for: {Year} {Day} {DayName} {Month} {MonthName} These fields are based on the publication date for the serial issue. To test: 0 - Apply patch 1 - Setup a enw numbering pattern Serials->Manage numbering patterns + New numbering pattern 2 - In the numbering formula enter: {X} {Y} {Z} {Year} {Month} {Day} {MonthName} {DayName} 3 - Populate X/Y/Z in the table as you wish, these should be unaffected by patch 4 - Set a Frequency / First issue plublication date / Subscription length 5 - Click 'Test pattern' 6 - Confirm the dates in the Number match the publication date values 7 - Try with different frequencies to confirm they match 8 - Save the pattern 9 - Create a new subscription and use the new pattern 10 - Confirm it works as expected Signed-off-by: Lucas Gass Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer --- C4/Serials.pm | 16 ++++++++++++++++ serials/showpredictionpattern.pl | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index ec88b0f3e6..6211779d43 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -42,6 +42,7 @@ use C4::Serials::Frequency qw( GetSubscriptionFrequency ); use C4::Serials::Numberpattern; use Koha::AdditionalFieldValues; use Koha::Biblios; +use Koha::DateUtils qw( dt_from_string ); use Koha::Serial; use Koha::SharedContent; use Koha::Subscription::Histories; @@ -909,6 +910,13 @@ sub GetNextSeq { $calculated =~ s/\{Z\}/$newlastvalue3string/g; } + my $dt = dt_from_string($planneddate); + $calculated =~ s/\{Month\}/$dt->month/eg; + $calculated =~ s/\{MonthName\}/$dt->month_name/eg; + $calculated =~ s/\{Year\}/$dt->year/eg; + $calculated =~ s/\{Day\}/$dt->day/eg; + $calculated =~ s/\{DayName\}/$dt->day_name/eg; + } return ($calculated, @@ -947,6 +955,14 @@ sub GetSeq { my $newlastvalue3 = $subscription->{'lastvalue3'} || 0; $newlastvalue3 = _numeration($newlastvalue3, $pattern->{numbering3}, $locale) if ($pattern->{numbering3}); # reset counter if needed. $calculated =~ s/\{Z\}/$newlastvalue3/g; + + my $dt = dt_from_string( $subscription->{firstaquidate} ); + $calculated =~ s/\{Month\}/$dt->month/eg; + $calculated =~ s/\{MonthName\}/$dt->month_name/eg; + $calculated =~ s/\{Year\}/$dt->year/eg; + $calculated =~ s/\{Day\}/$dt->day/eg; + $calculated =~ s/\{DayName\}/$dt->day_name/eg; + return $calculated; } diff --git a/serials/showpredictionpattern.pl b/serials/showpredictionpattern.pl index 9fc801102b..ae5e958ef3 100755 --- a/serials/showpredictionpattern.pl +++ b/serials/showpredictionpattern.pl @@ -163,7 +163,7 @@ while( $i < 1000 ) { last; } - ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern, $frequency); + ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern, $frequency, $date); $issuenumber++; $line{'number'} = $calculated; $line{'issuenumber'} = $issuenumber; -- 2.39.5