Bug 24298: Record transfer triggers for returns
[koha.git] / reserve / request.pl
blob5864b3d747676783efdc861185f0c58cb154b236
1 #!/usr/bin/perl
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>.
23 =head1 request.pl
25 script to place reserves/requests
27 =cut
29 use Modern::Perl;
31 use CGI qw ( -utf8 );
32 use List::MoreUtils qw/uniq/;
33 use Date::Calc qw/Date_to_Days/;
34 use C4::Output;
35 use C4::Auth;
36 use C4::Reserves;
37 use C4::Biblio;
38 use C4::Items;
39 use C4::Koha;
40 use C4::Serials;
41 use C4::Circulation;
42 use Koha::DateUtils;
43 use C4::Utils::DataTables::Members;
44 use C4::Members;
45 use C4::Search; # enabled_staff_search_views
47 use Koha::Biblios;
48 use Koha::DateUtils;
49 use Koha::Checkouts;
50 use Koha::Holds;
51 use Koha::CirculationRules;
52 use Koha::Items;
53 use Koha::ItemTypes;
54 use Koha::Libraries;
55 use Koha::Patrons;
56 use Koha::Clubs;
58 my $dbh = C4::Context->dbh;
59 my $input = new CGI;
60 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
62 template_name => "reserve/request.tt",
63 query => $input,
64 type => "intranet",
65 authnotrequired => 0,
66 flagsrequired => { reserveforothers => 'place_holds' },
70 my $showallitems = $input->param('showallitems');
71 my $pickup = $input->param('pickup') || C4::Context->userenv->{'branch'};
73 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
75 # Select borrowers infos
76 my $findborrower = $input->param('findborrower');
77 $findborrower = '' unless defined $findborrower;
78 $findborrower =~ s|,| |g;
79 my $findclub = $input->param('findclub');
80 $findclub = '' unless defined $findclub && !$findborrower;
81 my $borrowernumber_hold = $input->param('borrowernumber') || '';
82 my $club_hold = $input->param('club')||'';
83 my $messageborrower;
84 my $messageclub;
85 my $warnings;
86 my $messages;
87 my $exceeded_maxreserves;
88 my $exceeded_holds_per_record;
90 my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
91 my $action = $input->param('action');
92 $action ||= q{};
94 if ( $action eq 'move' ) {
95 my $where = $input->param('where');
96 my $reserve_id = $input->param('reserve_id');
97 my $prev_priority = $input->param('prev_priority');
98 my $next_priority = $input->param('next_priority');
99 my $first_priority = $input->param('first_priority');
100 my $last_priority = $input->param('last_priority');
101 my $hold_itemnumber = $input->param('itemnumber');
102 if ( $prev_priority == 0 && $next_priority == 1 ){
103 C4::Reserves::RevertWaitingStatus({ itemnumber => $hold_itemnumber });
104 } else {
105 AlterPriority( $where, $reserve_id, $prev_priority, $next_priority, $first_priority, $last_priority );
107 } elsif ( $action eq 'cancel' ) {
108 my $reserve_id = $input->param('reserve_id');
109 my $hold = Koha::Holds->find( $reserve_id );
110 $hold->cancel if $hold;
111 } elsif ( $action eq 'setLowestPriority' ) {
112 my $reserve_id = $input->param('reserve_id');
113 ToggleLowestPriority( $reserve_id );
114 } elsif ( $action eq 'toggleSuspend' ) {
115 my $reserve_id = $input->param('reserve_id');
116 my $suspend_until = $input->param('suspend_until');
117 ToggleSuspend( $reserve_id, $suspend_until );
120 if ($findborrower) {
121 my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
122 if ( $patron ) {
123 $borrowernumber_hold = $patron->borrowernumber;
124 } else {
125 my $dt_params = { iDisplayLength => -1 };
126 my $results = C4::Utils::DataTables::Members::search(
128 searchmember => $findborrower,
129 dt_params => $dt_params,
132 my $borrowers = $results->{patrons};
133 if ( scalar @$borrowers == 1 ) {
134 $borrowernumber_hold = $borrowers->[0]->{borrowernumber};
135 } elsif ( @$borrowers ) {
136 $template->param( borrowers => $borrowers );
137 } else {
138 $messageborrower = "'$findborrower'";
143 if($findclub) {
144 my $club = Koha::Clubs->find( { name => $findclub } );
145 if( $club ) {
146 $club_hold = $club->id;
147 } else {
148 my @clubs = Koha::Clubs->search( [
149 { name => { like => '%'.$findclub.'%' } },
150 { description => { like => '%'.$findclub.'%' } }
151 ] );
152 if( scalar @clubs == 1 ) {
153 $club_hold = $clubs[0]->id;
154 } elsif ( @clubs ) {
155 $template->param( clubs => \@clubs );
156 } else {
157 $messageclub = "'$findclub'";
162 my @biblionumbers = ();
163 my $biblionumber = $input->param('biblionumber');
164 my $biblionumbers = $input->param('biblionumbers');
165 if ( $biblionumbers ) {
166 @biblionumbers = split '/', $biblionumbers;
167 } else {
168 push @biblionumbers, $input->multi_param('biblionumber');
171 my $multihold = scalar $input->param('multi_hold');
172 # FIXME multi_hold should not be a variable but depends on the number of elements in @biblionumbers
173 $template->param(multi_hold => scalar $input->param('multi_hold'));
175 # If we have the borrowernumber because we've performed an action, then we
176 # don't want to try to place another reserve.
177 if ($borrowernumber_hold && !$action) {
178 my $patron = Koha::Patrons->find( $borrowernumber_hold );
179 my $diffbranch;
181 # we check the reserves of the user, and if they can reserve a document
182 # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
184 my $reserves_count = $patron->holds->count;
186 my $new_reserves_count = scalar( @biblionumbers );
188 my $maxreserves = C4::Context->preference('maxreserves');
189 if ( $maxreserves
190 && ( $reserves_count + $new_reserves_count > $maxreserves ) )
192 my $new_reserves_allowed =
193 $maxreserves - $reserves_count > 0
194 ? $maxreserves - $reserves_count
195 : 0;
196 $warnings = 1;
197 $exceeded_maxreserves = 1;
198 $template->param(
199 new_reserves_allowed => $new_reserves_allowed,
200 new_reserves_count => $new_reserves_count,
201 reserves_count => $reserves_count,
202 maxreserves => $maxreserves,
206 # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
207 my $expiry_date = $patron->dateexpiry;
208 my $expiry = 0; # flag set if patron account has expired
209 if ($expiry_date and $expiry_date ne '0000-00-00' and
210 Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
211 $expiry = 1;
214 # check if the borrower make the reserv in a different branch
215 if ( $patron->branchcode ne C4::Context->userenv->{'branch'} ) {
216 $diffbranch = 1;
219 my $amount_outstanding = $patron->account->balance;
220 $template->param(
221 patron => $patron,
222 expiry => $expiry,
223 diffbranch => $diffbranch,
224 messages => $messages,
225 warnings => $warnings,
226 amount_outstanding => $amount_outstanding,
230 if ($club_hold && !$borrowernumber_hold && !$action) {
231 my $club = Koha::Clubs->find($club_hold);
233 my $enrollments = $club->club_enrollments;
235 my $maxreserves = C4::Context->preference('maxreserves');
236 my $new_reserves_count = scalar( @biblionumbers );
238 my @members;
240 while(my $enrollment = $enrollments->next) {
241 next if $enrollment->is_canceled;
242 my $member = { patron => $enrollment->patron->unblessed };
243 my $reserves_count = $enrollment->patron->holds->count;
244 if ( $maxreserves
245 && ( $reserves_count + $new_reserves_count > $maxreserves ) )
247 $member->{new_reserves_allowed} = $maxreserves - $reserves_count > 0
248 ? $maxreserves - $reserves_count
249 : 0;
250 $member->{exceeded_maxreserves} = 1;
252 my $expiry_date = $enrollment->patron->dateexpiry;
253 $member->{expiry} = 0; # flag set if patron account has expired
254 if ($expiry_date and $expiry_date ne '0000-00-00' and
255 Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
256 $member->{expiry} = 1;
258 $member->{amount_outstanding} = $enrollment->patron->account->balance;
259 if ( $enrollment->patron->branchcode ne C4::Context->userenv->{'branch'} ) {
260 $member->{diffbranch} = 1;
263 push @members, $member;
266 $template->param(
267 club => $club,
268 members => \@members,
269 maxreserves => $maxreserves,
270 new_reserves_count => $new_reserves_count
274 $template->param(
275 messageborrower => $messageborrower,
276 messageclub => $messageclub
279 # FIXME launch another time GetMember perhaps until (Joubu: Why?)
280 my $patron = Koha::Patrons->find( $borrowernumber_hold );
282 my $logged_in_patron = Koha::Patrons->find( $borrowernumber );
284 my $wants_check;
285 if ($patron) {
286 $wants_check = $patron->wants_check_for_previous_checkout;
288 my $itemdata_enumchron = 0;
289 my $itemdata_ccode = 0;
290 my @biblioloop = ();
291 foreach my $biblionumber (@biblionumbers) {
292 next unless $biblionumber =~ m|^\d+$|;
294 my %biblioloopiter = ();
296 my $biblio = Koha::Biblios->find( $biblionumber );
298 my $force_hold_level;
299 if ( $patron ) {
300 { # CanBookBeReserved
301 my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
302 if ( $canReserve->{status} eq 'OK' ) {
304 #All is OK and we can continue
306 elsif ( $canReserve->{status} eq 'tooManyReserves' ) {
307 $exceeded_maxreserves = 1;
308 $template->param( maxreserves => $canReserve->{limit} );
310 elsif ( $canReserve->{status} eq 'tooManyHoldsForThisRecord' ) {
311 $exceeded_holds_per_record = 1;
312 $biblioloopiter{ $canReserve->{status} } = 1;
314 elsif ( $canReserve->{status} eq 'ageRestricted' ) {
315 $template->param( $canReserve->{status} => 1 );
316 $biblioloopiter{ $canReserve->{status} } = 1;
318 else {
319 $biblioloopiter{ $canReserve->{status} } = 1;
323 # For multiple holds per record, if a patron has previously placed a hold,
324 # the patron can only place more holds of the same type. That is, if the
325 # patron placed a record level hold, all the holds the patron places must
326 # be record level. If the patron placed an item level hold, all holds
327 # the patron places must be item level
328 my $holds = Koha::Holds->search(
330 borrowernumber => $patron->borrowernumber,
331 biblionumber => $biblionumber,
332 found => undef,
335 $force_hold_level = $holds->forced_hold_level();
336 $biblioloopiter{force_hold_level} = $force_hold_level;
337 $template->param( force_hold_level => $force_hold_level );
339 # For a librarian to be able to place multiple record holds for a patron for a record,
340 # we must find out what the maximum number of holds they can place for the patron is
341 my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber );
342 my $remaining_holds_for_record = $max_holds_for_record - $holds->count();
343 $biblioloopiter{remaining_holds_for_record} = $max_holds_for_record;
344 $template->param( max_holds_for_record => $max_holds_for_record );
345 $template->param( remaining_holds_for_record => $remaining_holds_for_record );
347 { # alreadypossession
348 # Check to see if patron is allowed to place holds on records where the
349 # patron already has an item from that record checked out
350 if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
351 && CheckIfIssuedToPatron( $patron->borrowernumber, $biblionumber ) )
353 $template->param( alreadypossession => 1, );
359 my $count = Koha::Holds->search( { biblionumber => $biblionumber } )->count();
360 my $totalcount = $count;
362 # FIXME think @optionloop, is maybe obsolete, or must be switchable by a systeme preference fixed rank or not
363 # make priorities options
365 my @optionloop;
366 for ( 1 .. $count + 1 ) {
367 push(
368 @optionloop,
370 num => $_,
371 selected => ( $_ == $count + 1 ),
375 # adding a fixed value for priority options
376 my $fixedRank = $count+1;
378 my %itemnumbers_of_biblioitem;
380 my @hostitems = get_hostitemnumbers_of($biblionumber);
381 my @itemnumbers;
382 if (@hostitems){
383 $template->param('hostitemsflag' => 1);
384 push(@itemnumbers, @hostitems);
387 my $items = Koha::Items->search({ -or => { biblionumber => $biblionumber, itemnumber => { in => \@itemnumbers } } });
389 unless ( $items->count ) {
390 # FIXME Then why do we continue?
391 $template->param('noitems' => 1);
392 $biblioloopiter{noitems} = 1;
395 ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
396 ## when by definition all of the itemnumber have the same biblioitemnumber
397 my ( $iteminfos_of );
398 while ( my $item = $items->next ) {
399 $item = $item->unblessed;
400 my $biblioitemnumber = $item->{biblioitemnumber};
401 my $itemnumber = $item->{itemnumber};
402 push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
403 $iteminfos_of->{$itemnumber} = $item;
406 ## Should be same as biblionumber
407 my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
409 my $biblioiteminfos_of = {
410 map {
411 my $biblioitem = $_;
412 ( $biblioitem->{biblioitemnumber} => $biblioitem )
413 } @{ Koha::Biblioitems->search(
414 { biblioitemnumber => { -in => \@biblioitemnumbers } },
415 { select => ['biblioitemnumber', 'publicationyear', 'itemtype']}
416 )->unblessed
420 my @bibitemloop;
422 my @available_itemtypes;
423 foreach my $biblioitemnumber (@biblioitemnumbers) {
424 my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
425 my $num_available = 0;
426 my $num_override = 0;
427 my $hiddencount = 0;
428 my $num_alreadyheld = 0;
430 $biblioitem->{force_hold_level} = $force_hold_level;
432 if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
433 $biblioitem->{hostitemsflag} = 1;
436 $biblioloopiter{description} = $biblioitem->{description};
437 $biblioloopiter{itypename} = $biblioitem->{description};
438 if ( $biblioitem->{itemtype} ) {
440 $biblioitem->{description} =
441 $itemtypes->{ $biblioitem->{itemtype} }{description};
443 $biblioloopiter{imageurl} =
444 getitemtypeimagelocation( 'intranet',
445 $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
448 foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } ) {
449 my $item = $iteminfos_of->{$itemnumber};
450 my $do_check;
451 if ( $patron ) {
452 $do_check = $patron->do_check_for_previous_checkout($item) if $wants_check;
453 if ( $do_check && $wants_check ) {
454 $item->{checked_previously} = $do_check;
455 if ( $multihold ) {
456 $biblioloopiter{checked_previously} = $do_check;
457 } else {
458 $template->param( checked_previously => $do_check );
462 $item->{force_hold_level} = $force_hold_level;
464 unless (C4::Context->preference('item-level_itypes')) {
465 $item->{itype} = $biblioitem->{itemtype};
468 $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
469 $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
470 $item->{homebranch} = $item->{homebranch};
472 # if the holdingbranch is different than the homebranch, we show the
473 # holdingbranch of the document too
474 if ( $item->{homebranch} ne $item->{holdingbranch} ) {
475 $item->{holdingbranch} = $item->{holdingbranch};
478 if($item->{biblionumber} ne $biblionumber){
479 $item->{hostitemsflag} = 1;
480 $item->{hosttitle} = Koha::Biblios->find( $item->{biblionumber} )->title;
483 # if the item is currently on loan, we display its return date and
484 # change the background color
485 my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
486 if ( $issue ) {
487 $item->{date_due} = $issue->date_due;
488 $item->{backgroundcolor} = 'onloan';
491 # checking reserve
492 my $item_object = Koha::Items->find( $itemnumber );
493 my $holds = $item_object->current_holds;
494 if ( my $first_hold = $holds->next ) {
495 my $p = Koha::Patrons->find( $first_hold->borrowernumber );
497 $item->{backgroundcolor} = 'reserved';
498 $item->{reservedate} = output_pref({ dt => dt_from_string( $first_hold->reservedate ), dateonly => 1 }); # FIXME Should be formatted in the template
499 $item->{ReservedFor} = $p;
500 $item->{ExpectedAtLibrary} = $first_hold->branchcode;
501 $item->{waitingdate} = $first_hold->waitingdate;
504 # Management of the notforloan document
505 if ( $item->{notforloan} ) {
506 $item->{backgroundcolor} = 'other';
509 # Management of lost or long overdue items
510 if ( $item->{itemlost} ) {
511 $item->{backgroundcolor} = 'other';
512 if ($logged_in_patron->category->hidelostitems && !$showallitems) {
513 $item->{hide} = 1;
514 $hiddencount++;
518 # Check the transit status
519 my ( $transfertwhen, $transfertfrom, $transfertto ) =
520 GetTransfers($itemnumber);
522 if ( defined $transfertwhen && $transfertwhen ne '' ) {
523 $item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
524 $item->{transfertfrom} = $transfertfrom;
525 $item->{transfertto} = $transfertto;
526 $item->{nocancel} = 1;
529 # If there is no loan, return and transfer, we show a checkbox.
530 $item->{notforloan} ||= 0;
532 # if independent branches is on we need to check if the person can reserve
533 # for branches they arent logged in to
534 if ( C4::Context->preference("IndependentBranches") ) {
535 if (! C4::Context->preference("canreservefromotherbranches")){
536 # can't reserve items so need to check if item homebranch and userenv branch match if not we can't reserve
537 my $userenv = C4::Context->userenv;
538 unless ( C4::Context->IsSuperLibrarian ) {
539 $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
544 if ( $patron ) {
545 my $patron_unblessed = $patron->unblessed;
546 my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
548 my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
550 $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
552 my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber )->{status};
553 $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
555 $item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
557 if (
558 !$item->{cantreserve}
559 && !$exceeded_maxreserves
560 && IsAvailableForItemLevelRequest($item_object, $patron)
561 && $can_item_be_reserved eq 'OK'
564 $item->{available} = 1;
565 $num_available++;
566 if($branchitemrule->{'hold_fulfillment_policy'} eq 'any' ) {
567 $item->{pickup_locations} = 'Any library';
568 $item->{pickup_locations_code} = 'all';
569 } else {
570 $item->{pickup_locations} = join( ', ',
571 map { $_->unblessed->{branchname} }
572 Koha::Items->find($itemnumber)
573 ->pickup_locations( { patron => $patron } ) );
574 $item->{pickup_locations_code} = join( ',',
575 map { $_->unblessed->{branchcode} }
576 Koha::Items->find($itemnumber)
577 ->pickup_locations( { patron => $patron } ) );
580 push( @available_itemtypes, $item->{itype} );
582 elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
583 # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
584 # with the exception of itemAlreadyOnHold because, you know, the item is already on hold
585 if ( $can_item_be_reserved ne 'itemAlreadyOnHold' ) {
586 $item->{override} = 1;
587 $num_override++;
588 } else { $num_alreadyheld++ }
590 push( @available_itemtypes, $item->{itype} );
593 # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
595 # Show serial enumeration when needed
596 if ($item->{enumchron}) {
597 $itemdata_enumchron = 1;
599 # Show collection when needed
600 if ($item->{ccode}) {
601 $itemdata_ccode = 1;
605 push @{ $biblioitem->{itemloop} }, $item;
608 # While we can't override an alreay held item, we should be able to override the others
609 # Unless all items are already held
610 if ( $num_override > 0 && ($num_override + $num_alreadyheld) == scalar( @{ $biblioitem->{itemloop} } ) ) {
611 # That is, if all items require an override
612 $template->param( override_required => 1 );
613 } elsif ( $num_available == 0 ) {
614 $template->param( none_available => 1 );
615 $biblioloopiter{warn} = 1;
616 $biblioloopiter{none_avail} = 1;
618 $template->param( hiddencount => $hiddencount);
620 push @bibitemloop, $biblioitem;
623 @available_itemtypes = uniq( @available_itemtypes );
624 $template->param( available_itemtypes => \@available_itemtypes );
626 # existingreserves building
627 my @reserveloop;
628 my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } );
629 foreach my $res (
630 sort {
631 my $a_found = $a->found() || '';
632 my $b_found = $a->found() || '';
633 $a_found cmp $b_found;
634 } @reserves
637 my $priority = $res->priority();
638 my %reserve;
639 my @optionloop;
640 for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
641 push(
642 @optionloop,
644 num => $i,
645 selected => ( $i == $priority ),
650 if ( $res->is_found() ) {
651 $reserve{'holdingbranch'} = $res->item()->holdingbranch();
652 $reserve{'biblionumber'} = $res->item()->biblionumber();
653 $reserve{'barcodenumber'} = $res->item()->barcode();
654 $reserve{'wbrcode'} = $res->branchcode();
655 $reserve{'itemnumber'} = $res->itemnumber();
656 $reserve{'wbrname'} = $res->branch()->branchname();
658 if ( $reserve{'holdingbranch'} eq $reserve{'wbrcode'} ) {
660 # Just because the holdingbranch matches the reserve branch doesn't mean the item
661 # has arrived at the destination, check for an open transfer for the item as well
662 my ( $transfertwhen, $transfertfrom, $transferto ) =
663 C4::Circulation::GetTransfers( $res->itemnumber() );
664 if ( not $transferto or $transferto ne $res->branchcode() ) {
665 $reserve{'atdestination'} = 1;
669 # set found to 1 if reserve is waiting for patron pickup
670 $reserve{'found'} = $res->is_found();
671 $reserve{'intransit'} = $res->is_in_transit();
673 elsif ( $res->priority() > 0 ) {
674 if ( my $item = $res->item() ) {
675 $reserve{'itemnumber'} = $item->id();
676 $reserve{'barcodenumber'} = $item->barcode();
677 $reserve{'item_level_hold'} = 1;
681 $reserve{'expirationdate'} = $res->expirationdate;
682 $reserve{'date'} = $res->reservedate;
683 $reserve{'borrowernumber'} = $res->borrowernumber();
684 $reserve{'biblionumber'} = $res->biblionumber();
685 $reserve{'patron'} = $res->borrower;
686 $reserve{'notes'} = $res->reservenotes();
687 $reserve{'waiting_date'} = $res->waitingdate();
688 $reserve{'ccode'} = $res->item() ? $res->item()->ccode() : undef;
689 $reserve{'barcode'} = $res->item() ? $res->item()->barcode() : undef;
690 $reserve{'priority'} = $res->priority();
691 $reserve{'lowestPriority'} = $res->lowestPriority();
692 $reserve{'optionloop'} = \@optionloop;
693 $reserve{'suspend'} = $res->suspend();
694 $reserve{'suspend_until'} = $res->suspend_until();
695 $reserve{'reserve_id'} = $res->reserve_id();
696 $reserve{itemtype} = $res->itemtype();
697 $reserve{branchcode} = $res->branchcode();
698 $reserve{object} = $res;
700 push( @reserveloop, \%reserve );
703 # get the time for the form name...
704 my $time = time();
706 $template->param(
707 time => $time,
708 fixedRank => $fixedRank,
711 # display infos
712 $template->param(
713 optionloop => \@optionloop,
714 bibitemloop => \@bibitemloop,
715 itemdata_enumchron => $itemdata_enumchron,
716 itemdata_ccode => $itemdata_ccode,
717 date => $date,
718 biblionumber => $biblionumber,
719 findborrower => $findborrower,
720 biblio => $biblio,
721 holdsview => 1,
722 C4::Search::enabled_staff_search_views,
725 $biblioloopiter{biblionumber} = $biblionumber;
726 $biblioloopiter{title} = $biblio->title;
727 $biblioloopiter{rank} = $fixedRank;
728 $biblioloopiter{reserveloop} = \@reserveloop;
730 if (@reserveloop) {
731 $template->param( reserveloop => \@reserveloop );
734 push @biblioloop, \%biblioloopiter;
737 $template->param( biblioloop => \@biblioloop );
738 $template->param( biblionumbers => $biblionumbers );
739 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
740 $template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
741 $template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber));
742 $template->param( pickup => $pickup );
744 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
745 $template->param( reserve_in_future => 1 );
748 $template->param(
749 SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
750 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
753 # printout the page
754 output_html_with_http_headers $input, $cookie, $template->output;
756 sub sort_borrowerlist {
757 my $borrowerslist = shift;
758 my $ref = [];
759 push @{$ref}, sort {
760 uc( $a->{surname} . $a->{firstname} ) cmp
761 uc( $b->{surname} . $b->{firstname} )
762 } @{$borrowerslist};
763 return $ref;