This patch change the operations, it add a new expected if no one expected 
exists, else it create new excepted, and set the others as "late"
---
 serials/serials-collection.pl |   50 ++++++++++++++++++++++++----------------
 1 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl
index 93aa00b..baef9b9 100755
--- a/serials/serials-collection.pl
+++ b/serials/serials-collection.pl
@@ -54,28 +54,38 @@ if($op eq "gennext" && @subscriptionid){
     my $subscriptionid = @subscriptionid[0];
     my $subscription = GetSubscription($subscriptionid);
 
-    my $expected = GetNextExpected($subscriptionid);
-    
-    my (
-            $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
-            $newinnerloop1, $newinnerloop2, $newinnerloop3
-        ) = GetNextSeq($subscription);
-
-    ## We generate the next publication date    
-    my $nextpublisheddate = GetNextDate( 
$expected->{planneddate}->output('iso'), $subscription );
-
-    ## Creating the new issue
-    NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
-            1, $nextpublisheddate, $nextpublisheddate );
-            
-    ## Updating the subscription seq status
-    my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, 
lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
-                WHERE  subscriptionid = ?";
-    $sth = $dbh->prepare($squery);
-    $sth->execute(
-        $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
-        $newinnerloop2, $newinnerloop3, $subscriptionid
-        );
+       my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, 
planneddate 
+                                                       FROM serial WHERE 
status = 1 AND subscriptionid = ?");
+       $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, "Automatically set to late" );
+       }else{
+               my $expected = GetNextExpected($subscriptionid);
+           my (
+                $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
+             $newinnerloop1, $newinnerloop2, $newinnerloop3
+            ) = GetNextSeq($subscription);
+       
+            ## We generate the next publication date    
+            my $nextpublisheddate = GetNextDate( 
$expected->{planneddate}->output('iso'), $subscription );
+            ## Creating the new issue
+            NewIssue( $newserialseq, $subscriptionid, 
$subscription->{'biblionumber'},
+                    1, $nextpublisheddate, $nextpublisheddate );
+                    
+            ## Updating the subscription seq status
+            my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, 
lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
+                        WHERE  subscriptionid = ?";
+            $sth = $dbh->prepare($squery);
+            $sth->execute(
+                $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
+                $newinnerloop2, $newinnerloop3, $subscriptionid
+                );
+
+       }
 
     print 
$query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
 }
-- 
1.6.0.4

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches

Reply via email to