From 68daee03d45b78b6f2772c6d614bb9da84a1e2be Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Mon, 26 Oct 2015 14:15:09 +0200 Subject: [PATCH] Bug 11626 - Cannot receive serial issues after subscription expiry date Some of our serials subscriptions were not renewed after 31/12/2013 but I cannot receive any of the outstanding 2013 issues unless I renew the subscription record (a couple of publishers are about 3 months late with their printing/postage schedules compared to the subscription/cover dates). We should still be able to receive late issues after the subscription expiry date (the date published for these issues would in most cases be on or before the expiry date). THIS PATCH: Changes expiration date checking for each serial to be calculated from the individual Serial's serial.publicationdate instead of the Serial's Subscription's expirationdate. Thus you can still receive late serials if their publicationdate is within the Subscription period. Replicating this issue in finicky, just as the Serials module is, but this patch fixes this design flaw in the Serials-module. REPLICATE THE ISSUE: 0. Have a Subscription with an end date. 1. Receive all the Subscription's Serials. 2. You cannot receive the last Serial of the subscription period. TEST PLAN: 0. Have a Subscription with an end date. 1. Receive all the Subscription's Serials. 2. Receive the last Subscription of the subscription period. --- C4/Serials.pm | 38 +++++++++++++++++++++++++++++++++++++- serials/serials-edit.pl | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 973ac46..0598f6a 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -24,6 +24,7 @@ use C4::Auth qw(haspermission); use C4::Context; use C4::Dates qw(format_date format_date_in_iso); use DateTime; +use DateTime::Format::MySQL; use Date::Calc qw(:all); use POSIX qw(strftime); use C4::Biblio; @@ -268,7 +269,7 @@ sub GetSerialInformation { } } $data->{ "status" . $data->{'serstatus'} } = 1; - $data->{'subscriptionexpired'} = HasSubscriptionExpired( $data->{'subscriptionid'} ) && $data->{'status'} == 1; + $data->{'subscriptionexpired'} = C4::Serials::HasSerialExpired( $data ) && $data->{'status'} == 1; $data->{'abouttoexpire'} = abouttoexpire( $data->{'subscriptionid'} ); $data->{cannotedit} = not can_edit_subscription( $data ); return $data; @@ -1878,6 +1879,41 @@ sub HasSubscriptionExpired { return 0; # Notice that you'll never get here. } +=head2 HasSerialExpired + +$has_expired = HasSerialExpired($serial) + +the serial has expired when the serials.publisheddate is beyond the subscription expiration date. + +Used to check if individual serials can still be received even if the subscription +has already expired. + +@param {HASHRef} Serial + +@returns : 0 if the serial has not expired + 1 if the serial has expired + 2 if has serial does not have a valid expiration date set + +=cut + +sub HasSerialExpired { + my ($serial) = @_; + + return unless ($serial); + + #Normalize dates for comparison + my $expirationdate = DateTime::Format::MySQL->parse_date($serial->{enddate} || GetExpirationDate($serial->{subscriptionid})); + my $publisheddate = Koha::DateUtils::dt_from_string($serial->{publisheddate}); + + if (!defined $expirationdate) { + return 2; + } + if (DateTime->compare($publisheddate, $expirationdate) == -1) { #publisheddate < expirationdate + return 0; + } + return 1; +} + =head2 SetDistributedto SetDistributedto($distributedto,$subscriptionid); diff --git a/serials/serials-edit.pl b/serials/serials-edit.pl index c6151c7..a19129e 100755 --- a/serials/serials-edit.pl +++ b/serials/serials-edit.pl @@ -147,7 +147,7 @@ foreach my $serialid (@serialids) { $serinfo->{'editdisable'} = ( ( - HasSubscriptionExpired( $serinfo->{subscriptionid} ) + C4::Serials::HasSerialExpired( $serinfo ) && $serinfo->{'status1'} ) || $serinfo->{'cannotedit'} -- 1.9.1