Bug 8454 - Holds to Pull : Show pull list on load. Otherwise, it looks like the pull...
[koha.git] / serials / serials-collection.pl
index a67db7a..4393546 100755 (executable)
@@ -34,6 +34,7 @@ use List::MoreUtils qw/uniq/;
 
 my $query = new CGI;
 my $op = $query->param('op') || q{};
+my $nbissues=$query->param('nbissues');
 my $dbh = C4::Context->dbh;
 
 my ($template, $loggedinuser, $cookie);
@@ -42,7 +43,7 @@ my ($template, $loggedinuser, $cookie);
                             query => $query,
                             type => "intranet",
                             authnotrequired => 0,
-                            flagsrequired => {serials => 'receive_serials'},
+                            flagsrequired => {serials => '*'},
                             debug => 1,
                             });
 my $biblionumber = $query->param('biblionumber');
@@ -55,19 +56,20 @@ my $subscriptions;
 
 if($op eq 'gennext' && @subscriptionid){
     my $subscriptionid = $subscriptionid[0];
-    my $subscription = GetSubscription($subscriptionid);
-
-       my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, planneddate
+    my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, planneddate
                                                        FROM serial WHERE status = 1 AND subscriptionid = ?");
+    my $status = defined( $nbissues ) ? 2 : 3;
+    $nbissues ||= 1;
+    for ( my $i = 0; $i < $nbissues; $i++ ){
        $sth->execute($subscriptionid);
-
        # modify actual expected issue, to generate the next
        if ( my $issue = $sth->fetchrow_hashref ) {
                ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
                 $issue->{planneddate}, $issue->{publisheddate},
-                3, "" );
+                $status, "" );
        }else{
-               my $expected = GetNextExpected($subscriptionid);
+            my $subscription = GetSubscription($subscriptionid);
+            my $expected = GetNextExpected($subscriptionid);
            my (
                 $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
              $newinnerloop1, $newinnerloop2, $newinnerloop3
@@ -82,14 +84,16 @@ if($op eq 'gennext' && @subscriptionid){
             ## Updating the subscription seq status
             my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
                         WHERE  subscriptionid = ?";
-            $sth = $dbh->prepare($squery);
-            $sth->execute(
+            my $seqsth = $dbh->prepare($squery);
+            $seqsth->execute(
                 $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
                 $newinnerloop2, $newinnerloop3, $subscriptionid
                 );
 
        }
-
+       last if $nbissues == 1;
+       last if HasSubscriptionExpired($subscriptionid) > 0;
+    }
     print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
 }
 
@@ -158,10 +162,13 @@ $template->param(
           bibliotitle => $title,
           suggestion => C4::Context->preference("suggestion"),
           virtualshelves => C4::Context->preference("virtualshelves"),
+          routing => C4::Context->preference("RoutingSerials"),
           subscr=>$query->param('subscriptionid'),
           subscriptioncount => $subscriptioncount,
-    location          => $locationlib,
-    callnumber        => $callnumber,
+          location            => $locationlib,
+          callnumber          => $callnumber,
+          uc(C4::Context->preference("marcflavour")) => 1,
+          serialsadditems   => $subscriptiondescs->[0]{'serialsadditems'},
           );
 
 output_html_with_http_headers $query, $cookie, $template->output;