Bug 17845: Remove unused code related to printers
[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::Output;
39 use C4::Circulation;
40 use C4::Reserves;
41 use C4::Biblio;
42 use C4::Circulation;
43 use C4::Context;
44 use C4::Items;
45 use C4::Koha;   # FIXME : is it still useful ?
46 use C4::Members::Messaging;
47 use C4::Members;
48 use C4::Output;
49 use C4::Reserves;
50 use C4::RotatingCollections;
51 use Koha::AuthorisedValues;
52 use Koha::BiblioFrameworks;
53 use Koha::Calendar;
54 use Koha::Checkouts;
55 use Koha::DateUtils;
56 use Koha::Holds;
57 use Koha::Items;
58 use Koha::Patrons;
59
60 my $query = new CGI;
61
62 #getting the template
63 my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
64     {
65         template_name   => "circ/returns.tt",
66         query           => $query,
67         type            => "intranet",
68         authnotrequired => 0,
69         flagsrequired   => { circulate => "circulate_remaining_permissions" },
70     }
71 );
72
73 my $sessionID = $query->cookie("CGISESSID");
74 my $session = get_session($sessionID);
75
76 # Print a reserve slip on this page
77 if ( $query->param('print_slip') ) {
78     $template->param(
79         print_slip     => 1,
80         borrowernumber => scalar $query->param('borrowernumber'), # FIXME We should send a Koha::Patron and raise an error if not exist.
81         biblionumber   => scalar $query->param('biblionumber'),
82         itemnumber     => scalar $query->param('itemnumber'),
83     );
84 }
85
86 #####################
87 #Global vars
88 my $userenv = C4::Context->userenv;
89 my $userenv_branch = $userenv->{'branch'} // '';
90 my $forgivemanualholdsexpire = $query->param('forgivemanualholdsexpire');
91
92 my $overduecharges = (C4::Context->preference('finesMode') && C4::Context->preference('finesMode') ne 'off');
93
94 # Set up the item stack ....
95 my %returneditems;
96 my %riduedate;
97 my %riborrowernumber;
98 my @inputloop;
99 foreach ( $query->param ) {
100     my $counter;
101     if (/ri-(\d*)/) {
102         $counter = $1;
103         if ($counter > 20) {
104             next;
105         }
106     }
107     else {
108         next;
109     }
110
111     my %input;
112     my $barcode        = $query->param("ri-$counter");
113     my $duedate        = $query->param("dd-$counter");
114     my $borrowernumber = $query->param("bn-$counter");
115     $counter++;
116
117     # decode barcode    ## Didn't we already decode them before passing them back last time??
118     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
119     $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter'));
120
121     ######################
122     #Are these lines still useful ?
123     $returneditems{$counter}    = $barcode;
124     $riduedate{$counter}        = $duedate;
125     $riborrowernumber{$counter} = $borrowernumber;
126
127     #######################
128     $input{counter}        = $counter;
129     $input{barcode}        = $barcode;
130     $input{duedate}        = $duedate;
131     $input{borrowernumber} = $borrowernumber;
132     push( @inputloop, \%input );
133 }
134
135 ############
136 # Deal with the requests....
137
138 if ($query->param('WT-itemNumber')){
139         updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From'));
140 }
141
142 if ( $query->param('reserve_id') ) {
143     my $itemnumber     = $query->param('itemnumber');
144     my $borrowernumber = $query->param('borrowernumber');
145     my $reserve_id     = $query->param('reserve_id');
146     my $diffBranchReturned = $query->param('diffBranch');
147     my $cancel_reserve = $query->param('cancel_reserve');
148     # fix up item type for display
149     my $item = Koha::Items->find( $itemnumber );
150     my $biblio = $item->biblio;
151
152     if ( $cancel_reserve ) {
153         my $hold = Koha::Holds->find( $reserve_id );
154         if ( $hold ) {
155             $hold->cancel( { charge_cancel_fee => !$forgivemanualholdsexpire } );
156         } # FIXME else?
157     } else {
158         my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
159         # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
160         # i.e., whether to apply waiting status
161         ModReserveAffect( $itemnumber, $borrowernumber, $diffBranchSend, $reserve_id );
162     }
163 #   check if we have other reserves for this document, if we have a return send the message of transfer
164     my ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
165
166     my $patron = Koha::Patrons->find( $nextreservinfo );
167     my $name   = $patron ? $patron->surname . ", " . $patron->title . " " . $patron->firstname : '';
168     if ( $messages->{'transfert'} ) {
169         $template->param(
170             itemtitle      => $biblio->title,
171             itemnumber     => $item->itemnumber,
172             itembiblionumber => $biblio->biblionumber,
173             iteminfo       => $biblio->author,
174             name           => $name,
175             patron         => $patron,
176             diffbranch     => 1,
177         );
178     }
179 }
180
181 my $borrower;
182 my $returned = 0;
183 my $messages;
184 my $issue;
185 my $itemnumber;
186 my $barcode     = $query->param('barcode');
187 my $exemptfine  = $query->param('exemptfine');
188 if (
189   $exemptfine &&
190   !C4::Auth::haspermission(C4::Context->userenv->{'id'}, {'updatecharges' => 'writeoff'})
191 ) {
192     # silently prevent unauthorized operator from forgiving overdue
193     # fines by manually tweaking form parameters
194     undef $exemptfine;
195 }
196 my $dropboxmode = $query->param('dropboxmode');
197 my $dotransfer  = $query->param('dotransfer');
198 my $canceltransfer = $query->param('canceltransfer');
199 my $dest = $query->param('dest');
200 #dropbox: get last open day (today - 1)
201 my $dropboxdate = Koha::Checkouts::calculate_dropbox_date();
202
203 my $return_date_override = $query->param('return_date_override');
204 my $return_date_override_dt;
205 my $return_date_override_remember =
206   $query->param('return_date_override_remember');
207 if ($return_date_override) {
208     if ( C4::Context->preference('SpecifyReturnDate') ) {
209         $return_date_override_dt = eval {dt_from_string( $return_date_override ) };
210         if ( $return_date_override_dt ) {
211             # note that we've overriden the return date
212             $template->param( return_date_was_overriden => 1);
213             # Save the original format if we are remembering for this series
214             $template->param(
215                 return_date_override          => $return_date_override,
216                 return_date_override_remember => 1
217             ) if ($return_date_override_remember);
218
219             $return_date_override =
220               DateTime::Format::MySQL->format_datetime( $return_date_override_dt );
221         }
222     }
223     else {
224         $return_date_override = q{};
225     }
226 }
227
228 if ($dotransfer){
229 # An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer
230     my $transferitem = $query->param('transferitem');
231     my $tobranch     = $query->param('tobranch');
232     ModItemTransfer($transferitem, $userenv_branch, $tobranch);
233 }
234
235 if ($canceltransfer){
236     $itemnumber=$query->param('itemnumber');
237     DeleteTransfer($itemnumber);
238     if($dest eq "ttr"){
239         print $query->redirect("/cgi-bin/koha/circ/transferstoreceive.pl");
240         exit;
241     } else {
242         $template->param( transfercancelled => 1);
243     }
244 }
245
246 # actually return book and prepare item table.....
247 my $returnbranch;
248 if ($barcode) {
249     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
250     $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter');
251     my $item = Koha::Items->find({ barcode => $barcode });
252
253     if ( $item ) {
254         $itemnumber = $item->itemnumber;
255         # Check if we should display a checkin message, based on the the item
256         # type of the checked in item
257         my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
258         if ( $itemtype && $itemtype->checkinmsg ) {
259             $template->param(
260                 checkinmsg     => $itemtype->checkinmsg,
261                 checkinmsgtype => $itemtype->checkinmsgtype,
262             );
263         }
264
265         # make sure return branch respects home branch circulation rules, default to homebranch
266         my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
267         $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch
268
269         my $materials = $item->materials;
270         my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
271         $materials = $descriptions->{lib} // $materials;
272
273         my $checkout = $item->checkout;
274         my $biblio   = $item->biblio;
275         $template->param(
276             title            => $biblio->title,
277             homebranch       => $item->homebranch,
278             holdingbranch    => $item->holdingbranch,
279             returnbranch     => $returnbranch,
280             author           => $biblio->author,
281             itembarcode      => $item->barcode,
282             itemtype         => $item->effective_itemtype,
283             ccode            => $item->ccode,
284             itembiblionumber => $biblio->biblionumber,
285             biblionumber     => $biblio->biblionumber,
286             additional_materials => $materials,
287             issue            => $checkout,
288         );
289     } # FIXME else we should not call AddReturn but set BadBarcode directly instead
290
291     my %input = (
292         counter => 0,
293         first   => 1,
294         barcode => $barcode,
295     );
296
297     my $return_date = $dropboxmode ? $dropboxdate : $return_date_override_dt;
298
299     # do the return
300     ( $returned, $messages, $issue, $borrower ) =
301       AddReturn( $barcode, $userenv_branch, $exemptfine, $return_date );
302
303     if ($returned) {
304         my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
305         my $date_due_dt = dt_from_string( $issue->date_due, 'sql' );
306         my $duedate = $date_due_dt->strftime('%Y-%m-%d %H:%M');
307         $returneditems{0}      = $barcode;
308         $riborrowernumber{0}   = $borrower->{'borrowernumber'};
309         $riduedate{0}          = $duedate;
310         $input{borrowernumber} = $borrower->{'borrowernumber'};
311         $input{duedate}        = $duedate;
312         unless ( $dropboxmode ) {
313             $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, DateTime->now()) == -1);
314         } else {
315             $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, $dropboxdate) == -1);
316         }
317         push( @inputloop, \%input );
318
319         if ( C4::Context->preference("FineNotifyAtCheckin") ) {
320             my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
321             my $balance = $patron->account->balance;
322
323             if ($balance > 0) {
324                 $template->param( fines => sprintf("%.2f", $balance) );
325                 $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
326             }
327         }
328
329         if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
330             #Check for waiting holds
331             my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
332             my $waiting_holds = $patron->holds->search({ found => 'W', branchcode => $userenv_branch })->count;
333             if ($waiting_holds > 0) {
334                 $template->param(
335                     waiting_holds       => $waiting_holds,
336                     holdsborrowernumber => $borrower->{'borrowernumber'},
337                     holdsfirstname => $borrower->{'firstname'},
338                     holdssurname => $borrower->{'surname'},
339                 );
340             }
341         }
342     } elsif ( C4::Context->preference('ShowAllCheckins') and !$messages->{'BadBarcode'} ) {
343         $input{duedate}   = 0;
344         $returneditems{0} = $barcode;
345         $riduedate{0}     = 0;
346         push( @inputloop, \%input );
347     }
348     $template->param( privacy => $borrower->{privacy} );
349 }
350 $template->param( inputloop => \@inputloop );
351
352 my $found    = 0;
353 my $waiting  = 0;
354 my $reserved = 0;
355
356 # new op dev : we check if the document must be returned to his homebranch directly,
357 #  if the document is transferred, we have warning message .
358
359 if ( $messages->{'WasTransfered'} ) {
360     $template->param(
361         found          => 1,
362         transfer       => 1,
363         itemnumber     => $itemnumber,
364     );
365 }
366
367 if ( $messages->{'NeedsTransfer'} ){
368     $template->param(
369         found          => 1,
370         needstransfer  => $messages->{'NeedsTransfer'},
371         itemnumber     => $itemnumber,
372     );
373 }
374
375 if ( $messages->{'Wrongbranch'} ){
376     $template->param(
377         wrongbranch => 1,
378         rightbranch => $messages->{'Wrongbranch'}->{'Rightbranch'},
379     );
380 }
381
382 # case of wrong transfert, if the document wasn't transferred to the right library (according to branchtransfer (tobranch) BDD)
383
384 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
385     $template->param(
386         WrongTransfer  => 1,
387         TransferWaitingAt => $messages->{'WrongTransfer'},
388         WrongTransferItem => $messages->{'WrongTransferItem'},
389         itemnumber => $itemnumber,
390     );
391
392     my $reserve    = $messages->{'ResFound'};
393     if ( $reserve ) {
394         my $patron = Koha::Patrons->find( $reserve->{'borrowernumber'} );
395         my $name = $patron->surname . ", " . $patron->title . " " . $patron->firstname;
396         $template->param(
397             patron => $patron,
398         );
399     }
400     $template->param(
401         wtransfertFrom  => $userenv_branch,
402     );
403 }
404
405 #
406 # reserve found and item arrived at the expected branch
407 #
408 if ( $messages->{'ResFound'}) {
409     my $reserve    = $messages->{'ResFound'};
410     my $patron = Koha::Patrons->find( $reserve->{borrowernumber} );
411     my $holdmsgpreferences =  C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name   => 'Hold_Filled' } );
412     my $branchCheck = ( $userenv_branch eq $reserve->{branchcode} );
413     if ( $reserve->{'ResFound'} eq "Reserved" && C4::Context->preference('HoldsAutoFill') ) {
414         my $item = Koha::Items->find( $itemnumber );
415         my $biblio = $item->biblio;
416
417         my $diffBranchSend = !$branchCheck ? $reserve->{branchcode} : undef;
418         ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber}, $diffBranchSend, $reserve->{reserve_id} );
419         my ( $messages, $nextreservinfo ) = GetOtherReserves($reserve->{itemnumber});
420
421         my $patron = Koha::Patrons->find( $nextreservinfo );
422
423         $template->param(
424             hold_auto_filled => 1,
425             print_slip       => C4::Context->preference('HoldsAutoFillPrintSlip'),
426             patron           => $patron,
427             borrowernumber   => $patron->id,
428             biblionumber     => $biblio->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, DateTime->now()) == -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     errmsgloop     => \@errmsgloop,
620     exemptfine     => $exemptfine,
621     dropboxmode    => $dropboxmode,
622     dropboxdate    => $dropboxdate,
623     forgivemanualholdsexpire => $forgivemanualholdsexpire,
624     overduecharges => $overduecharges,
625     AudioAlerts        => C4::Context->preference("AudioAlerts"),
626 );
627
628 if ( $barcode ) {
629     my $item_from_barcode = Koha::Items->find({barcode => $barcode }); # How many times do we fetch this item?!?
630     if ( $item_from_barcode ) {
631         $itemnumber = $item_from_barcode->itemnumber;
632         my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
633         if ( $holdingBranch and $collectionBranch ) {
634             $holdingBranch //= '';
635             $collectionBranch //= $returnbranch;
636             if ( ! ( $holdingBranch eq $collectionBranch ) ) {
637                 $template->param(
638                   collectionItemNeedsTransferred => 1,
639                   collectionBranch => $collectionBranch,
640                   itemnumber => $itemnumber,
641                 );
642             }
643         }
644     }
645 }
646
647 # Checking if there is a Fast Cataloging Framework
648 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
649
650 # actually print the page!
651 output_html_with_http_headers $query, $cookie, $template->output;