Bug 28306: Fix t/db_dependent/Koha/Objects.t
[koha-ffzg.git] / reserve / request.pl
index bf13c3d..6ab8ba7 100755 (executable)
@@ -29,23 +29,21 @@ script to place reserves/requests
 use Modern::Perl;
 
 use CGI qw ( -utf8 );
-use List::MoreUtils qw/uniq/;
-use Date::Calc qw/Date_to_Days/;
-use C4::Output;
-use C4::Auth;
-use C4::Reserves;
-use C4::Biblio;
-use C4::Items;
-use C4::Koha;
-use C4::Serials;
-use C4::Circulation;
-use Koha::DateUtils;
+use List::MoreUtils qw( uniq );
+use Date::Calc qw( Date_to_Days );
+use C4::Output qw( output_html_with_http_headers );
+use C4::Auth qw( get_template_and_user );
+use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority ToggleSuspend CanBookBeReserved GetMaxPatronHoldsForRecord ItemsAnyAvailableAndNotRestricted CanItemBeReserved IsAvailableForItemLevelRequest );
+use C4::Items qw( get_hostitemnumbers_of );
+use C4::Koha qw( getitemtypeimagelocation );
+use C4::Serials qw( CountSubscriptionFromBiblionumber );
+use C4::Circulation qw( GetTransfers _GetCircControlBranch GetBranchItemRule );
+use Koha::DateUtils qw( dt_from_string output_pref );
 use C4::Utils::DataTables::Members;
-use C4::Members;
-use C4::Search;                # enabled_staff_search_views
+use C4::Search qw( enabled_staff_search_views );
 
 use Koha::Biblios;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Checkouts;
 use Koha::Holds;
 use Koha::CirculationRules;
@@ -309,6 +307,11 @@ foreach my $biblionumber (@biblionumbers) {
     my %biblioloopiter = ();
 
     my $biblio = Koha::Biblios->find( $biblionumber );
+    unless ($biblio) {
+        $biblioloopiter{noitems} = 1;
+        $template->param('nobiblio' => 1);
+        last;
+    }
 
     my $force_hold_level;
     if ( $patron ) {
@@ -400,12 +403,12 @@ foreach my $biblionumber (@biblionumbers) {
 
     unless ( $items->count ) {
         # FIXME Then why do we continue?
-        $template->param('noitems' => 1);
+        $template->param('noitems' => 1) unless ( $multi_hold );
         $biblioloopiter{noitems} = 1;
     }
 
-    ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
-    ## when by definition all of the itemnumber have the same biblioitemnumber
+    ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers
+    ## this is important when we have analytic items which may be on another record
     my ( $iteminfos_of );
     while ( my $item = $items->next ) {
         $item = $item->unblessed;
@@ -415,7 +418,6 @@ foreach my $biblionumber (@biblionumbers) {
         $iteminfos_of->{$itemnumber} = $item;
     }
 
-    ## Should be same as biblionumber
     my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
 
     my $biblioiteminfos_of = {
@@ -424,7 +426,7 @@ foreach my $biblionumber (@biblionumbers) {
             ( $biblioitem->{biblioitemnumber} => $biblioitem )
           } @{ Koha::Biblioitems->search(
                 { biblioitemnumber => { -in => \@biblioitemnumbers } },
-                { select => ['biblioitemnumber', 'publicationyear', 'itemtype']}
+                { select => ['biblionumber', 'biblioitemnumber', 'publicationyear', 'itemtype']}
             )->unblessed
           }
     };
@@ -462,8 +464,7 @@ foreach my $biblionumber (@biblionumbers) {
         # it's complicated logic to analyse.
         # (before this loop was inside that sub loop so it was O(n^2) )
         my $items_any_available;
-
-        $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblioitemnumber, patron => $patron })
+        $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblioitem->{biblionumber}, patron => $patron })
             if $patron;
 
         foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
@@ -755,8 +756,8 @@ foreach my $biblionumber (@biblionumbers) {
 }
 
 $template->param( biblioloop => \@biblioloop );
-$template->param( biblionumbers => $biblionumbers );
 $template->param( no_reserves_allowed => $no_reserves_allowed );
+$template->param( biblionumbers => join('/', @biblionumbers) );
 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
 $template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
 $template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber));