From 28a19df13de79f52e624837b63d299caa700ee2e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 13 Sep 2024 17:41:02 +0000 Subject: [PATCH] Bug 37796: Pass correct publication date when generating the next serial form the serial collection page Before this patch, we pass the previous issue date to generate the next seq - this works for the pattern as we are incrementing. When the patter is translated ot words, we need to do this from the date of the next issue, so we must pass in the next published date This patch changes the call to GetNextSeq from serial-collection.pl to ensure the new issue publication date is used to generate the numbers. To test: 0 - Follow the plan to recreate from the initial bug description and recreate 1 - Apply patch 2 - On the serial used in previous patch go to 'Serial collection' 3 - Generate next issue 4 - Confirm the numbering is correctly generated after this patch Signed-off-by: Wesley Owen --- C4/Serials.pm | 16 +++++++++------- serials/serials-collection.pl | 14 ++++++++++---- t/Serials/GetNextSeq.t | 2 +- t/db_dependent/Serials.t | 14 ++++++++------ 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 18f7318e506..09bcf1ed75b 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -813,7 +813,7 @@ sub GetPreviousSerialid { my ( $nextseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) = GetNextSeq( $subscription, $pattern, $frequency, $planneddate, $count_forward ); + ) = GetNextSeq( $subscription, $pattern, $frequency, $planneddate, $nextpublisheddate, $count_forward ); $subscription is a hashref containing all the attributes of the table 'subscription'. @@ -821,13 +821,14 @@ $pattern is a hashref containing all the attributes of the table 'subscription_numberpatterns'. $frequency is a hashref containing all the attributes of the table 'subscription_frequencies' $planneddate is a date string in iso format. +$nextpublishedddate is a date string in iso format. $count_forward is the number of issues to count forward, defaults to 1 if omitted This function get the next issue for the subscription given on input arg =cut sub GetNextSeq { - my ( $subscription, $pattern, $frequency, $planneddate, $count_forward ) = @_; + my ( $subscription, $pattern, $frequency, $planneddate, $nextpublisheddate, $count_forward ) = @_; return unless ( $subscription and $pattern ); @@ -918,7 +919,7 @@ sub GetNextSeq { $calculated =~ s/\{Z\}/$newlastvalue3string/g; } - my $dt = dt_from_string($planneddate); + my $dt = dt_from_string($nextpublisheddate); $calculated =~ s/\{Month\}/$dt->month/eg; $calculated =~ s/\{MonthName\}/$dt->month_name/eg; $calculated =~ s/\{Year\}/$dt->year/eg; @@ -1170,15 +1171,16 @@ sub ModSerialStatus { my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern( $subscription->{numberpattern} ); my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency( $subscription->{periodicity} ); + # next date (calculated from actual date & frequency parameters) + my $nextpublisheddate = GetNextDate( $subscription, $publisheddate, $frequency, 1 ); + my $nextpubdate = $nextpublisheddate; + # next issue number my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate, $count ); + ) = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate, $nextpublisheddate, $count ); - # next date (calculated from actual date & frequency parameters) - my $nextpublisheddate = GetNextDate( $subscription, $publisheddate, $frequency, 1 ); - my $nextpubdate = $nextpublisheddate; $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? WHERE subscriptionid = ?"; diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index eccb80cbf5f..d0d2812b3ac 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -82,14 +82,20 @@ if ( $op eq 'cud-gennext' && @subscriptionid ) { my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern( $subscription->{numberpattern} ); my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency( $subscription->{periodicity} ); my $expected = GetNextExpected($subscriptionid); + + ## We generate the next publication date + my $nextpublisheddate = GetNextDate( $subscription, $expected->{publisheddate}, $frequency, 1 ); + my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) = GetNextSeq( $subscription, $pattern, $frequency, $expected->{publisheddate}, $count_forward ); + ) + = GetNextSeq( + $subscription, $pattern, $frequency, $expected->{publisheddate}, $nextpublisheddate, + $count_forward + ); - ## We generate the next publication date - my $nextpublisheddate = GetNextDate( $subscription, $expected->{publisheddate}, $frequency, 1 ); - my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate; + my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate; ## Creating the new issue NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'}, diff --git a/t/Serials/GetNextSeq.t b/t/Serials/GetNextSeq.t index 5d36b70278e..5f309b1f41c 100755 --- a/t/Serials/GetNextSeq.t +++ b/t/Serials/GetNextSeq.t @@ -259,6 +259,6 @@ sub _next_seq { $seq, $subscription->{lastvalue1}, $subscription->{lastvalue2}, $subscription->{lastvalue3}, $subscription->{innerloop1}, $subscription->{innerloop2}, $subscription->{innerloop3} - ) = GetNextSeq( $subscription, $pattern, undef, undef, $count_forward ); + ) = GetNextSeq( $subscription, $pattern, undef, undef, undef, $count_forward ); return $seq; } diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index 1e2e5bbff69..f2bd3ca18f5 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -726,14 +726,16 @@ subtest "test numbering pattern with dates in GetSeq GetNextSeq" => sub { 'GetSeq correctly calculates numbering from first aqui date, leap year' ); - my $planneddate = '1970-11-01'; - ($numbering) = GetNextSeq( $subscription, $pattern, undef, $planneddate ); - is( $numbering, '1970 1 Sunday 11 November', 'GetNextSeq correctly calculates numbering from planned date' ); - $planneddate = '2024-02-29'; - ($numbering) = GetNextSeq( $subscription, $pattern, undef, $planneddate ); + my $planneddate = '1970-10-01'; + my $nextpublisheddate = '1970-11-01'; + ($numbering) = GetNextSeq( $subscription, $pattern, undef, $planneddate, $nextpublisheddate ); + is( $numbering, '1970 1 Sunday 11 November', 'GetNextSeq correctly calculates numbering from next published date' ); + $planneddate = '2024-01-29'; + $nextpublisheddate = '2024-02-29'; + ($numbering) = GetNextSeq( $subscription, $pattern, undef, $planneddate, $nextpublisheddate ); is( $numbering, '2024 29 Thursday 2 February', - 'GetNextSeq correctly calculates numbering from planned date, leap year' + 'GetNextSeq correctly calculates numbering from next published date, leap year' ); }; -- 2.39.5