Bug 21746: Remove NO_LIBRARY_SET
[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 Modern::Perl;
31
32 # FIXME There are weird things going on with $patron and $borrowernumber in this script
33
34 use CGI qw ( -utf8 );
35 use DateTime;
36
37 use C4::Auth qw/:DEFAULT get_session/;
38 use C4::Biblio;
39 use C4::Circulation;
40 use C4::Context;
41 use C4::Items;
42 use C4::Koha;   # FIXME : is it still useful ?
43 use C4::Members::Messaging;
44 use C4::Members;
45 use C4::Output;
46 use C4::Print;
47 use C4::Reserves;
48 use C4::RotatingCollections;
49 use Koha::AuthorisedValues;
50 use Koha::BiblioFrameworks;
51 use Koha::Calendar;
52 use Koha::Checkouts;
53 use Koha::DateUtils;
54 use Koha::Holds;
55 use Koha::Items;
56 use Koha::Patrons;
57
58 my $query = new CGI;
59
60 #getting the template
61 my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
62     {
63         template_name   => "circ/returns.tt",
64         query           => $query,
65         type            => "intranet",
66         authnotrequired => 0,
67         flagsrequired   => { circulate => "circulate_remaining_permissions" },
68     }
69 );
70
71 my $sessionID = $query->cookie("CGISESSID");
72 my $session = get_session($sessionID);
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'), # FIXME We should send a Koha::Patron and raise an error if not exist.
79         biblionumber   => scalar $query->param('biblionumber'),
80         itemnumber     => scalar $query->param('itemnumber'),
81     );
82 }
83
84 #####################
85 #Global vars
86 my $printers = GetPrinters();
87 my $userenv = C4::Context->userenv;
88 my $userenv_branch = $userenv->{'branch'} // '';
89 my $printer = $userenv->{'branchprinter'} // '';
90 my $forgivemanualholdsexpire = $query->param('forgivemanualholdsexpire');
91
92 my $overduecharges = (C4::Context->preference('finesMode') && C4::Context->preference('finesMode') ne 'off');
93  #
94 # Some code to handle the error if there is no branch or printer setting.....
95 #
96
97 # Set up the item stack ....
98 my %returneditems;
99 my %riduedate;
100 my %riborrowernumber;
101 my @inputloop;
102 foreach ( $query->param ) {
103     my $counter;
104     if (/ri-(\d*)/) {
105         $counter = $1;
106         if ($counter > 20) {
107             next;
108         }
109     }
110     else {
111         next;
112     }
113
114     my %input;
115     my $barcode        = $query->param("ri-$counter");
116     my $duedate        = $query->param("dd-$counter");
117     my $borrowernumber = $query->param("bn-$counter");
118     $counter++;
119
120     # decode barcode    ## Didn't we already decode them before passing them back last time??
121     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
122     $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter'));
123
124     ######################
125     #Are these lines still useful ?
126     $returneditems{$counter}    = $barcode;
127     $riduedate{$counter}        = $duedate;
128     $riborrowernumber{$counter} = $borrowernumber;
129
130     #######################
131     $input{counter}        = $counter;
132     $input{barcode}        = $barcode;
133     $input{duedate}        = $duedate;
134     $input{borrowernumber} = $borrowernumber;
135     push( @inputloop, \%input );
136 }
137
138 ############
139 # Deal with the requests....
140
141 if ($query->param('WT-itemNumber')){
142         updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From'));
143 }
144
145 if ( $query->param('reserve_id') ) {
146     my $itemnumber     = $query->param('itemnumber');
147     my $borrowernumber = $query->param('borrowernumber');
148     my $reserve_id     = $query->param('reserve_id');
149     my $diffBranchReturned = $query->param('diffBranch');
150     my $cancel_reserve = $query->param('cancel_reserve');
151     # fix up item type for display
152     my $item = Koha::Items->find( $itemnumber );
153     my $biblio = $item->biblio;
154
155     if ( $cancel_reserve ) {
156         my $hold = Koha::Holds->find( $reserve_id );
157         if ( $hold ) {
158             $hold->cancel( { charge_cancel_fee => !$forgivemanualholdsexpire } );
159         } # FIXME else?
160     } else {
161         my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
162         # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
163         # i.e., whether to apply waiting status
164         ModReserveAffect( $itemnumber, $borrowernumber, $diffBranchSend, $reserve_id );
165     }
166 #   check if we have other reserves for this document, if we have a return send the message of transfer
167     my ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
168
169     my $patron = Koha::Patrons->find( $nextreservinfo );
170     my $name   = $patron ? $patron->surname . ", " . $patron->title . " " . $patron->firstname : '';
171     if ( $messages->{'transfert'} ) {
172         $template->param(
173             itemtitle      => $biblio->title,
174             itemnumber     => $item->itemnumber,
175             itembiblionumber => $biblio->biblionumber,
176             iteminfo       => $biblio->author,
177             name           => $name,
178             patron         => $patron,
179             diffbranch     => 1,
180         );
181     }
182 }
183
184 my $borrower;
185 my $returned = 0;
186 my $messages;
187 my $issue;
188 my $itemnumber;
189 my $barcode     = $query->param('barcode');
190 my $exemptfine  = $query->param('exemptfine');
191 if (
192   $exemptfine &&
193   !C4::Auth::haspermission(C4::Context->userenv->{'id'}, {'updatecharges' => 'writeoff'})
194 ) {
195     # silently prevent unauthorized operator from forgiving overdue
196     # fines by manually tweaking form parameters
197     undef $exemptfine;
198 }
199 my $dropboxmode = $query->param('dropboxmode');
200 my $dotransfer  = $query->param('dotransfer');
201 my $canceltransfer = $query->param('canceltransfer');
202 my $dest = $query->param('dest');
203 #dropbox: get last open day (today - 1)
204 my $dropboxdate = Koha::Checkouts::calculate_dropbox_date();
205
206 my $return_date_override = $query->param('return_date_override');
207 my $return_date_override_dt;
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         $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     my $item = Koha::Items->find({ barcode => $barcode });
255
256     if ( $item ) {
257         $itemnumber = $item->itemnumber;
258         # Check if we should display a checkin message, based on the the item
259         # type of the checked in item
260         my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
261         if ( $itemtype && $itemtype->checkinmsg ) {
262             $template->param(
263                 checkinmsg     => $itemtype->checkinmsg,
264                 checkinmsgtype => $itemtype->checkinmsgtype,
265             );
266         }
267
268         # make sure return branch respects home branch circulation rules, default to homebranch
269         my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
270         $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch
271
272         my $materials = $item->materials;
273         my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
274         $materials = $descriptions->{lib} // $materials;
275
276         my $checkout = $item->checkout;
277         my $biblio   = $item->biblio;
278         $template->param(
279             title            => $biblio->title,
280             homebranch       => $item->homebranch,
281             holdingbranch    => $item->holdingbranch,
282             returnbranch     => $returnbranch,
283             author           => $biblio->author,
284             itembarcode      => $item->barcode,
285             itemtype         => $item->effective_itemtype,
286             ccode            => $item->ccode,
287             itembiblionumber => $biblio->biblionumber,
288             biblionumber     => $biblio->biblionumber,
289             additional_materials => $materials,
290             issue            => $checkout,
291         );
292     } # FIXME else we should not call AddReturn but set BadBarcode directly instead
293
294     my %input = (
295         counter => 0,
296         first   => 1,
297         barcode => $barcode,
298     );
299
300     my $return_date = $dropboxmode ? $dropboxdate : $return_date_override_dt;
301
302     # do the return
303     ( $returned, $messages, $issue, $borrower ) =
304       AddReturn( $barcode, $userenv_branch, $exemptfine, $return_date );
305
306     if ($returned) {
307         my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
308         my $date_due_dt = dt_from_string( $issue->date_due, 'sql' );
309         my $duedate = $date_due_dt->strftime('%Y-%m-%d %H:%M');
310         $returneditems{0}      = $barcode;
311         $riborrowernumber{0}   = $borrower->{'borrowernumber'};
312         $riduedate{0}          = $duedate;
313         $input{borrowernumber} = $borrower->{'borrowernumber'};
314         $input{duedate}        = $duedate;
315         unless ( $dropboxmode ) {
316             $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, DateTime->now()) == -1);
317         } else {
318             $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, $dropboxdate) == -1);
319         }
320         push( @inputloop, \%input );
321
322         if ( C4::Context->preference("FineNotifyAtCheckin") ) {
323             my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
324             my $balance = $patron->account->balance;
325
326             if ($balance > 0) {
327                 $template->param( fines => sprintf("%.2f", $balance) );
328                 $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
329             }
330         }
331
332         if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
333             #Check for waiting holds
334             my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
335             my $waiting_holds = $patron->holds->search({ found => 'W', branchcode => $userenv_branch })->count;
336             if ($waiting_holds > 0) {
337                 $template->param(
338                     waiting_holds       => $waiting_holds,
339                     holdsborrowernumber => $borrower->{'borrowernumber'},
340                     holdsfirstname => $borrower->{'firstname'},
341                     holdssurname => $borrower->{'surname'},
342                 );
343             }
344         }
345     } elsif ( C4::Context->preference('ShowAllCheckins') and !$messages->{'BadBarcode'} ) {
346         $input{duedate}   = 0;
347         $returneditems{0} = $barcode;
348         $riduedate{0}     = 0;
349         push( @inputloop, \%input );
350     }
351     $template->param( privacy => $borrower->{privacy} );
352 }
353 $template->param( inputloop => \@inputloop );
354
355 my $found    = 0;
356 my $waiting  = 0;
357 my $reserved = 0;
358
359 # new op dev : we check if the document must be returned to his homebranch directly,
360 #  if the document is transferred, we have warning message .
361
362 if ( $messages->{'WasTransfered'} ) {
363     $template->param(
364         found          => 1,
365         transfer       => 1,
366         itemnumber     => $itemnumber,
367     );
368 }
369
370 if ( $messages->{'NeedsTransfer'} ){
371     $template->param(
372         found          => 1,
373         needstransfer  => $messages->{'NeedsTransfer'},
374         itemnumber     => $itemnumber,
375     );
376 }
377
378 if ( $messages->{'Wrongbranch'} ){
379     $template->param(
380         wrongbranch => 1,
381         rightbranch => $messages->{'Wrongbranch'}->{'Rightbranch'},
382     );
383 }
384
385 # case of wrong transfert, if the document wasn't transferred to the right library (according to branchtransfer (tobranch) BDD)
386
387 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
388     $template->param(
389         WrongTransfer  => 1,
390         TransferWaitingAt => $messages->{'WrongTransfer'},
391         WrongTransferItem => $messages->{'WrongTransferItem'},
392         itemnumber => $itemnumber,
393     );
394
395     my $reserve    = $messages->{'ResFound'};
396     if ( $reserve ) {
397         my $patron = Koha::Patrons->find( $reserve->{'borrowernumber'} );
398         my $name = $patron->surname . ", " . $patron->title . " " . $patron->firstname;
399         $template->param(
400             patron => $patron,
401         );
402     }
403     $template->param(
404         wtransfertFrom  => $userenv_branch,
405     );
406 }
407
408 #
409 # reserve found and item arrived at the expected branch
410 #
411 if ( $messages->{'ResFound'}) {
412     my $reserve    = $messages->{'ResFound'};
413     my $patron = Koha::Patrons->find( $reserve->{borrowernumber} );
414     my $holdmsgpreferences =  C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name   => 'Hold_Filled' } );
415     my $branchCheck = ( $userenv_branch eq $reserve->{branchcode} );
416     if ( $reserve->{'ResFound'} eq "Reserved" && C4::Context->preference('HoldsAutoFill') ) {
417         my $item = Koha::Items->find( $itemnumber );
418         my $biblio = $item->biblio;
419
420         my $diffBranchSend = !$branchCheck ? $reserve->{branchcode} : undef;
421         ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber}, $diffBranchSend, $reserve->{reserve_id} );
422         my ( $messages, $nextreservinfo ) = GetOtherReserves($reserve->{itemnumber});
423
424         my $patron = Koha::Patrons->find( $nextreservinfo );
425
426         $template->param(
427             hold_auto_filled => 1,
428             print_slip       => C4::Context->preference('HoldsAutoFillPrintSlip'),
429             patron           => $patron,
430             borrowernumber   => $patron->id,
431             biblionumber     => $biblio->id,
432         );
433
434         if ( $messages->{'transfert'} ) {
435             $template->param(
436                 itemtitle      => $biblio->title,
437                 itemnumber     => $item->itemnumber,
438                 itembiblionumber => $biblio->biblionumber,
439                 iteminfo       => $biblio->author,
440                 diffbranch     => 1,
441             );
442         }
443     }
444     elsif ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
445         if ( $reserve->{'ResFound'} eq "Waiting" ) {
446             $template->param(
447                 waiting      => $branchCheck ? 1 : undef,
448             );
449         } elsif ( $reserve->{'ResFound'} eq "Reserved" ) {
450             $template->param(
451                 intransit    => $branchCheck ? undef : 1,
452                 transfertodo => $branchCheck ? undef : 1,
453                 reserve_id   => $reserve->{reserve_id},
454                 reserved     => 1,
455             );
456         }
457
458     } # else { ; }  # error?
459
460     # same params for Waiting or Reserved
461     $template->param(
462         found          => 1,
463         patron         => $patron,
464         barcode        => $barcode,
465         destbranch     => $reserve->{'branchcode'},
466         itemnumber     => $reserve->{'itemnumber'},
467         reservenotes   => $reserve->{'reservenotes'},
468         reserve_id     => $reserve->{reserve_id},
469         bormessagepref => $holdmsgpreferences->{'transports'},
470     );
471 }
472
473 # Error Messages
474 my @errmsgloop;
475 foreach my $code ( keys %$messages ) {
476     my %err;
477     my $exit_required_p = 0;
478     if ( $code eq 'BadBarcode' ) {
479         $err{badbarcode} = 1;
480         $err{msg}        = $messages->{'BadBarcode'};
481     }
482     elsif ( $code eq 'NotIssued' ) {
483         $err{notissued} = 1;
484         $err{msg} = '';
485     }
486     elsif ( $code eq 'LocalUse' ) {
487         $err{localuse} = 1;
488     }
489     elsif ( $code eq 'WasLost' ) {
490         $err{waslost} = 1;
491         $exit_required_p = 1 if C4::Context->preference("BlockReturnOfLostItems");
492     }
493     elsif ( $code eq 'LostItemFeeRefunded' ) {
494         $template->param( LostItemFeeRefunded => 1 );
495     }
496     elsif ( $code eq 'ResFound' ) {
497         ;    # FIXME... anything to do here?
498     }
499     elsif ( $code eq 'WasReturned' ) {
500         ;    # FIXME... anything to do here?
501     }
502     elsif ( $code eq 'WasTransfered' ) {
503         ;    # FIXME... anything to do here?
504     }
505     elsif ( $code eq 'withdrawn' ) {
506         $err{withdrawn} = 1;
507         $exit_required_p = 1 if C4::Context->preference("BlockReturnOfWithdrawnItems");
508     }
509     elsif ( $code eq 'WrongTransfer' ) {
510         ;    # FIXME... anything to do here?
511     }
512     elsif ( $code eq 'WrongTransferItem' ) {
513         ;    # FIXME... anything to do here?
514     }
515     elsif ( $code eq 'NeedsTransfer' ) {
516     }
517     elsif ( $code eq 'Wrongbranch' ) {
518     }
519     elsif ( $code eq 'Debarred' ) {
520         $err{debarred}            = $messages->{'Debarred'};
521         $err{debarcardnumber}     = $borrower->{cardnumber};
522         $err{debarborrowernumber} = $borrower->{borrowernumber};
523         $err{debarname}           = "$borrower->{firstname} $borrower->{surname}";
524     }
525     elsif ( $code eq 'PrevDebarred' ) {
526         $err{prevdebarred}        = $messages->{'PrevDebarred'};
527     }
528     elsif ( $code eq 'ForeverDebarred' ) {
529         $err{foreverdebarred}        = $messages->{'ForeverDebarred'};
530     }
531     elsif ( $code eq 'ItemLocationUpdated' ) {
532         $err{ItemLocationUpdated} = $messages->{ItemLocationUpdated};
533     }
534     elsif ( $code eq 'NotForLoanStatusUpdated' ) {
535         $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
536     }
537     elsif ( $code eq 'DataCorrupted' ) {
538         $err{data_corrupted} = 1;
539     }
540     elsif ( $code eq 'ReturnClaims' ) {
541         $template->param( ReturnClaims => $messages->{ReturnClaims} );
542     } else {
543         die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
544         # This forces the issue of staying in sync w/ Circulation.pm
545     }
546     if (%err) {
547         push( @errmsgloop, \%err );
548     }
549     last if $exit_required_p;
550 }
551 $template->param( errmsgloop => \@errmsgloop );
552
553 #set up so only the last 8 returned items display (make for faster loading pages)
554 my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C4::Context->preference('numReturnedItemsToShow') : 8;
555 my $count = 0;
556 my @riloop;
557 my $shelflocations =
558   { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) };
559 foreach ( sort { $a <=> $b } keys %returneditems ) {
560     my %ri;
561     if ( $count++ < $returned_counter ) {
562         my $bar_code = $returneditems{$_};
563         if ($riduedate{$_}) {
564             my $duedate = dt_from_string( $riduedate{$_}, 'sql');
565             $ri{year}  = $duedate->year();
566             $ri{month} = $duedate->month();
567             $ri{day}   = $duedate->day();
568             $ri{hour}   = $duedate->hour();
569             $ri{minute}   = $duedate->minute();
570             $ri{duedate} = output_pref($duedate);
571             my $patron = Koha::Patrons->find( $riborrowernumber{$_} );
572             unless ( $dropboxmode ) {
573                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, DateTime->now()) == -1);
574             } else {
575                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, $dropboxdate) == -1);
576             }
577             $ri{patron} = $patron,
578             $ri{borissuescount} = $patron->checkouts->count;
579         }
580         else {
581             $ri{borrowernumber} = $riborrowernumber{$_};
582         }
583
584         my $item = Koha::Items->find({ barcode => $bar_code });
585         next unless $item; # FIXME The item has been deleted in the meantime,
586                            # we could handle that better displaying a message in the template
587
588         my $biblio = $item->biblio;
589         # FIXME pass $item to the template and we are done here...
590         $ri{itembiblionumber}    = $biblio->biblionumber;
591         $ri{itemtitle}           = $biblio->title;
592         $ri{subtitle}            = $biblio->subtitle;
593         $ri{part_name}           = $biblio->part_name;
594         $ri{part_number}         = $biblio->part_number;
595         $ri{itemauthor}          = $biblio->author;
596         $ri{itemcallnumber}      = $item->itemcallnumber;
597         $ri{dateaccessioned}     = $item->dateaccessioned;
598         $ri{recordtype}          = $biblio->itemtype;
599         $ri{itemtype}            = $item->itype;
600         $ri{itemnote}            = $item->itemnotes;
601         $ri{itemnotes_nonpublic} = $item->itemnotes_nonpublic;
602         $ri{ccode}               = $item->ccode;
603         $ri{enumchron}           = $item->enumchron;
604         $ri{itemnumber}          = $item->itemnumber;
605         $ri{barcode}             = $bar_code;
606         $ri{homebranch}          = $item->homebranch;
607         $ri{holdingbranch}       = $item->holdingbranch;
608
609         $ri{location} = $item->location;
610         my $shelfcode = $ri{'location'};
611         $ri{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
612
613     }
614     else {
615         last;
616     }
617     push @riloop, \%ri;
618 }
619
620 $template->param(
621     riloop         => \@riloop,
622     printer        => $printer,
623     errmsgloop     => \@errmsgloop,
624     exemptfine     => $exemptfine,
625     dropboxmode    => $dropboxmode,
626     dropboxdate    => $dropboxdate,
627     forgivemanualholdsexpire => $forgivemanualholdsexpire,
628     overduecharges => $overduecharges,
629     AudioAlerts        => C4::Context->preference("AudioAlerts"),
630 );
631
632 if ( $barcode ) {
633     my $item_from_barcode = Koha::Items->find({barcode => $barcode }); # How many times do we fetch this item?!?
634     if ( $item_from_barcode ) {
635         $itemnumber = $item_from_barcode->itemnumber;
636         my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
637         if ( $holdingBranch and $collectionBranch ) {
638             $holdingBranch //= '';
639             $collectionBranch //= $returnbranch;
640             if ( ! ( $holdingBranch eq $collectionBranch ) ) {
641                 $template->param(
642                   collectionItemNeedsTransferred => 1,
643                   collectionBranch => $collectionBranch,
644                   itemnumber => $itemnumber,
645                 );
646             }
647         }
648     }
649 }
650
651 # Checking if there is a Fast Cataloging Framework
652 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
653
654 # actually print the page!
655 output_html_with_http_headers $query, $cookie, $template->output;