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