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( ',', scalar $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(
170 { name => { like => '%' . $findclub . '%' } },
171 { description => { like => '%' . $findclub . '%' } }
173 )->filter_out_empty->as_list;
175 if( scalar @clubs == 1 ) {
176 $club_hold = $clubs[0]->id;
178 $template->param( clubs => \@clubs );
180 $messageclub = "'$findclub'";
185 my @biblionumbers = ();
186 my $biblionumber = $input->param('biblionumber');
187 my $biblionumbers = $input->param('biblionumbers');
188 if ( $biblionumbers ) {
189 @biblionumbers = split '/', $biblionumbers;
191 push @biblionumbers, $input->multi_param('biblionumber');
194 my $multi_hold = @biblionumbers > 1;
196 multi_hold => $multi_hold,
199 # If we are coming from the search result and only 1 is selected
200 $biblionumber ||= $biblionumbers[0] unless $multi_hold;
202 # If we have the borrowernumber because we've performed an action, then we
203 # don't want to try to place another reserve.
204 if ($borrowernumber_hold && !$action) {
205 my $patron = Koha::Patrons->find( $borrowernumber_hold );
208 # we check the reserves of the user, and if they can reserve a document
209 # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
211 my $reserves_count = $patron->holds->count;
213 my $new_reserves_count = scalar( @biblionumbers );
215 my $maxreserves = C4::Context->preference('maxreserves');
216 $template->param( maxreserves => $maxreserves );
219 && ( $reserves_count + $new_reserves_count > $maxreserves ) )
221 my $new_reserves_allowed =
222 $maxreserves - $reserves_count > 0
223 ? $maxreserves - $reserves_count
226 $exceeded_maxreserves = 1;
228 new_reserves_allowed => $new_reserves_allowed,
229 new_reserves_count => $new_reserves_count,
230 reserves_count => $reserves_count,
231 maxreserves => $maxreserves,
235 # check if the borrower make the reserv in a different branch
236 if ( $patron->branchcode ne C4::Context->userenv->{'branch'} ) {
240 my $amount_outstanding = $patron->account->balance;
243 diffbranch => $diffbranch,
244 messages => $messages,
245 warnings => $warnings,
246 amount_outstanding => $amount_outstanding,
250 if ($club_hold && !$borrowernumber_hold && !$action) {
251 my $club = Koha::Clubs->find($club_hold);
253 my $enrollments = $club->club_enrollments;
255 my $maxreserves = C4::Context->preference('maxreserves');
256 my $new_reserves_count = scalar( @biblionumbers );
260 while(my $enrollment = $enrollments->next) {
261 next if $enrollment->is_canceled;
262 my $member = { patron => $enrollment->patron };
263 my $reserves_count = $enrollment->patron->holds->count;
265 && ( $reserves_count + $new_reserves_count > $maxreserves ) )
267 $member->{new_reserves_allowed} = $maxreserves - $reserves_count > 0
268 ? $maxreserves - $reserves_count
270 $member->{exceeded_maxreserves} = 1;
272 $member->{amount_outstanding} = $enrollment->patron->account->balance;
273 if ( $enrollment->patron->branchcode ne C4::Context->userenv->{'branch'} ) {
274 $member->{diffbranch} = 1;
277 push @members, $member;
282 members => \@members,
283 maxreserves => $maxreserves,
284 new_reserves_count => $new_reserves_count
288 unless ( $club_hold or $borrowernumber_hold ) {
289 $template->param( clubcount => Koha::Clubs->search->count );
293 messageborrower => $messageborrower,
294 messageclub => $messageclub
297 # Load the hold list if
298 # - we are searching for a patron or club and found one
299 # - we are not searching for anything
300 if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold )
301 || ( !$findborrower && !$findclub ) )
303 # FIXME launch another time GetMember perhaps until (Joubu: Why?)
304 my $patron = Koha::Patrons->find( $borrowernumber_hold );
306 if ( $patron && $multi_hold ) {
307 my @multi_pickup_locations =
308 Koha::Biblios->search( { biblionumber => \@biblionumbers } )
309 ->pickup_locations( { patron => $patron } )->as_list;
310 $template->param( multi_pickup_locations => \@multi_pickup_locations );
313 my $logged_in_patron = Koha::Patrons->find( $borrowernumber );
317 $wants_check = $patron->wants_check_for_previous_checkout;
319 my $itemdata_enumchron = 0;
320 my $itemdata_ccode = 0;
322 my $no_reserves_allowed = 0;
323 my $num_bibs_available = 0;
324 foreach my $biblionumber (@biblionumbers) {
325 next unless $biblionumber =~ m|^\d+$|;
327 my %biblioloopiter = ();
329 my $biblio = Koha::Biblios->find( $biblionumber );
331 $biblioloopiter{noitems} = 1;
332 $template->param('nobiblio' => 1);
336 my $force_hold_level;
338 { # CanBookBeReserved
339 my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
340 if ( $canReserve->{status} eq 'OK' ) {
342 #All is OK and we can continue
344 elsif ( $canReserve->{status} eq 'noReservesAllowed' || $canReserve->{status} eq 'notReservable' ) {
345 $no_reserves_allowed = 1;
347 elsif ( $canReserve->{status} eq 'tooManyReserves' ) {
348 $exceeded_maxreserves = 1;
349 $template->param( maxreserves => $canReserve->{limit} );
351 elsif ( $canReserve->{status} eq 'tooManyHoldsForThisRecord' ) {
352 $exceeded_holds_per_record = 1;
353 $biblioloopiter{ $canReserve->{status} } = 1;
355 elsif ( $canReserve->{status} eq 'ageRestricted' ) {
356 $template->param( $canReserve->{status} => 1 );
357 $biblioloopiter{ $canReserve->{status} } = 1;
359 elsif ( $canReserve->{status} eq 'alreadypossession' ) {
360 $template->param( $canReserve->{status} => 1);
361 $biblioloopiter{ $canReserve->{status} } = 1;
364 $biblioloopiter{ $canReserve->{status} } = 1;
368 # For multiple holds per record, if a patron has previously placed a hold,
369 # the patron can only place more holds of the same type. That is, if the
370 # patron placed a record level hold, all the holds the patron places must
371 # be record level. If the patron placed an item level hold, all holds
372 # the patron places must be item level
373 my $holds = Koha::Holds->search(
375 borrowernumber => $patron->borrowernumber,
376 biblionumber => $biblionumber,
380 $force_hold_level = $holds->forced_hold_level();
381 $biblioloopiter{force_hold_level} = $force_hold_level;
382 $template->param( force_hold_level => $force_hold_level );
384 # For a librarian to be able to place multiple record holds for a patron for a record,
385 # we must find out what the maximum number of holds they can place for the patron is
386 my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber );
387 my $remaining_holds_for_record = $max_holds_for_record - $holds->count();
388 $biblioloopiter{remaining_holds_for_record} = $max_holds_for_record;
389 $template->param( max_holds_for_record => $max_holds_for_record );
390 $template->param( remaining_holds_for_record => $remaining_holds_for_record );
394 my $count = Koha::Holds->search( { biblionumber => $biblionumber } )->count();
395 my $totalcount = $count;
397 # adding a fixed value for priority options
398 my $fixedRank = $count+1;
400 my %itemnumbers_of_biblioitem;
402 my @hostitems = get_hostitemnumbers_of($biblionumber);
405 $template->param('hostitemsflag' => 1);
406 push(@itemnumbers, @hostitems);
409 my $items = Koha::Items->search({ -or => { biblionumber => $biblionumber, itemnumber => { in => \@itemnumbers } } });
411 unless ( $items->count ) {
412 # FIXME Then why do we continue?
413 $template->param('noitems' => 1) unless ( $multi_hold );
414 $biblioloopiter{noitems} = 1;
417 ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers
418 ## this is important when we have analytic items which may be on another record
419 my ( $iteminfos_of );
420 while ( my $item = $items->next ) {
421 $item = $item->unblessed;
422 my $biblioitemnumber = $item->{biblioitemnumber};
423 my $itemnumber = $item->{itemnumber};
424 push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
425 $iteminfos_of->{$itemnumber} = $item;
428 my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
430 my $biblioiteminfos_of = {
433 ( $biblioitem->{biblioitemnumber} => $biblioitem )
434 } @{ Koha::Biblioitems->search(
435 { biblioitemnumber => { -in => \@biblioitemnumbers } },
436 { select => ['biblionumber', 'biblioitemnumber', 'publicationyear', 'itemtype']}
441 if ( $club_hold or $borrowernumber_hold ) {
444 my @available_itemtypes;
445 foreach my $biblioitemnumber (@biblioitemnumbers) {
446 my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
447 my $num_items_available = 0;
448 my $num_override = 0;
450 my $num_alreadyheld = 0;
452 $biblioitem->{force_hold_level} = $force_hold_level;
454 if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
455 $biblioitem->{hostitemsflag} = 1;
458 $biblioloopiter{description} = $biblioitem->{description};
459 $biblioloopiter{itypename} = $biblioitem->{description};
460 if ( $biblioitem->{itemtype} ) {
462 $biblioitem->{description} =
463 $itemtypes->{ $biblioitem->{itemtype} }{description};
465 $biblioloopiter{imageurl} =
466 getitemtypeimagelocation( 'intranet',
467 $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
470 # iterating through all items first to check if any of them available
471 # to pass this value further inside down to IsAvailableForItemLevelRequest to
472 # it's complicated logic to analyse.
473 # (before this loop was inside that sub loop so it was O(n^2) )
474 my $items_any_available;
475 $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblioitem->{biblionumber}, patron => $patron })
478 foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } ) {
479 my $item = $iteminfos_of->{$itemnumber};
482 $do_check = $patron->do_check_for_previous_checkout($item) if $wants_check;
483 if ( $do_check && $wants_check ) {
484 $item->{checked_previously} = $do_check;
486 $biblioloopiter{checked_previously} = $do_check;
488 $template->param( checked_previously => $do_check );
492 $item->{force_hold_level} = $force_hold_level;
494 unless (C4::Context->preference('item-level_itypes')) {
495 $item->{itype} = $biblioitem->{itemtype};
498 $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
499 $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
500 $item->{homebranch} = $item->{homebranch};
502 # if the holdingbranch is different than the homebranch, we show the
503 # holdingbranch of the document too
504 if ( $item->{homebranch} ne $item->{holdingbranch} ) {
505 $item->{holdingbranch} = $item->{holdingbranch};
508 if($item->{biblionumber} ne $biblionumber){
509 $item->{hostitemsflag} = 1;
510 $item->{hosttitle} = Koha::Biblios->find( $item->{biblionumber} )->title;
513 # if the item is currently on loan, we display its return date and
514 # change the background color
515 my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
517 $item->{date_due} = $issue->date_due;
518 $item->{backgroundcolor} = 'onloan';
522 my $item_object = Koha::Items->find( $itemnumber );
523 my $holds = $item_object->current_holds;
524 if ( my $first_hold = $holds->next ) {
525 my $p = Koha::Patrons->find( $first_hold->borrowernumber );
527 $item->{backgroundcolor} = 'reserved';
528 $item->{reservedate} = output_pref({ dt => dt_from_string( $first_hold->reservedate ), dateonly => 1 }); # FIXME Should be formatted in the template
529 $item->{ReservedFor} = $p;
530 $item->{ExpectedAtLibrary} = $first_hold->branchcode;
531 $item->{waitingdate} = $first_hold->waitingdate;
534 # Management of the notforloan document
535 if ( $item->{notforloan} ) {
536 $item->{backgroundcolor} = 'other';
539 # Management of lost or long overdue items
540 if ( $item->{itemlost} ) {
541 $item->{backgroundcolor} = 'other';
542 if ($logged_in_patron->category->hidelostitems && !$showallitems) {
548 # Check the transit status
549 my ( $transfertwhen, $transfertfrom, $transfertto ) =
550 GetTransfers($itemnumber);
552 if ( defined $transfertwhen && $transfertwhen ne '' ) {
553 $item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
554 $item->{transfertfrom} = $transfertfrom;
555 $item->{transfertto} = $transfertto;
556 $item->{nocancel} = 1;
559 # If there is no loan, return and transfer, we show a checkbox.
560 $item->{notforloanitype} = $itemtypes->{$item->{itype}}{notforloan};
561 $item->{notforloan} ||= 0;
563 # if independent branches is on we need to check if the person can reserve
564 # for branches they arent logged in to
565 if ( C4::Context->preference("IndependentBranches") ) {
566 if (! C4::Context->preference("canreservefromotherbranches")){
567 # can't reserve items so need to check if item homebranch and userenv branch match if not we can't reserve
568 my $userenv = C4::Context->userenv;
569 unless ( C4::Context->IsSuperLibrarian ) {
570 $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
576 my $patron_unblessed = $patron->unblessed;
577 my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
579 my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
581 $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
583 my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status};
584 $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
585 $item->{not_holdable} ||= 'notforloan' if ( $item->{notforloanitype} || $item->{notforloan} > 0 );
587 $item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
590 !$item->{cantreserve}
591 && !$exceeded_maxreserves
592 && $can_item_be_reserved eq 'OK'
593 # items_any_available defined outside of the current loop,
594 # so we avoiding loop inside IsAvailableForItemLevelRequest:
595 && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
598 # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
599 my @pickup_locations = $item_object->pickup_locations({ patron => $patron })->as_list;
600 $item->{pickup_locations_count} = scalar @pickup_locations;
602 if ( @pickup_locations ) {
603 $num_items_available++;
604 $item->{available} = 1;
606 my $default_pickup_location;
608 # Default to logged-in, if valid
609 if ( C4::Context->userenv->{branch} ) {
610 ($default_pickup_location) = grep { $_->branchcode eq C4::Context->userenv->{branch} } @pickup_locations;
613 $item->{default_pickup_location} = $default_pickup_location;
616 $item->{available} = 0;
617 $item->{not_holdable} = "no_valid_pickup_location";
620 push( @available_itemtypes, $item->{itype} );
622 elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
623 # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
624 # with the exception of itemAlreadyOnHold because, you know, the item is already on hold
625 if ( $can_item_be_reserved ne 'itemAlreadyOnHold' ) {
626 # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
627 my $pickup_locations = $item_object->pickup_locations({ patron => $patron });
628 $item->{pickup_locations_count} = $pickup_locations->count;
629 if ( $item->{pickup_locations_count} > 0 ) {
630 $item->{override} = 1;
632 # pass the holding branch for use as default
633 my $default_pickup_location = $pickup_locations->search({ branchcode => $item->{holdingbranch} })->next;
634 $item->{default_pickup_location} = $default_pickup_location;
637 $item->{available} = 0;
638 $item->{not_holdable} = "no_valid_pickup_location";
640 } else { $num_alreadyheld++ }
642 push( @available_itemtypes, $item->{itype} );
645 # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
647 # Show serial enumeration when needed
648 if ($item->{enumchron}) {
649 $itemdata_enumchron = 1;
651 # Show collection when needed
652 if ($item->{ccode}) {
657 push @{ $biblioitem->{itemloop} }, $item;
660 # While we can't override an alreay held item, we should be able to override the others
661 # Unless all items are already held
662 if ( $num_override > 0 && ($num_override + $num_alreadyheld) == scalar( @{ $biblioitem->{itemloop} } ) ) {
663 # That is, if all items require an override
664 $template->param( override_required => 1 );
665 } elsif ( $num_items_available == 0 ) {
666 $template->param( none_available => 1 );
667 $biblioloopiter{warn} = 1;
668 $biblioloopiter{none_avail} = 1;
670 $template->param( hiddencount => $hiddencount);
672 push @bibitemloop, $biblioitem;
675 @available_itemtypes = uniq( @available_itemtypes );
677 bibitemloop => \@bibitemloop,
678 available_itemtypes => \@available_itemtypes
682 # existingreserves building
684 my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } );
687 my $a_found = $a->found() || '';
688 my $b_found = $a->found() || '';
689 $a_found cmp $b_found;
694 if ( $res->is_found() ) {
695 $reserve{'holdingbranch'} = $res->item()->holdingbranch();
696 $reserve{'biblionumber'} = $res->item()->biblionumber();
697 $reserve{'barcodenumber'} = $res->item()->barcode();
698 $reserve{'wbrcode'} = $res->branchcode();
699 $reserve{'itemnumber'} = $res->itemnumber();
700 $reserve{'wbrname'} = $res->branch()->branchname();
701 $reserve{'atdestination'} = $res->is_at_destination();
702 $reserve{'desk_name'} = ( $res->desk() ) ? $res->desk()->desk_name() : '' ;
703 $reserve{'found'} = $res->is_found();
704 $reserve{'inprocessing'} = $res->is_in_processing();
705 $reserve{'intransit'} = $res->is_in_transit();
707 elsif ( $res->priority() > 0 ) {
708 if ( my $item = $res->item() ) {
709 $reserve{'itemnumber'} = $item->id();
710 $reserve{'barcodenumber'} = $item->barcode();
711 $reserve{'item_level_hold'} = 1;
715 $reserve{'expirationdate'} = $res->expirationdate;
716 $reserve{'date'} = $res->reservedate;
717 $reserve{'borrowernumber'} = $res->borrowernumber();
718 $reserve{'biblionumber'} = $res->biblionumber();
719 $reserve{'patron'} = $res->borrower;
720 $reserve{'notes'} = $res->reservenotes();
721 $reserve{'waiting_date'} = $res->waitingdate();
722 $reserve{'ccode'} = $res->item() ? $res->item()->ccode() : undef;
723 $reserve{'barcode'} = $res->item() ? $res->item()->barcode() : undef;
724 $reserve{'priority'} = $res->priority();
725 $reserve{'lowestPriority'} = $res->lowestPriority();
726 $reserve{'suspend'} = $res->suspend();
727 $reserve{'suspend_until'} = $res->suspend_until();
728 $reserve{'reserve_id'} = $res->reserve_id();
729 $reserve{itemtype} = $res->itemtype();
730 $reserve{branchcode} = $res->branchcode();
731 $reserve{non_priority} = $res->non_priority();
732 $reserve{object} = $res;
734 push( @reserveloop, \%reserve );
737 # get the time for the form name...
742 fixedRank => $fixedRank,
747 itemdata_enumchron => $itemdata_enumchron,
748 itemdata_ccode => $itemdata_ccode,
750 biblionumber => $biblionumber,
751 findborrower => $findborrower,
754 C4::Search::enabled_staff_search_views,
757 $biblioloopiter{biblionumber} = $biblionumber;
758 $biblioloopiter{title} = $biblio->title;
759 $biblioloopiter{rank} = $fixedRank;
760 $biblioloopiter{reserveloop} = \@reserveloop;
763 $template->param( reserveloop => \@reserveloop );
767 # Add the valid pickup locations
768 my @pickup_locations = $biblio->pickup_locations({ patron => $patron })->as_list;
769 $biblioloopiter{pickup_locations} = \@pickup_locations;
770 $biblioloopiter{pickup_locations_codes} = [ map { $_->branchcode } @pickup_locations ];
773 $num_bibs_available++ unless $biblioloopiter{none_avail};
774 push @biblioloop, \%biblioloopiter;
777 $template->param( no_bibs_available => 1 ) unless $num_bibs_available > 0;
778 $template->param( biblioloop => \@biblioloop );
779 $template->param( no_reserves_allowed => $no_reserves_allowed );
780 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
781 $template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
782 $template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber));
783 } elsif ( ! $multi_hold ) {
784 my $biblio = Koha::Biblios->find( $biblionumber );
785 $template->param( biblio => $biblio );
789 $template->param( biblionumbers => join('/', @biblionumbers) );
791 $template->param( biblionumber => $biblionumber || $biblionumbers[0] );
794 # pass the userenv branch if no pickup location selected
795 $template->param( pickup => $pickup || C4::Context->userenv->{branch} );
797 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
798 $template->param( reserve_in_future => 1 );
802 SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
803 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
807 output_html_with_http_headers $input, $cookie, $template->output;
809 sub sort_borrowerlist {
810 my $borrowerslist = shift;
813 uc( $a->{surname} . $a->{firstname} ) cmp
814 uc( $b->{surname} . $b->{firstname} )