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