Bug 15758: Koha::Libraries - Remove GetBranches
[koha.git] / circ / returns.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #           2006 SAN-OP
5 #           2007-2010 BibLibre, Paul POULAIN
6 #           2010 Catalyst IT
7 #           2011 PTFS-Europe Ltd.
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
15 #
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23
24 =head1 returns.pl
25
26 script to execute returns of books
27
28 =cut
29
30 use strict;
31 use warnings;
32
33 use Carp 'verbose';
34 $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
35
36 use CGI qw ( -utf8 );
37 use DateTime;
38 use C4::Context;
39 use C4::Auth qw/:DEFAULT get_session/;
40 use C4::Output;
41 use C4::Circulation;
42 use C4::Print;
43 use C4::Reserves;
44 use C4::Biblio;
45 use C4::Items;
46 use C4::Members;
47 use C4::Members::Messaging;
48 use C4::Koha;   # FIXME : is it still useful ?
49 use C4::RotatingCollections;
50 use Koha::DateUtils;
51 use Koha::Calendar;
52
53 my $query = new CGI;
54
55 #getting the template
56 my ( $template, $librarian, $cookie ) = get_template_and_user(
57     {
58         template_name   => "circ/returns.tt",
59         query           => $query,
60         type            => "intranet",
61         authnotrequired => 0,
62         flagsrequired   => { circulate => "circulate_remaining_permissions" },
63     }
64 );
65
66 my $sessionID = $query->cookie("CGISESSID");
67 my $session = get_session($sessionID);
68 if ($session->param('branch') eq 'NO_LIBRARY_SET'){
69     # no branch set we can't return
70     print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
71     exit;
72 }
73
74 # Print a reserve slip on this page
75 if ( $query->param('print_slip') ) {
76     $template->param(
77         print_slip     => 1,
78         borrowernumber => scalar $query->param('borrowernumber'),
79         biblionumber   => scalar $query->param('biblionumber'),
80     );
81 }
82
83 #####################
84 #Global vars
85 my $printers = GetPrinters();
86 my $userenv = C4::Context->userenv;
87 my $userenv_branch = $userenv->{'branch'} // '';
88 my $printer = $userenv->{'branchprinter'} // '';
89 my $forgivemanualholdsexpire = $query->param('forgivemanualholdsexpire');
90
91 my $overduecharges = (C4::Context->preference('finesMode') && C4::Context->preference('finesMode') ne 'off');
92 #
93 # Some code to handle the error if there is no branch or printer setting.....
94 #
95
96 # Set up the item stack ....
97 my %returneditems;
98 my %riduedate;
99 my %riborrowernumber;
100 my @inputloop;
101 foreach ( $query->param ) {
102     my $counter;
103     if (/ri-(\d*)/) {
104         $counter = $1;
105         if ($counter > 20) {
106             next;
107         }
108     }
109     else {
110         next;
111     }
112
113     my %input;
114     my $barcode        = $query->param("ri-$counter");
115     my $duedate        = $query->param("dd-$counter");
116     my $borrowernumber = $query->param("bn-$counter");
117     $counter++;
118
119     # decode barcode    ## Didn't we already decode them before passing them back last time??
120     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
121     $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter'));
122
123     ######################
124     #Are these lines still useful ?
125     $returneditems{$counter}    = $barcode;
126     $riduedate{$counter}        = $duedate;
127     $riborrowernumber{$counter} = $borrowernumber;
128
129     #######################
130     $input{counter}        = $counter;
131     $input{barcode}        = $barcode;
132     $input{duedate}        = $duedate;
133     $input{borrowernumber} = $borrowernumber;
134     push( @inputloop, \%input );
135 }
136
137 ############
138 # Deal with the requests....
139
140 if ($query->param('WT-itemNumber')){
141         updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From'));
142 }
143
144 if ( $query->param('reserve_id') ) {
145     my $item           = $query->param('itemnumber');
146     my $borrowernumber = $query->param('borrowernumber');
147     my $reserve_id     = $query->param('reserve_id');
148     my $diffBranchReturned = $query->param('diffBranch');
149     my $iteminfo   = GetBiblioFromItemNumber($item);
150     my $cancel_reserve = $query->param('cancel_reserve');
151     # fix up item type for display
152     $iteminfo->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $iteminfo->{'itype'} : $iteminfo->{'itemtype'};
153
154     if ( $cancel_reserve ) {
155         CancelReserve({ reserve_id => $reserve_id, charge_cancel_fee => !$forgivemanualholdsexpire });
156     } else {
157         my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
158         # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
159         # i.e., whether to apply waiting status
160         ModReserveAffect( $item, $borrowernumber, $diffBranchSend, $reserve_id );
161     }
162 #   check if we have other reserves for this document, if we have a return send the message of transfer
163     my ( $messages, $nextreservinfo ) = GetOtherReserves($item);
164
165     my $borr = GetMember( borrowernumber => $nextreservinfo );
166     my $name   = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
167     if ( $messages->{'transfert'} ) {
168         $template->param(
169             itemtitle      => $iteminfo->{'title'},
170             itemnumber     => $iteminfo->{'itemnumber'},
171             itembiblionumber => $iteminfo->{'biblionumber'},
172             iteminfo       => $iteminfo->{'author'},
173             name           => $name,
174             borrowernumber => $borrowernumber,
175             borcnum        => $borr->{'cardnumber'},
176             borfirstname   => $borr->{'firstname'},
177             borsurname     => $borr->{'surname'},
178             diffbranch     => 1,
179         );
180     }
181 }
182
183 my $borrower;
184 my $returned = 0;
185 my $messages;
186 my $issueinformation;
187 my $itemnumber;
188 my $barcode     = $query->param('barcode');
189 my $exemptfine  = $query->param('exemptfine');
190 if (
191   $exemptfine &&
192   !C4::Auth::haspermission(C4::Context->userenv->{'id'}, {'updatecharges' => 'writeoff'})
193 ) {
194     # silently prevent unauthorized operator from forgiving overdue
195     # fines by manually tweaking form parameters
196     undef $exemptfine;
197 }
198 my $dropboxmode = $query->param('dropboxmode');
199 my $dotransfer  = $query->param('dotransfer');
200 my $canceltransfer = $query->param('canceltransfer');
201 my $dest = $query->param('dest');
202 my $calendar    = Koha::Calendar->new( branchcode => $userenv_branch );
203 #dropbox: get last open day (today - 1)
204 my $today       = DateTime->now( time_zone => C4::Context->tz());
205 my $dropboxdate = $calendar->addDate($today, -1);
206
207 my $return_date_override = $query->param('return_date_override');
208 my $return_date_override_remember =
209   $query->param('return_date_override_remember');
210 if ($return_date_override) {
211     if ( C4::Context->preference('SpecifyReturnDate') ) {
212         my $return_date_override_dt = eval {dt_from_string( $return_date_override ) };
213         if ( $return_date_override_dt ) {
214             # note that we've overriden the return date
215             $template->param( return_date_was_overriden => 1);
216             # Save the original format if we are remembering for this series
217             $template->param(
218                 return_date_override          => $return_date_override,
219                 return_date_override_remember => 1
220             ) if ($return_date_override_remember);
221
222             $return_date_override =
223               DateTime::Format::MySQL->format_datetime( $return_date_override_dt );
224         }
225     }
226     else {
227         $return_date_override = q{};
228     }
229 }
230
231 if ($dotransfer){
232 # An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer
233     my $transferitem = $query->param('transferitem');
234     my $tobranch     = $query->param('tobranch');
235     ModItemTransfer($transferitem, $userenv_branch, $tobranch);
236 }
237
238 if ($canceltransfer){
239     $itemnumber=$query->param('itemnumber');
240     DeleteTransfer($itemnumber);
241     if($dest eq "ttr"){
242         print $query->redirect("/cgi-bin/koha/circ/transferstoreceive.pl");
243         exit;
244     } else {
245         $template->param( transfercancelled => 1);
246     }
247 }
248
249 # actually return book and prepare item table.....
250 my $returnbranch;
251 if ($barcode) {
252     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
253     $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter');
254     $itemnumber = GetItemnumberFromBarcode($barcode);
255
256 #
257 # save the return
258 #
259
260     # get biblio description
261     my $biblio = GetBiblioFromItemNumber($itemnumber);
262     # fix up item type for display
263     $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'};
264
265     # Check if we should display a checkin message, based on the the item
266     # type of the checked in item
267     my $itemtype = Koha::ItemTypes->find( $biblio->{'itemtype'} );
268     if ( $itemtype && $itemtype->checkinmsg ) {
269         $template->param(
270             checkinmsg     => $itemtype->checkinmsg,
271             checkinmsgtype => $itemtype->checkinmsgtype,
272         );
273     }
274
275     # make sure return branch respects home branch circulation rules, default to homebranch
276     my $hbr = GetBranchItemRule($biblio->{'homebranch'}, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
277     $returnbranch = $biblio->{$hbr};
278
279     my $materials = $biblio->{'materials'};
280     my $avcode = GetAuthValCode('items.materials');
281     if ($avcode) {
282         $materials = GetKohaAuthorisedValueLib($avcode, $materials);
283     }
284
285     $template->param(
286         title            => $biblio->{'title'},
287         homebranch       => $biblio->{'homebranch'},
288         holdingbranch    => $biblio->{'holdingbranch'},
289         returnbranch     => $returnbranch,
290         author           => $biblio->{'author'},
291         itembarcode      => $biblio->{'barcode'},
292         itemtype         => $biblio->{'itemtype'},
293         ccode            => $biblio->{'ccode'},
294         itembiblionumber => $biblio->{'biblionumber'},
295         biblionumber     => $biblio->{'biblionumber'},
296         borrower         => $borrower,
297         additional_materials => $materials,
298     );
299
300     my %input = (
301         counter => 0,
302         first   => 1,
303         barcode => $barcode,
304     );
305
306     # do the return
307     ( $returned, $messages, $issueinformation, $borrower ) =
308       AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override, $dropboxdate );
309
310     if ($returned) {
311         my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
312         my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
313         $returneditems{0}      = $barcode;
314         $riborrowernumber{0}   = $borrower->{'borrowernumber'};
315         $riduedate{0}          = $duedate;
316         $input{borrowernumber} = $borrower->{'borrowernumber'};
317         $input{duedate}        = $duedate;
318         unless ( $dropboxmode ) {
319             $input{return_overdue} = 1 if (DateTime->compare($issueinformation->{date_due}, DateTime->now()) == -1);
320         } else {
321             $input{return_overdue} = 1 if (DateTime->compare($issueinformation->{date_due}, $dropboxdate) == -1);
322         }
323         push( @inputloop, \%input );
324
325         if ( C4::Context->preference("FineNotifyAtCheckin") ) {
326             my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrower->{'borrowernumber'} );
327             if ($fines && $fines > 0) {
328                 $template->param( fines => sprintf("%.2f",$fines) );
329                 $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
330             }
331         }
332
333         if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
334             #Check for waiting holds
335             my @reserves = GetReservesFromBorrowernumber($borrower->{'borrowernumber'});
336             my $waiting_holds = 0;
337             foreach my $num_res (@reserves) {
338                 if ( $num_res->{'found'} eq 'W' && $num_res->{'branchcode'} eq $userenv_branch) {
339                     $waiting_holds++;
340                 }
341             }
342             if ($waiting_holds > 0) {
343                 $template->param(
344                     waiting_holds       => $waiting_holds,
345                     holdsborrowernumber => $borrower->{'borrowernumber'},
346                     holdsfirstname => $borrower->{'firstname'},
347                     holdssurname => $borrower->{'surname'},
348                 );
349             }
350         }
351     } elsif ( C4::Context->preference('ShowAllCheckins') and !$messages->{'BadBarcode'} ) {
352         $input{duedate}   = 0;
353         $returneditems{0} = $barcode;
354         $riduedate{0}     = 0;
355         push( @inputloop, \%input );
356     }
357     $template->param( privacy => $borrower->{privacy} );
358 }
359 $template->param( inputloop => \@inputloop );
360
361 my $found    = 0;
362 my $waiting  = 0;
363 my $reserved = 0;
364
365 # new op dev : we check if the document must be returned to his homebranch directly,
366 #  if the document is transfered, we have warning message .
367
368 if ( $messages->{'WasTransfered'} ) {
369     $template->param(
370         found          => 1,
371         transfer       => 1,
372         itemnumber     => $itemnumber,
373     );
374 }
375
376 if ( $messages->{'NeedsTransfer'} ){
377     $template->param(
378         found          => 1,
379         needstransfer  => $messages->{'NeedsTransfer'},
380         itemnumber     => $itemnumber,
381     );
382 }
383
384 if ( $messages->{'Wrongbranch'} ){
385     $template->param(
386         wrongbranch => 1,
387         rightbranch => $messages->{'Wrongbranch'}->{'Rightbranch'},
388     );
389 }
390
391 # case of wrong transfert, if the document wasn't transfered to the right library (according to branchtransfer (tobranch) BDD)
392
393 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
394     $template->param(
395         WrongTransfer  => 1,
396         TransferWaitingAt => $messages->{'WrongTransfer'},
397         WrongTransferItem => $messages->{'WrongTransferItem'},
398         itemnumber => $itemnumber,
399     );
400
401     my $reserve    = $messages->{'ResFound'};
402     my $borr = C4::Members::GetMember( borrowernumber => $reserve->{'borrowernumber'} );
403     my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
404     $template->param(
405             wname           => $name,
406             wborfirstname   => $borr->{'firstname'},
407             wborsurname     => $borr->{'surname'},
408             wbortitle       => $borr->{'title'},
409             wborphone       => $borr->{'phone'},
410             wboremail       => $borr->{'email'},
411             wborstnum       => $borr->{streetnumber},
412             wboraddress     => $borr->{'address'},
413             wboraddress2    => $borr->{'address2'},
414             wborcity        => $borr->{'city'},
415             wborzip         => $borr->{'zipcode'},
416             wborrowernumber => $reserve->{'borrowernumber'},
417             wborcnum        => $borr->{'cardnumber'},
418             wtransfertFrom  => $userenv_branch,
419     );
420 }
421
422 #
423 # reserve found and item arrived at the expected branch
424 #
425 if ( $messages->{'ResFound'}) {
426     my $reserve    = $messages->{'ResFound'};
427     my $borr = C4::Members::GetMember( borrowernumber => $reserve->{'borrowernumber'} );
428     my $holdmsgpreferences =  C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name   => 'Hold_Filled' } );
429     if ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
430         if ( $reserve->{'ResFound'} eq "Waiting" ) {
431             $template->param(
432                 waiting      => ($userenv_branch eq $reserve->{'branchcode'} ? 1 : 0 ),
433             );
434         } elsif ( $reserve->{'ResFound'} eq "Reserved" ) {
435             $template->param(
436                 intransit    => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
437                 transfertodo => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
438                 reserve_id   => $reserve->{reserve_id},
439                 reserved     => 1,
440             );
441         }
442
443         # same params for Waiting or Reserved
444         $template->param(
445             found          => 1,
446             name           => $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'},
447             borfirstname   => $borr->{'firstname'},
448             borsurname     => $borr->{'surname'},
449             bortitle       => $borr->{'title'},
450             borphone       => $borr->{'phone'},
451             boremail       => $borr->{'email'},
452             boraddress     => $borr->{'address'},
453             boraddress2    => $borr->{'address2'},
454             borstnum       => $borr->{streetnumber},
455             borcity        => $borr->{'city'},
456             borzip         => $borr->{'zipcode'},
457             borcnum        => $borr->{'cardnumber'},
458             debarred       => $borr->{'debarred'},
459             gonenoaddress  => $borr->{'gonenoaddress'},
460             barcode        => $barcode,
461             destbranch     => $reserve->{'branchcode'},
462             borrowernumber => $reserve->{'borrowernumber'},
463             itemnumber     => $reserve->{'itemnumber'},
464             reservenotes   => $reserve->{'reservenotes'},
465             bormessagepref => $holdmsgpreferences->{'transports'},
466         );
467     } # else { ; }  # error?
468 }
469
470 # Error Messages
471 my @errmsgloop;
472 foreach my $code ( keys %$messages ) {
473     my %err;
474     my $exit_required_p = 0;
475     if ( $code eq 'BadBarcode' ) {
476         $err{badbarcode} = 1;
477         $err{msg}        = $messages->{'BadBarcode'};
478     }
479     elsif ( $code eq 'NotIssued' ) {
480         $err{notissued} = 1;
481         $err{msg} = '';
482         $err{msg} = $messages->{'IsPermanent'} if $messages->{'IsPermanent'};
483     }
484     elsif ( $code eq 'LocalUse' ) {
485         $err{localuse} = 1;
486     }
487     elsif ( $code eq 'WasLost' ) {
488         $err{waslost} = 1;
489     }
490     elsif ( $code eq 'LostItemFeeRefunded' ) {
491         $template->param( LostItemFeeRefunded => 1 );
492     }
493     elsif ( $code eq 'ResFound' ) {
494         ;    # FIXME... anything to do here?
495     }
496     elsif ( $code eq 'WasReturned' ) {
497         ;    # FIXME... anything to do here?
498     }
499     elsif ( $code eq 'WasTransfered' ) {
500         ;    # FIXME... anything to do here?
501     }
502     elsif ( $code eq 'withdrawn' ) {
503         $err{withdrawn} = 1;
504         $exit_required_p = 1 if C4::Context->preference("BlockReturnOfWithdrawnItems");
505     }
506     elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
507         if ( $messages->{'IsPermanent'} ne $userenv_branch ) {
508             $err{ispermanent} = 1;
509             $err{msg}         = $messages->{'IsPermanent'};
510         }
511     }
512     elsif ( $code eq 'WrongTransfer' ) {
513         ;    # FIXME... anything to do here?
514     }
515     elsif ( $code eq 'WrongTransferItem' ) {
516         ;    # FIXME... anything to do here?
517     }
518     elsif ( $code eq 'NeedsTransfer' ) {
519     }
520     elsif ( $code eq 'Wrongbranch' ) {
521     }
522     elsif ( $code eq 'Debarred' ) {
523         $err{debarred}            = $messages->{'Debarred'};
524         $err{debarcardnumber}     = $borrower->{cardnumber};
525         $err{debarborrowernumber} = $borrower->{borrowernumber};
526         $err{debarname}           = "$borrower->{firstname} $borrower->{surname}";
527     }
528     elsif ( $code eq 'PrevDebarred' ) {
529         $err{prevdebarred}        = $messages->{'PrevDebarred'};
530     }
531     elsif ( $code eq 'ForeverDebarred' ) {
532         $err{foreverdebarred}        = $messages->{'ForeverDebarred'};
533     }
534     elsif ( $code eq 'NotForLoanStatusUpdated' ) {
535         $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
536     }
537     else {
538         die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
539         # This forces the issue of staying in sync w/ Circulation.pm
540     }
541     if (%err) {
542         push( @errmsgloop, \%err );
543     }
544     last if $exit_required_p;
545 }
546 $template->param( errmsgloop => \@errmsgloop );
547
548 #set up so only the last 8 returned items display (make for faster loading pages)
549 my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C4::Context->preference('numReturnedItemsToShow') : 8;
550 my $count = 0;
551 my @riloop;
552 my $shelflocations = GetKohaAuthorisedValues('items.location','');
553 foreach ( sort { $a <=> $b } keys %returneditems ) {
554     my %ri;
555     if ( $count++ < $returned_counter ) {
556         my $bar_code = $returneditems{$_};
557         if ($riduedate{$_}) {
558             my $duedate = dt_from_string( $riduedate{$_}, 'sql');
559             $ri{year}  = $duedate->year();
560             $ri{month} = $duedate->month();
561             $ri{day}   = $duedate->day();
562             $ri{hour}   = $duedate->hour();
563             $ri{minute}   = $duedate->minute();
564             $ri{duedate} = output_pref($duedate);
565             my $b      = C4::Members::GetMember( borrowernumber => $riborrowernumber{$_} );
566             unless ( $dropboxmode ) {
567                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, DateTime->now()) == -1);
568             } else {
569                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, $dropboxdate) == -1);
570             }
571             $ri{borrowernumber} = $b->{'borrowernumber'};
572             $ri{borcnum}        = $b->{'cardnumber'};
573             $ri{borfirstname}   = $b->{'firstname'};
574             $ri{borsurname}     = $b->{'surname'};
575             $ri{bortitle}       = $b->{'title'};
576             $ri{bornote}        = $b->{'borrowernotes'};
577             $ri{borcategorycode}= $b->{'categorycode'};
578         }
579         else {
580             $ri{borrowernumber} = $riborrowernumber{$_};
581         }
582
583         #        my %ri;
584         my $biblio = GetBiblioFromItemNumber(GetItemnumberFromBarcode($bar_code));
585         my $item   = GetItem( GetItemnumberFromBarcode($bar_code) );
586         # fix up item type for display
587         $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'};
588         $ri{itembiblionumber}    = $biblio->{'biblionumber'};
589         $ri{itemtitle}           = $biblio->{'title'};
590         $ri{itemauthor}          = $biblio->{'author'};
591         $ri{itemcallnumber}      = $biblio->{'itemcallnumber'};
592         $ri{dateaccessioned}     = $item->{dateaccessioned};
593         $ri{itemtype}            = $biblio->{'itemtype'};
594         $ri{itemnote}            = $biblio->{'itemnotes'};
595         $ri{itemnotes_nonpublic} = $item->{'itemnotes_nonpublic'};
596         $ri{ccode}               = $biblio->{'ccode'};
597         $ri{enumchron}           = $biblio->{'enumchron'};
598         $ri{itemnumber}          = $biblio->{'itemnumber'};
599         $ri{barcode}             = $bar_code;
600         $ri{homebranch}          = $item->{'homebranch'};
601         $ri{holdingbranch}       = $item->{'holdingbranch'};
602
603         $ri{location}         = $biblio->{'location'};
604         my $shelfcode = $ri{'location'};
605         $ri{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
606
607     }
608     else {
609         last;
610     }
611     push @riloop, \%ri;
612 }
613
614 $template->param(
615     riloop         => \@riloop,
616     printer        => $printer,
617     errmsgloop     => \@errmsgloop,
618     exemptfine     => $exemptfine,
619     dropboxmode    => $dropboxmode,
620     dropboxdate    => output_pref($dropboxdate),
621     forgivemanualholdsexpire => $forgivemanualholdsexpire,
622     overduecharges => $overduecharges,
623     AudioAlerts        => C4::Context->preference("AudioAlerts"),
624     BlockReturnOfWithdrawnItems => C4::Context->preference("BlockReturnOfWithdrawnItems"),
625 );
626
627 $itemnumber = GetItemnumberFromBarcode( $barcode );
628 if ( $itemnumber ) {
629     my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
630     if ( $holdingBranch and $collectionBranch ) {
631         $holdingBranch //= '';
632         $collectionBranch //= $returnbranch;
633         if ( ! ( $holdingBranch eq $collectionBranch ) ) {
634             $template->param(
635               collectionItemNeedsTransferred => 1,
636               collectionBranch => $collectionBranch,
637               itemnumber => $itemnumber,
638             );
639         }
640     }
641 }
642
643 # actually print the page!
644 output_html_with_http_headers $query, $cookie, $template->output;