Bug 15149: Serial test prediction pattern does not consider end date
[koha.git] / serials / serials-edit.pl
index e28fd59..33e11ad 100755 (executable)
@@ -61,8 +61,7 @@ op can be :
 
 =cut
 
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI qw ( -utf8 );
 use Encode qw( decode is_utf8 );
 use C4::Auth;
@@ -73,7 +72,10 @@ use C4::Output;
 use C4::Context;
 use C4::Serials;
 use C4::Search qw/enabled_staff_search_views/;
+
 use Koha::DateUtils;
+use Koha::Items;
+use Koha::Serial::Items;
 
 use List::MoreUtils qw/uniq/;
 
@@ -112,6 +114,7 @@ unless ( @serialids ) {
     $string =~ s/,$//;
 
     print $query->redirect($string);
+    exit;
 }
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -163,7 +166,7 @@ foreach my $serialid (@serialids) {
         $processedserialid{$serialid} = 1;
     }
 }
-my $biblio = GetBiblioData( $serialdatalist[0]->{'biblionumber'} );
+my $biblio = Koha::Biblios->find( $serialdatalist[0]->{biblionumber} );
 
 my @newserialloop;
 my @subscriptionloop;
@@ -256,13 +259,9 @@ if ( $op and $op eq 'serialchangestatus' ) {
             my $previous = GetPreviousSerialid($subscriptionids[$i]);
             if ($previous) {
 
-                # Getting the itemnumber matching the serialid
-                my $query = "SELECT itemnumber FROM serialitems WHERE serialid=?";
-                my $sth = $dbh->prepare($query);
-                $sth->execute($previous);
-                my @row = $sth->fetchrow_array;
-                if ($row[0]) {
-                    my $itemnumber = $row[0];
+                my $serialitem = Koha::Serial::Items->search( {serialid => $previous} )->next;
+                my $itemnumber = $serialitem ? $serialitem->itemnumber : undef;
+                if ($itemnumber) {
 
                     # Getting the itemtype to set from the database
                     my $subscriptioninfos = GetSubscription($subscriptionids[$i]);
@@ -376,11 +375,8 @@ if ( $op and $op eq 'serialchangestatus' ) {
                         )
                       )
                     {
-                        $exists = GetItemnumberFromBarcode(
-                            $bib_record->subfield(
-                                $barcodetagfield, $barcodetagsubfield
-                            )
-                        );
+                        my $barcode = $bib_record->subfield( $barcodetagfield, $barcodetagsubfield );
+                        $exists = Koha::Items->find({barcode => $barcode});
                     }
 
                     #           push @errors,"barcode_not_unique" if($exists);
@@ -425,10 +421,11 @@ my $location = $serialdatalist[0]->{'location'};
 my $default_bib_view = get_default_view();
 
 $template->param(
+    subscriptionid  => $serialdatalist[0]->{subscriptionid},
     serialsadditems => $serialdatalist[0]->{'serialsadditems'},
     callnumber      => $serialdatalist[0]->{'callnumber'},
     internalnotes   => $serialdatalist[0]->{'internalnotes'},
-    bibliotitle     => $biblio->{'title'},
+    bibliotitle     => $biblio->title,
     biblionumber    => $serialdatalist[0]->{'biblionumber'},
     serialslist     => \@serialdatalist,
     default_bib_view => $default_bib_view,