From 47a9afcb7ecedc805550f46e6373b9a8c8615bdc Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 28 Mar 2014 14:38:25 +0100 Subject: [PATCH] Bug 12003: Do not calculate next pubdate for irregular subscriptions Show 'Unknown' when planneddate and publisheddate cannot be calculated Also fixes SQL query in misc/cronjobs/serialsUpdate.pl that was still using "periodicity != 32" to exclude irregular subscriptions from results Test plan: 1) Create a subscription in the serials module. Make sure to choose: Frequency = Irregular 2) Test the prediction pattern, first publication date is set to "First issue publication date" field, others will show as 'unknown' 3) Save the subscription 4) Check the created issue - it will show a published date and a planned date (same as "First issue publication date" field) 5) Receive the issue and check the next generated issue, planned date and published date should show as 'Unknown' 6) Generate a next issue, planned date and published date should also show as 'Unknown' Signed-off-by: Bernardo Gonzalez Kriegel Work as described following test plan. No koha-qa errors Signed-off-by: Katrin Fischer Passes all tests and QA script. Also tested: - multi receiving generates mulitple issues without dates - 'unknown' - staff detail page shows the dates empty, which is fine - OPAC detail page shows the dates empty, which is fine - serial collection page shows 'unknown' and those issues appear on the 'manage' tab, as they did in the past - Editing the issue from the serial collection page leaves the date fields empty. - Receving the issue, setting the status to 'Arrived' the Expected on date is set to 'today' automatically. Date published has to be entered manually (maybe something we could improve later - subscription detail > issues tab shows Uknown. - t/db_dependent/Serials/GetNextDate.t pass. Signed-off-by: Galen Charlton --- C4/Serials.pm | 17 ++++++----------- .../en/modules/serials/serials-collection.tt | 16 ++++++++++++++-- .../en/modules/serials/subscription-detail.tt | 12 ++++++++++-- misc/cronjobs/serialsUpdate.pl | 4 +++- serials/showpredictionpattern.pl | 4 ++-- t/db_dependent/Serials/GetNextDate.t | 18 ++++++++++++------ 6 files changed, 47 insertions(+), 24 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 2540f16e7d..c62d1ed81a 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -419,9 +419,9 @@ sub PrepareSerialsData { foreach my $subs (@{$lines}) { for my $datefield ( qw(publisheddate planneddate) ) { - # handle both undef and undef returned as 0000-00-00 - if (!defined $subs->{$datefield} or $subs->{$datefield}=~m/^00/) { - $subs->{$datefield} = 'XXX'; + # handle 0000-00-00 dates + if (defined $subs->{$datefield} and $subs->{$datefield} =~ m/^00/) { + $subs->{$datefield} = undef; } } $subs->{ "status" . $subs->{'status'} } = 1; @@ -1232,10 +1232,6 @@ sub ModSerialStatus { DelIssue( { 'serialid' => $serialid, 'subscriptionid' => $subscriptionid, 'serialseq' => $serialseq } ); } else { - unless ($frequency->{'unit'}) { - if ( not $planneddate or $planneddate eq '0000-00-00' ) { $planneddate = C4::Dates->new()->output('iso') }; - if ( not $publisheddate or $publisheddate eq '0000-00-00' ) { $publisheddate = C4::Dates->new()->output('iso') }; - } my $query = 'UPDATE serial SET serialseq=?,publisheddate=?,planneddate=?,status=?,notes=? WHERE serialid = ?'; $sth = $dbh->prepare($query); $sth->execute( $serialseq, $publisheddate, $planneddate, $status, $notes, $serialid ); @@ -2529,13 +2525,15 @@ skipped then the returned date will be 2007-05-10 return : $resultdate - then next date in the sequence (ISO date) -Return $publisheddate if subscription is irregular +Return undef if subscription is irregular =cut sub GetNextDate { my ( $subscription, $publisheddate, $updatecount ) = @_; + return unless $subscription and $publisheddate; + my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'}); if ($freqdata->{'unit'}) { @@ -2673,9 +2671,6 @@ sub GetNextDate { } return sprintf("%04d-%02d-%02d", $year, $month, $day); } - else { - return $publisheddate; - } } =head2 _numeration diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt index ed1dc3903e..ab39821a30 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt @@ -244,10 +244,22 @@ $(document).ready(function() { [% serial.subscriptionid %] [% END %] - [% serial.publisheddate | $KohaDates %] + + [% IF serial.publisheddate %] + [% serial.publisheddate | $KohaDates %] + [% ELSE %] + Unknown + [% END %] + - [% serial.planneddate | $KohaDates %] + + [% IF serial.planneddate %] + [% serial.planneddate | $KohaDates %] + [% ELSE %] + Unknown + [% END %] + [% serial.serialseq %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt index f02194e615..b684e5e2c9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt @@ -259,10 +259,18 @@ $(document).ready(function() { [% serialslis.serialseq %] - [% serialslis.planneddate %] + [% IF serialslis.planneddate %] + [% serialslis.planneddate %] + [% ELSE %] + Unknown + [% END %] - [% serialslis.publisheddate %] + [% IF serialslis.publisheddate %] + [% serialslis.publisheddate %] + [% ELSE %] + Unknown + [% END %] [% IF ( serialslis.status1 ) %]Expected[% END %] diff --git a/misc/cronjobs/serialsUpdate.pl b/misc/cronjobs/serialsUpdate.pl index 813ef21270..6ac5558b49 100755 --- a/misc/cronjobs/serialsUpdate.pl +++ b/misc/cronjobs/serialsUpdate.pl @@ -99,8 +99,10 @@ my $sth = $dbh->prepare( FROM serial LEFT JOIN subscription ON (subscription.subscriptionid=serial.subscriptionid) + LEFT JOIN subscription_frequencies + ON (subscription.periodicity = subscription_frequencies.id) WHERE serial.status = 1 - AND periodicity <> 32 + AND subscription_frequencies.unit IS NOT NULL AND DATE_ADD(planneddate, INTERVAL CAST(graceperiod AS SIGNED) DAY) < NOW() AND subscription.closed = 0 } diff --git a/serials/showpredictionpattern.pl b/serials/showpredictionpattern.pl index c654f556e0..82cf8af880 100755 --- a/serials/showpredictionpattern.pl +++ b/serials/showpredictionpattern.pl @@ -119,7 +119,7 @@ my @predictions_loop; my ($calculated) = GetSeq(\%subscription, \%pattern); push @predictions_loop, { number => $calculated, - publicationdate => ($frequency->{unit} ? $date : undef), + publicationdate => $date, issuenumber => $issuenumber, dow => Day_of_Week(split /-/, $date), }; @@ -143,7 +143,7 @@ while( $i < 1000 ) { $date = GetNextDate(\%subscription, $date); } if(defined $date){ - $line{'publicationdate'} = $date if $frequency->{unit}; + $line{'publicationdate'} = $date; $line{'dow'} = Day_of_Week(split /-/, $date); } diff --git a/t/db_dependent/Serials/GetNextDate.t b/t/db_dependent/Serials/GetNextDate.t index ed80f2965b..1572d0a78a 100644 --- a/t/db_dependent/Serials/GetNextDate.t +++ b/t/db_dependent/Serials/GetNextDate.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use C4::Context; -use Test::More tests => 84; +use Test::More tests => 86; use Modern::Perl; my $dbh = C4::Context->dbh; @@ -471,7 +471,7 @@ is($publisheddate, '1974-01-01'); # TEST CASE 25 - Irregular $id = AddSubscriptionFrequency({ description => "Irregular", - unit => '', + unit => undef, issuesperunit => 1, unitsperissue => 1, }); @@ -482,10 +482,16 @@ $subscription = { countissuesperunit => 1, }; $publisheddate = $subscription->{firstacquidate}; -# GetNextDate always return the same date if subscription is irregular +# GetNextDate always return undef if subscription is irregular $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-01-01'); -$publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-01-01'); +is($publisheddate, undef); + +# GetNextDate returns undef if one of two first parameters is undef +$publisheddate = GetNextDate($subscription, undef); +is($publisheddate, undef); +$publisheddate = GetNextDate(undef, $subscription->{firstacquidate}); +is($publisheddate, undef); +$publisheddate = GetNextDate(undef, undef); +is($publisheddate, undef); $dbh->rollback; -- 2.39.2