Bug 12003: Do not calculate next pubdate for irregular subscriptions
authorJulian Maurice <julian.maurice@biblibre.com>
Fri, 28 Mar 2014 13:38:25 +0000 (14:38 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 18 Apr 2014 20:57:51 +0000 (20:57 +0000)
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 <bgkriegel@gmail.com>
Work as described following test plan.
No koha-qa errors

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
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 <gmc@esilibrary.com>
C4/Serials.pm
koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt
misc/cronjobs/serialsUpdate.pl
serials/showpredictionpattern.pl
t/db_dependent/Serials/GetNextDate.t

index 2540f16..c62d1ed 100644 (file)
@@ -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
index ed1dc39..ab39821 100644 (file)
@@ -244,10 +244,22 @@ $(document).ready(function() {
                  <td><a href="serials-collection.pl?subscriptionid=[% serial.subscriptionid %]">[% serial.subscriptionid %]</a></td>
 [% END %]
                 <td>
-                    <span title="[% serial.publisheddate %]">[% serial.publisheddate | $KohaDates %]</span>
+                    <span title="[% serial.publisheddate %]">
+                      [% IF serial.publisheddate %]
+                        [% serial.publisheddate | $KohaDates %]
+                      [% ELSE %]
+                        Unknown
+                      [% END %]
+                    </span>
                 </td>
                 <td>
-                    <span title="[% serial.planneddate %]">[% serial.planneddate | $KohaDates %]</span>
+                    <span title="[% serial.planneddate %]">
+                      [% IF serial.planneddate %]
+                        [% serial.planneddate | $KohaDates %]
+                      [% ELSE %]
+                        Unknown
+                      [% END %]
+                    </span>
                 </td>
                 <td>
                     [% serial.serialseq %]
index f02194e..b684e5e 100644 (file)
@@ -259,10 +259,18 @@ $(document).ready(function() {
                     [% serialslis.serialseq %]
                 </td>
                 <td>
-                    [% serialslis.planneddate %]
+                    [% IF serialslis.planneddate %]
+                      [% serialslis.planneddate %]
+                    [% ELSE %]
+                      Unknown
+                    [% END %]
                 </td>
                 <td>
-                    [% serialslis.publisheddate %]
+                    [% IF serialslis.publisheddate %]
+                      [% serialslis.publisheddate %]
+                    [% ELSE %]
+                      Unknown
+                    [% END %]
                 </td>
                 <td>
                     [% IF ( serialslis.status1 ) %]Expected[% END %]
index 813ef21..6ac5558 100755 (executable)
@@ -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
     }
index c654f55..82cf8af 100755 (executable)
@@ -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);
     }
 
index ed80f29..1572d0a 100644 (file)
@@ -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;