4 #written 2/1/00 by chris@katipo.oc.nz
5 # Copyright 2000-2002 Katipo Communications
6 # Parts Copyright 2011 Catalyst IT
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 script to place reserves/requests
32 use List::MoreUtils qw( uniq );
33 use Date::Calc qw( Date_to_Days );
34 use C4::Output qw( output_html_with_http_headers );
35 use C4::Auth qw( get_template_and_user );
36 use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority ToggleSuspend CanBookBeReserved GetMaxPatronHoldsForRecord ItemsAnyAvailableAndNotRestricted CanItemBeReserved IsAvailableForItemLevelRequest );
37 use C4::Items qw( get_hostitemnumbers_of );
38 use C4::Koha qw( getitemtypeimagelocation );
39 use C4::Serials qw( CountSubscriptionFromBiblionumber );
40 use C4::Circulation qw( GetTransfers _GetCircControlBranch GetBranchItemRule );
41 use Koha::DateUtils qw( dt_from_string output_pref );
42 use C4::Utils::DataTables::Members;
43 use C4::Search qw( enabled_staff_search_views );
46 use Koha::DateUtils qw( dt_from_string output_pref );
49 use Koha::CirculationRules;
55 use Koha::BackgroundJob::BatchCancelHold;
57 my $dbh = C4::Context->dbh;
59 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
61 template_name => "reserve/request.tt",
64 flagsrequired => { reserveforothers => 'place_holds' },
68 my $showallitems = $input->param('showallitems');
69 my $pickup = $input->param('pickup');
71 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
73 # Select borrowers infos
74 my $findborrower = $input->param('findborrower');
75 $findborrower = '' unless defined $findborrower;
76 $findborrower =~ s|,| |g;
77 my $findclub = $input->param('findclub');
78 $findclub = '' unless defined $findclub && !$findborrower;
79 my $borrowernumber_hold = $input->param('borrowernumber') || '';
80 my $club_hold = $input->param('club')||'';
85 my $exceeded_maxreserves;
86 my $exceeded_holds_per_record;
88 my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
89 my $action = $input->param('action');
92 if ( $action eq 'move' ) {
93 my $where = $input->param('where');
94 my $reserve_id = $input->param('reserve_id');
95 my $prev_priority = $input->param('prev_priority');
96 my $next_priority = $input->param('next_priority');
97 my $first_priority = $input->param('first_priority');
98 my $last_priority = $input->param('last_priority');
99 my $hold_itemnumber = $input->param('itemnumber');
100 if ( $prev_priority == 0 && $next_priority == 1 ) {
101 C4::Reserves::RevertWaitingStatus( { itemnumber => $hold_itemnumber } );
105 $where, $reserve_id, $prev_priority,
106 $next_priority, $first_priority, $last_priority
110 elsif ( $action eq 'cancel' ) {
111 my $reserve_id = $input->param('reserve_id');
112 my $cancellation_reason = $input->param("cancellation-reason");
113 my $hold = Koha::Holds->find($reserve_id);
114 $hold->cancel( { cancellation_reason => $cancellation_reason } ) if $hold;
116 elsif ( $action eq 'setLowestPriority' ) {
117 my $reserve_id = $input->param('reserve_id');
118 ToggleLowestPriority($reserve_id);
120 elsif ( $action eq 'toggleSuspend' ) {
121 my $reserve_id = $input->param('reserve_id');
122 my $suspend_until = $input->param('suspend_until');
123 ToggleSuspend( $reserve_id, $suspend_until );
125 elsif ( $action eq 'cancelBulk' ) {
126 my $cancellation_reason = $input->param("cancellation-reason");
127 my @hold_ids = split ',', $input->param("ids");
129 reason => $cancellation_reason,
130 hold_ids => \@hold_ids,
132 my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params);
141 my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
143 $borrowernumber_hold = $patron->borrowernumber;
145 my $dt_params = { iDisplayLength => -1 };
146 my $results = C4::Utils::DataTables::Members::search(
148 searchmember => $findborrower,
149 dt_params => $dt_params,
152 my $borrowers = $results->{patrons};
153 if ( scalar @$borrowers == 1 ) {
154 $borrowernumber_hold = $borrowers->[0]->{borrowernumber};
155 } elsif ( @$borrowers ) {
156 $template->param( borrowers => $borrowers );
158 $messageborrower = "'$findborrower'";
164 my $club = Koha::Clubs->find( { name => $findclub } );
166 $club_hold = $club->id;
168 my @clubs = Koha::Clubs->search( [
169 { name => { like => '%'.$findclub.'%' } },
170 { description => { like => '%'.$findclub.'%' } }
172 if( scalar @clubs == 1 ) {
173 $club_hold = $clubs[0]->id;
175 $template->param( clubs => \@clubs );
177 $messageclub = "'$findclub'";
182 my @biblionumbers = ();
183 my $biblionumber = $input->param('biblionumber');
184 my $biblionumbers = $input->param('biblionumbers');
185 if ( $biblionumbers ) {
186 @biblionumbers = split '/', $biblionumbers;
188 push @biblionumbers, $input->multi_param('biblionumber');
191 my $multi_hold = @biblionumbers > 1;
193 multi_hold => $multi_hold,
196 # If we have the borrowernumber because we've performed an action, then we
197 # don't want to try to place another reserve.
198 if ($borrowernumber_hold && !$action) {
199 my $patron = Koha::Patrons->find( $borrowernumber_hold );
202 # we check the reserves of the user, and if they can reserve a document
203 # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
205 my $reserves_count = $patron->holds->count;
207 my $new_reserves_count = scalar( @biblionumbers );
209 my $maxreserves = C4::Context->preference('maxreserves');
210 $template->param( maxreserves => $maxreserves );
213 && ( $reserves_count + $new_reserves_count > $maxreserves ) )
215 my $new_reserves_allowed =
216 $maxreserves - $reserves_count > 0
217 ? $maxreserves - $reserves_count
220 $exceeded_maxreserves = 1;
222 new_reserves_allowed => $new_reserves_allowed,
223 new_reserves_count => $new_reserves_count,
224 reserves_count => $reserves_count,
225 maxreserves => $maxreserves,
229 # check if the borrower make the reserv in a different branch
230 if ( $patron->branchcode ne C4::Context->userenv->{'branch'} ) {
234 my $amount_outstanding = $patron->account->balance;
237 diffbranch => $diffbranch,
238 messages => $messages,
239 warnings => $warnings,
240 amount_outstanding => $amount_outstanding,
244 if ($club_hold && !$borrowernumber_hold && !$action) {
245 my $club = Koha::Clubs->find($club_hold);
247 my $enrollments = $club->club_enrollments;
249 my $maxreserves = C4::Context->preference('maxreserves');
250 my $new_reserves_count = scalar( @biblionumbers );
254 while(my $enrollment = $enrollments->next) {
255 next if $enrollment->is_canceled;
256 my $member = { patron => $enrollment->patron };
257 my $reserves_count = $enrollment->patron->holds->count;
259 && ( $reserves_count + $new_reserves_count > $maxreserves ) )
261 $member->{new_reserves_allowed} = $maxreserves - $reserves_count > 0
262 ? $maxreserves - $reserves_count
264 $member->{exceeded_maxreserves} = 1;
266 $member->{amount_outstanding} = $enrollment->patron->account->balance;
267 if ( $enrollment->patron->branchcode ne C4::Context->userenv->{'branch'} ) {
268 $member->{diffbranch} = 1;
271 push @members, $member;
276 members => \@members,
277 maxreserves => $maxreserves,
278 new_reserves_count => $new_reserves_count
282 unless ( $club_hold or $borrowernumber_hold ) {
283 $template->param( clubcount => Koha::Clubs->search->count );
287 messageborrower => $messageborrower,
288 messageclub => $messageclub
291 # FIXME launch another time GetMember perhaps until (Joubu: Why?)
292 my $patron = Koha::Patrons->find( $borrowernumber_hold );
294 if ( $patron && $multi_hold ) {
295 my @multi_pickup_locations =
296 Koha::Biblios->search( { biblionumber => \@biblionumbers } )
297 ->pickup_locations( { patron => $patron } );
298 $template->param( multi_pickup_locations => \@multi_pickup_locations );
301 my $logged_in_patron = Koha::Patrons->find( $borrowernumber );
305 $wants_check = $patron->wants_check_for_previous_checkout;
307 my $itemdata_enumchron = 0;
308 my $itemdata_ccode = 0;
310 my $no_reserves_allowed = 0;
311 foreach my $biblionumber (@biblionumbers) {
312 next unless $biblionumber =~ m|^\d+$|;
314 my %biblioloopiter = ();
316 my $biblio = Koha::Biblios->find( $biblionumber );
318 $biblioloopiter{noitems} = 1;
319 $template->param('nobiblio' => 1);
323 my $force_hold_level;
325 { # CanBookBeReserved
326 my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
327 if ( $canReserve->{status} eq 'OK' ) {
329 #All is OK and we can continue
331 elsif ( $canReserve->{status} eq 'noReservesAllowed' || $canReserve->{status} eq 'notReservable' ) {
332 $no_reserves_allowed = 1;
334 elsif ( $canReserve->{status} eq 'tooManyReserves' ) {
335 $exceeded_maxreserves = 1;
336 $template->param( maxreserves => $canReserve->{limit} );
338 elsif ( $canReserve->{status} eq 'tooManyHoldsForThisRecord' ) {
339 $exceeded_holds_per_record = 1;
340 $biblioloopiter{ $canReserve->{status} } = 1;
342 elsif ( $canReserve->{status} eq 'ageRestricted' ) {
343 $template->param( $canReserve->{status} => 1 );
344 $biblioloopiter{ $canReserve->{status} } = 1;
346 elsif ( $canReserve->{status} eq 'alreadypossession' ) {
347 $template->param( $canReserve->{status} => 1);
348 $biblioloopiter{ $canReserve->{status} } = 1;
351 $biblioloopiter{ $canReserve->{status} } = 1;
355 # For multiple holds per record, if a patron has previously placed a hold,
356 # the patron can only place more holds of the same type. That is, if the
357 # patron placed a record level hold, all the holds the patron places must
358 # be record level. If the patron placed an item level hold, all holds
359 # the patron places must be item level
360 my $holds = Koha::Holds->search(
362 borrowernumber => $patron->borrowernumber,
363 biblionumber => $biblionumber,
367 $force_hold_level = $holds->forced_hold_level();
368 $biblioloopiter{force_hold_level} = $force_hold_level;
369 $template->param( force_hold_level => $force_hold_level );
371 # For a librarian to be able to place multiple record holds for a patron for a record,
372 # we must find out what the maximum number of holds they can place for the patron is
373 my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber );
374 my $remaining_holds_for_record = $max_holds_for_record - $holds->count();
375 $biblioloopiter{remaining_holds_for_record} = $max_holds_for_record;
376 $template->param( max_holds_for_record => $max_holds_for_record );
377 $template->param( remaining_holds_for_record => $remaining_holds_for_record );
381 my $count = Koha::Holds->search( { biblionumber => $biblionumber } )->count();
382 my $totalcount = $count;
384 # adding a fixed value for priority options
385 my $fixedRank = $count+1;
387 my %itemnumbers_of_biblioitem;
389 my @hostitems = get_hostitemnumbers_of($biblionumber);
392 $template->param('hostitemsflag' => 1);
393 push(@itemnumbers, @hostitems);
396 my $items = Koha::Items->search({ -or => { biblionumber => $biblionumber, itemnumber => { in => \@itemnumbers } } });
398 unless ( $items->count ) {
399 # FIXME Then why do we continue?
400 $template->param('noitems' => 1) unless ( $multi_hold );
401 $biblioloopiter{noitems} = 1;
404 ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers
405 ## this is important when we have analytic items which may be on another record
406 my ( $iteminfos_of );
407 while ( my $item = $items->next ) {
408 $item = $item->unblessed;
409 my $biblioitemnumber = $item->{biblioitemnumber};
410 my $itemnumber = $item->{itemnumber};
411 push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
412 $iteminfos_of->{$itemnumber} = $item;
415 my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
417 my $biblioiteminfos_of = {
420 ( $biblioitem->{biblioitemnumber} => $biblioitem )
421 } @{ Koha::Biblioitems->search(
422 { biblioitemnumber => { -in => \@biblioitemnumbers } },
423 { select => ['biblionumber', 'biblioitemnumber', 'publicationyear', 'itemtype']}
430 my @available_itemtypes;
431 foreach my $biblioitemnumber (@biblioitemnumbers) {
432 my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
433 my $num_available = 0;
434 my $num_override = 0;
436 my $num_alreadyheld = 0;
438 $biblioitem->{force_hold_level} = $force_hold_level;
440 if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
441 $biblioitem->{hostitemsflag} = 1;
444 $biblioloopiter{description} = $biblioitem->{description};
445 $biblioloopiter{itypename} = $biblioitem->{description};
446 if ( $biblioitem->{itemtype} ) {
448 $biblioitem->{description} =
449 $itemtypes->{ $biblioitem->{itemtype} }{description};
451 $biblioloopiter{imageurl} =
452 getitemtypeimagelocation( 'intranet',
453 $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
456 # iterating through all items first to check if any of them available
457 # to pass this value further inside down to IsAvailableForItemLevelRequest to
458 # it's complicated logic to analyse.
459 # (before this loop was inside that sub loop so it was O(n^2) )
460 my $items_any_available;
461 $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblioitem->{biblionumber}, patron => $patron })
464 foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } ) {
465 my $item = $iteminfos_of->{$itemnumber};
468 $do_check = $patron->do_check_for_previous_checkout($item) if $wants_check;
469 if ( $do_check && $wants_check ) {
470 $item->{checked_previously} = $do_check;
472 $biblioloopiter{checked_previously} = $do_check;
474 $template->param( checked_previously => $do_check );
478 $item->{force_hold_level} = $force_hold_level;
480 unless (C4::Context->preference('item-level_itypes')) {
481 $item->{itype} = $biblioitem->{itemtype};
484 $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
485 $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
486 $item->{homebranch} = $item->{homebranch};
488 # if the holdingbranch is different than the homebranch, we show the
489 # holdingbranch of the document too
490 if ( $item->{homebranch} ne $item->{holdingbranch} ) {
491 $item->{holdingbranch} = $item->{holdingbranch};
494 if($item->{biblionumber} ne $biblionumber){
495 $item->{hostitemsflag} = 1;
496 $item->{hosttitle} = Koha::Biblios->find( $item->{biblionumber} )->title;
499 # if the item is currently on loan, we display its return date and
500 # change the background color
501 my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
503 $item->{date_due} = $issue->date_due;
504 $item->{backgroundcolor} = 'onloan';
508 my $item_object = Koha::Items->find( $itemnumber );
509 my $holds = $item_object->current_holds;
510 if ( my $first_hold = $holds->next ) {
511 my $p = Koha::Patrons->find( $first_hold->borrowernumber );
513 $item->{backgroundcolor} = 'reserved';
514 $item->{reservedate} = output_pref({ dt => dt_from_string( $first_hold->reservedate ), dateonly => 1 }); # FIXME Should be formatted in the template
515 $item->{ReservedFor} = $p;
516 $item->{ExpectedAtLibrary} = $first_hold->branchcode;
517 $item->{waitingdate} = $first_hold->waitingdate;
520 # Management of the notforloan document
521 if ( $item->{notforloan} ) {
522 $item->{backgroundcolor} = 'other';
525 # Management of lost or long overdue items
526 if ( $item->{itemlost} ) {
527 $item->{backgroundcolor} = 'other';
528 if ($logged_in_patron->category->hidelostitems && !$showallitems) {
534 # Check the transit status
535 my ( $transfertwhen, $transfertfrom, $transfertto ) =
536 GetTransfers($itemnumber);
538 if ( defined $transfertwhen && $transfertwhen ne '' ) {
539 $item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
540 $item->{transfertfrom} = $transfertfrom;
541 $item->{transfertto} = $transfertto;
542 $item->{nocancel} = 1;
545 # If there is no loan, return and transfer, we show a checkbox.
546 $item->{notforloan} ||= 0;
548 # if independent branches is on we need to check if the person can reserve
549 # for branches they arent logged in to
550 if ( C4::Context->preference("IndependentBranches") ) {
551 if (! C4::Context->preference("canreservefromotherbranches")){
552 # can't reserve items so need to check if item homebranch and userenv branch match if not we can't reserve
553 my $userenv = C4::Context->userenv;
554 unless ( C4::Context->IsSuperLibrarian ) {
555 $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
561 my $patron_unblessed = $patron->unblessed;
562 my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
564 my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
566 $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
568 my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status};
569 $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
571 $item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
574 !$item->{cantreserve}
575 && !$exceeded_maxreserves
576 && $can_item_be_reserved eq 'OK'
577 # items_any_available defined outside of the current loop,
578 # so we avoiding loop inside IsAvailableForItemLevelRequest:
579 && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
582 # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
583 my @pickup_locations = $item_object->pickup_locations({ patron => $patron })->as_list;
584 $item->{pickup_locations_count} = scalar @pickup_locations;
586 if ( @pickup_locations ) {
588 $item->{available} = 1;
590 my $default_pickup_location;
592 # Default to logged-in, if valid
593 if ( C4::Context->userenv->{branch} ) {
594 ($default_pickup_location) = grep { $_->branchcode eq C4::Context->userenv->{branch} } @pickup_locations;
597 $item->{default_pickup_location} = $default_pickup_location;
600 $item->{available} = 0;
601 $item->{not_holdable} = "no_valid_pickup_location";
604 push( @available_itemtypes, $item->{itype} );
606 elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
607 # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
608 # with the exception of itemAlreadyOnHold because, you know, the item is already on hold
609 if ( $can_item_be_reserved ne 'itemAlreadyOnHold' ) {
610 # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
611 my $pickup_locations = $item_object->pickup_locations({ patron => $patron });
612 $item->{pickup_locations_count} = $pickup_locations->count;
613 if ( $item->{pickup_locations_count} > 0 ) {
614 $item->{override} = 1;
616 # pass the holding branch for use as default
617 my $default_pickup_location = $pickup_locations->search({ branchcode => $item->{holdingbranch} })->next;
618 $item->{default_pickup_location} = $default_pickup_location;
621 $item->{available} = 0;
622 $item->{not_holdable} = "no_valid_pickup_location";
624 } else { $num_alreadyheld++ }
626 push( @available_itemtypes, $item->{itype} );
629 # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
631 # Show serial enumeration when needed
632 if ($item->{enumchron}) {
633 $itemdata_enumchron = 1;
635 # Show collection when needed
636 if ($item->{ccode}) {
641 push @{ $biblioitem->{itemloop} }, $item;
644 # While we can't override an alreay held item, we should be able to override the others
645 # Unless all items are already held
646 if ( $num_override > 0 && ($num_override + $num_alreadyheld) == scalar( @{ $biblioitem->{itemloop} } ) ) {
647 # That is, if all items require an override
648 $template->param( override_required => 1 );
649 } elsif ( $num_available == 0 ) {
650 $template->param( none_available => 1 );
651 $biblioloopiter{warn} = 1;
652 $biblioloopiter{none_avail} = 1;
654 $template->param( hiddencount => $hiddencount);
656 push @bibitemloop, $biblioitem;
659 @available_itemtypes = uniq( @available_itemtypes );
660 $template->param( available_itemtypes => \@available_itemtypes );
662 # existingreserves building
664 my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } );
667 my $a_found = $a->found() || '';
668 my $b_found = $a->found() || '';
669 $a_found cmp $b_found;
674 if ( $res->is_found() ) {
675 $reserve{'holdingbranch'} = $res->item()->holdingbranch();
676 $reserve{'biblionumber'} = $res->item()->biblionumber();
677 $reserve{'barcodenumber'} = $res->item()->barcode();
678 $reserve{'wbrcode'} = $res->branchcode();
679 $reserve{'itemnumber'} = $res->itemnumber();
680 $reserve{'wbrname'} = $res->branch()->branchname();
681 $reserve{'atdestination'} = $res->is_at_destination();
682 $reserve{'desk_name'} = ( $res->desk() ) ? $res->desk()->desk_name() : '' ;
683 $reserve{'found'} = $res->is_found();
684 $reserve{'inprocessing'} = $res->is_in_processing();
685 $reserve{'intransit'} = $res->is_in_transit();
687 elsif ( $res->priority() > 0 ) {
688 if ( my $item = $res->item() ) {
689 $reserve{'itemnumber'} = $item->id();
690 $reserve{'barcodenumber'} = $item->barcode();
691 $reserve{'item_level_hold'} = 1;
695 $reserve{'expirationdate'} = $res->expirationdate;
696 $reserve{'date'} = $res->reservedate;
697 $reserve{'borrowernumber'} = $res->borrowernumber();
698 $reserve{'biblionumber'} = $res->biblionumber();
699 $reserve{'patron'} = $res->borrower;
700 $reserve{'notes'} = $res->reservenotes();
701 $reserve{'waiting_date'} = $res->waitingdate();
702 $reserve{'ccode'} = $res->item() ? $res->item()->ccode() : undef;
703 $reserve{'barcode'} = $res->item() ? $res->item()->barcode() : undef;
704 $reserve{'priority'} = $res->priority();
705 $reserve{'lowestPriority'} = $res->lowestPriority();
706 $reserve{'suspend'} = $res->suspend();
707 $reserve{'suspend_until'} = $res->suspend_until();
708 $reserve{'reserve_id'} = $res->reserve_id();
709 $reserve{itemtype} = $res->itemtype();
710 $reserve{branchcode} = $res->branchcode();
711 $reserve{non_priority} = $res->non_priority();
712 $reserve{object} = $res;
714 push( @reserveloop, \%reserve );
717 # get the time for the form name...
722 fixedRank => $fixedRank,
727 bibitemloop => \@bibitemloop,
728 itemdata_enumchron => $itemdata_enumchron,
729 itemdata_ccode => $itemdata_ccode,
731 biblionumber => $biblionumber,
732 findborrower => $findborrower,
735 C4::Search::enabled_staff_search_views,
738 $biblioloopiter{biblionumber} = $biblionumber;
739 $biblioloopiter{title} = $biblio->title;
740 $biblioloopiter{rank} = $fixedRank;
741 $biblioloopiter{reserveloop} = \@reserveloop;
744 $template->param( reserveloop => \@reserveloop );
748 # Add the valid pickup locations
749 my @pickup_locations = $biblio->pickup_locations({ patron => $patron });
750 $biblioloopiter{pickup_locations} = \@pickup_locations;
751 $biblioloopiter{pickup_locations_codes} = [ map { $_->branchcode } @pickup_locations ];
754 push @biblioloop, \%biblioloopiter;
757 $template->param( biblioloop => \@biblioloop );
758 $template->param( no_reserves_allowed => $no_reserves_allowed );
759 $template->param( biblionumbers => join('/', @biblionumbers) );
760 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
761 $template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
762 $template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber));
764 # pass the userenv branch if no pickup location selected
765 $template->param( pickup => $pickup || C4::Context->userenv->{branch} );
767 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
768 $template->param( reserve_in_future => 1 );
772 SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
773 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
777 output_html_with_http_headers $input, $cookie, $template->output;
779 sub sort_borrowerlist {
780 my $borrowerslist = shift;
783 uc( $a->{surname} . $a->{firstname} ) cmp
784 uc( $b->{surname} . $b->{firstname} )