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