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