Bug 7981: Remove HomeOrHoldingBranchReturn syspref
[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 strict;
31 use warnings;
32
33 use CGI qw ( -utf8 );
34 use DateTime;
35 use C4::Context;
36 use C4::Auth qw/:DEFAULT get_session/;
37 use C4::Output;
38 use C4::Circulation;
39 use C4::Print;
40 use C4::Reserves;
41 use C4::Biblio;
42 use C4::Items;
43 use C4::Members;
44 use C4::Branch; # GetBranches GetBranchName
45 use C4::Koha;   # FIXME : is it still useful ?
46 use C4::RotatingCollections;
47 use Koha::DateUtils;
48 use Koha::Calendar;
49
50 my $query = new CGI;
51
52 #getting the template
53 my ( $template, $librarian, $cookie ) = get_template_and_user(
54     {
55         template_name   => "circ/returns.tt",
56         query           => $query,
57         type            => "intranet",
58         authnotrequired => 0,
59         flagsrequired   => { circulate => "circulate_remaining_permissions" },
60     }
61 );
62
63 my $sessionID = $query->cookie("CGISESSID");
64 my $session = get_session($sessionID);
65 if ($session->param('branch') eq 'NO_LIBRARY_SET'){
66     # no branch set we can't return
67     print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
68     exit;
69 }
70
71 # Print a reserve slip on this page
72 if ( $query->param('print_slip') ) {
73     $template->param(
74         print_slip     => 1,
75         borrowernumber => $query->param('borrowernumber'),
76         biblionumber   => $query->param('biblionumber'),
77     );
78 }
79
80 #####################
81 #Global vars
82 my $branches = GetBranches();
83 my $printers = GetPrinters();
84 my $userenv = C4::Context->userenv;
85 my $userenv_branch = $userenv->{'branch'} // '';
86 my $printer = $userenv->{'branchprinter'} // '';
87
88 my $overduecharges = (C4::Context->preference('finesMode') && C4::Context->preference('finesMode') ne 'off');
89 #
90 # Some code to handle the error if there is no branch or printer setting.....
91 #
92
93 # Set up the item stack ....
94 my %returneditems;
95 my %riduedate;
96 my %riborrowernumber;
97 my @inputloop;
98 foreach ( $query->param ) {
99     my $counter;
100     if (/ri-(\d*)/) {
101         $counter = $1;
102         if ($counter > 20) {
103             next;
104         }
105     }
106     else {
107         next;
108     }
109
110     my %input;
111     my $barcode        = $query->param("ri-$counter");
112     my $duedate        = $query->param("dd-$counter");
113     my $borrowernumber = $query->param("bn-$counter");
114     $counter++;
115
116     # decode barcode    ## Didn't we already decode them before passing them back last time??
117     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
118     $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter'));
119
120     ######################
121     #Are these lines still useful ?
122     $returneditems{$counter}    = $barcode;
123     $riduedate{$counter}        = $duedate;
124     $riborrowernumber{$counter} = $borrowernumber;
125
126     #######################
127     $input{counter}        = $counter;
128     $input{barcode}        = $barcode;
129     $input{duedate}        = $duedate;
130     $input{borrowernumber} = $borrowernumber;
131     push( @inputloop, \%input );
132 }
133
134 ############
135 # Deal with the requests....
136
137 if ($query->param('WT-itemNumber')){
138         updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From'));
139 }
140
141 if ( $query->param('resbarcode') ) {
142     my $item           = $query->param('itemnumber');
143     my $borrowernumber = $query->param('borrowernumber');
144     my $resbarcode     = $query->param('resbarcode');
145     my $diffBranchReturned = $query->param('diffBranch');
146     my $iteminfo   = GetBiblioFromItemNumber($item);
147     # fix up item type for display
148     $iteminfo->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $iteminfo->{'itype'} : $iteminfo->{'itemtype'};
149     my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
150 # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
151 # i.e., whether to apply waiting status
152     ModReserveAffect( $item, $borrowernumber, $diffBranchSend);
153 #   check if we have other reserves for this document, if we have a return send the message of transfer
154     my ( $messages, $nextreservinfo ) = GetOtherReserves($item);
155
156     my ($borr) = GetMemberDetails( $nextreservinfo, 0 );
157     my $name   = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
158     if ( $messages->{'transfert'} ) {
159         $template->param(
160             itemtitle      => $iteminfo->{'title'},
161             itemnumber     => $iteminfo->{'itemnumber'},
162             itembiblionumber => $iteminfo->{'biblionumber'},
163             iteminfo       => $iteminfo->{'author'},
164             tobranchname   => GetBranchName($messages->{'transfert'}),
165             name           => $name,
166             borrowernumber => $borrowernumber,
167             borcnum        => $borr->{'cardnumber'},
168             borfirstname   => $borr->{'firstname'},
169             borsurname     => $borr->{'surname'},
170             diffbranch     => 1,
171         );
172     }
173 }
174
175 my $borrower;
176 my $returned = 0;
177 my $messages;
178 my $issueinformation;
179 my $itemnumber;
180 my $barcode     = $query->param('barcode');
181 my $exemptfine  = $query->param('exemptfine');
182 if (
183   $exemptfine &&
184   !C4::Auth::haspermission(C4::Context->userenv->{'id'}, {'updatecharges' => 'writeoff'})
185 ) {
186     # silently prevent unauthorized operator from forgiving overdue
187     # fines by manually tweaking form parameters
188     undef $exemptfine;
189 }
190 my $dropboxmode = $query->param('dropboxmode');
191 my $dotransfer  = $query->param('dotransfer');
192 my $canceltransfer = $query->param('canceltransfer');
193 my $dest = $query->param('dest');
194 my $calendar    = Koha::Calendar->new( branchcode => $userenv_branch );
195 #dropbox: get last open day (today - 1)
196 my $today       = DateTime->now( time_zone => C4::Context->tz());
197 my $dropboxdate = $calendar->addDate($today, -1);
198
199 my $return_date_override = $query->param('return_date_override');
200 my $return_date_override_remember =
201   $query->param('return_date_override_remember');
202 if ($return_date_override) {
203     if ( C4::Context->preference('SpecifyReturnDate') ) {
204         # FIXME we really need to stop adding more uses of C4::Dates
205         if ( $return_date_override =~ C4::Dates->regexp('syspref') ) {
206
207             # note that we've overriden the return date
208             $template->param( return_date_was_overriden => 1);
209             # Save the original format if we are remembering for this series
210             $template->param(
211                 return_date_override          => $return_date_override,
212                 return_date_override_remember => 1
213             ) if ($return_date_override_remember);
214
215             my $dt = dt_from_string($return_date_override);
216             $return_date_override =
217               DateTime::Format::MySQL->format_datetime($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     ModItemTransfer($transferitem, $userenv_branch, $tobranch);
230 }
231
232 if ($canceltransfer){
233     $itemnumber=$query->param('itemnumber');
234     DeleteTransfer($itemnumber);
235     if($dest eq "ttr"){
236         print $query->redirect("/cgi-bin/koha/circ/transferstoreceive.pl");
237         exit;
238     } else {
239         $template->param( transfercancelled => 1);
240     }
241 }
242
243 # actually return book and prepare item table.....
244 if ($barcode) {
245     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
246     $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter');
247     $itemnumber = GetItemnumberFromBarcode($barcode);
248
249 #
250 # save the return
251 #
252
253     # get biblio description
254     my $biblio = GetBiblioFromItemNumber($itemnumber);
255     # fix up item type for display
256     $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'};
257
258     # Check if we should display a checkin message, based on the the item
259     # type of the checked in item
260     my $itemtype = C4::ItemType->get( $biblio->{'itemtype'} );
261     if ( $itemtype->{'checkinmsg'} ) {
262         $template->param(
263             checkinmsg     => $itemtype->{'checkinmsg'},
264             checkinmsgtype => $itemtype->{'checkinmsgtype'},
265         );
266     }
267
268     # make sure return branch respects home branch circulation rules, default to homebranch
269     my $hbr = GetBranchItemRule($biblio->{'homebranch'}, $itemtype)->{'returnbranch'} || "homebranch";
270     my $returnbranch = $biblio->{$hbr} ;
271
272     $template->param(
273         title            => $biblio->{'title'},
274         homebranch       => $biblio->{'homebranch'},
275         homebranchname   => GetBranchName( $biblio->{'homebranch'} ),
276         returnbranch     => $returnbranch,
277         returnbranchname => GetBranchName( $returnbranch ),
278         author           => $biblio->{'author'},
279         itembarcode      => $biblio->{'barcode'},
280         itemtype         => $biblio->{'itemtype'},
281         ccode            => $biblio->{'ccode'},
282         itembiblionumber => $biblio->{'biblionumber'},
283         biblionumber     => $biblio->{'biblionumber'},
284         borrower         => $borrower,
285         additional_materials => $biblio->{'materials'},
286     );
287
288     my %input = (
289         counter => 0,
290         first   => 1,
291         barcode => $barcode,
292     );
293
294     # do the return
295     ( $returned, $messages, $issueinformation, $borrower ) =
296       AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override );
297
298     if ($returned) {
299         my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
300         my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
301         $returneditems{0}      = $barcode;
302         $riborrowernumber{0}   = $borrower->{'borrowernumber'};
303         $riduedate{0}          = $duedate;
304         $input{borrowernumber} = $borrower->{'borrowernumber'};
305         $input{duedate}        = $duedate;
306         unless ( $dropboxmode ) {
307             $input{return_overdue} = 1 if (DateTime->compare($issueinformation->{date_due}, DateTime->now()) == -1);
308         } else {
309             $input{return_overdue} = 1 if (DateTime->compare($issueinformation->{date_due}, $dropboxdate) == -1);
310         }
311         push( @inputloop, \%input );
312
313         if ( C4::Context->preference("FineNotifyAtCheckin") ) {
314             my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrower->{'borrowernumber'} );
315             if ($fines && $fines > 0) {
316                 $template->param( fines => sprintf("%.2f",$fines) );
317                 $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
318             }
319         }
320
321         if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
322             #Check for waiting holds
323             my @reserves = GetReservesFromBorrowernumber($borrower->{'borrowernumber'});
324             my $waiting_holds = 0;
325             foreach my $num_res (@reserves) {
326                 if ( $num_res->{'found'} eq 'W' && $num_res->{'branchcode'} eq $userenv_branch) {
327                     $waiting_holds++;
328                 }
329             }
330             if ($waiting_holds > 0) {
331                 $template->param(
332                     waiting_holds       => $waiting_holds,
333                     holdsborrowernumber => $borrower->{'borrowernumber'},
334                     holdsfirstname => $borrower->{'firstname'},
335                     holdssurname => $borrower->{'surname'},
336                 );
337             }
338         }
339     }
340     elsif ( !$messages->{'BadBarcode'} ) {
341         $input{duedate}   = 0;
342         $returneditems{0} = $barcode;
343         $riduedate{0}     = 0;
344         push( @inputloop, \%input );
345     }
346 }
347 $template->param( inputloop => \@inputloop );
348
349 my $found    = 0;
350 my $waiting  = 0;
351 my $reserved = 0;
352
353 # new op dev : we check if the document must be returned to his homebranch directly,
354 #  if the document is transfered, we have warning message .
355
356 if ( $messages->{'WasTransfered'} ) {
357     $template->param(
358         found          => 1,
359         transfer       => 1,
360         itemnumber     => $itemnumber,
361     );
362 }
363
364 if ( $messages->{'NeedsTransfer'} ){
365     $template->param(
366         found          => 1,
367         needstransfer  => $messages->{'NeedsTransfer'},
368         itemnumber     => $itemnumber,
369     );
370 }
371
372 if ( $messages->{'Wrongbranch'} ){
373     $template->param(
374         wrongbranch => 1,
375     );
376 }
377
378 # case of wrong transfert, if the document wasn't transfered to the right library (according to branchtransfer (tobranch) BDD)
379
380 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
381     $template->param(
382         WrongTransfer  => 1,
383         TransferWaitingAt => $messages->{'WrongTransfer'},
384         WrongTransferItem => $messages->{'WrongTransferItem'},
385         itemnumber => $itemnumber,
386     );
387
388     my $reserve    = $messages->{'ResFound'};
389     my $branchname = $branches->{ $reserve->{'branchcode'} }->{'branchname'};
390     my ($borr) = GetMemberDetails( $reserve->{'borrowernumber'}, 0 );
391     my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
392     $template->param(
393             wname           => $name,
394             wborfirstname   => $borr->{'firstname'},
395             wborsurname     => $borr->{'surname'},
396             wbortitle       => $borr->{'title'},
397             wborphone       => $borr->{'phone'},
398             wboremail       => $borr->{'email'},
399             wborstnum       => $borr->{streetnumber},
400             wboraddress     => $borr->{'address'},
401             wboraddress2    => $borr->{'address2'},
402             wborcity        => $borr->{'city'},
403             wborzip         => $borr->{'zipcode'},
404             wborrowernumber => $reserve->{'borrowernumber'},
405             wborcnum        => $borr->{'cardnumber'},
406             wtransfertFrom  => $userenv_branch,
407     );
408 }
409
410 #
411 # reserve found and item arrived at the expected branch
412 #
413 if ( $messages->{'ResFound'}) {
414     my $reserve    = $messages->{'ResFound'};
415     my $branchname = $branches->{ $reserve->{'branchcode'} }->{'branchname'};
416     my ($borr) = GetMemberDetails( $reserve->{'borrowernumber'}, 0 );
417
418     if ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
419         if ( $reserve->{'ResFound'} eq "Waiting" ) {
420             $template->param(
421                 waiting      => ($userenv_branch eq $reserve->{'branchcode'} ? 1 : 0 ),
422             );
423         } elsif ( $reserve->{'ResFound'} eq "Reserved" ) {
424             $template->param(
425                 intransit    => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
426                 transfertodo => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
427                 resbarcode   => $barcode,
428                 reserved     => 1,
429             );
430         }
431
432         # same params for Waiting or Reserved
433         $template->param(
434             found          => 1,
435             currentbranch  => $branches->{$userenv_branch}->{'branchname'},
436             destbranchname => $branches->{ $reserve->{'branchcode'} }->{'branchname'},
437             name           => $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'},
438             borfirstname   => $borr->{'firstname'},
439             borsurname     => $borr->{'surname'},
440             bortitle       => $borr->{'title'},
441             borphone       => $borr->{'phone'},
442             boremail       => $borr->{'email'},
443             boraddress     => $borr->{'address'},
444             boraddress2    => $borr->{'address2'},
445             borstnum       => $borr->{streetnumber},
446             borcity        => $borr->{'city'},
447             borzip         => $borr->{'zipcode'},
448             borcnum        => $borr->{'cardnumber'},
449             debarred       => $borr->{'debarred'},
450             gonenoaddress  => $borr->{'gonenoaddress'},
451             barcode        => $barcode,
452             destbranch     => $reserve->{'branchcode'},
453             borrowernumber => $reserve->{'borrowernumber'},
454             itemnumber     => $reserve->{'itemnumber'},
455             reservenotes   => $reserve->{'reservenotes'},
456         );
457     } # else { ; }  # error?
458 }
459
460 # Error Messages
461 my @errmsgloop;
462 foreach my $code ( keys %$messages ) {
463     my %err;
464     my $exit_required_p = 0;
465     if ( $code eq 'BadBarcode' ) {
466         $err{badbarcode} = 1;
467         $err{msg}        = $messages->{'BadBarcode'};
468     }
469     elsif ( $code eq 'NotIssued' ) {
470         $err{notissued} = 1;
471         $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
472     }
473     elsif ( $code eq 'LocalUse' ) {
474         $err{localuse} = 1;
475     }
476     elsif ( $code eq 'WasLost' ) {
477         $err{waslost} = 1;
478     }
479     elsif ( $code eq 'LostItemFeeRefunded' ) {
480         $template->param( LostItemFeeRefunded => 1 );
481     }
482     elsif ( $code eq 'ResFound' ) {
483         ;    # FIXME... anything to do here?
484     }
485     elsif ( $code eq 'WasReturned' ) {
486         ;    # FIXME... anything to do here?
487     }
488     elsif ( $code eq 'WasTransfered' ) {
489         ;    # FIXME... anything to do here?
490     }
491     elsif ( $code eq 'withdrawn' ) {
492         $err{withdrawn} = 1;
493         $exit_required_p = 1 if C4::Context->preference("BlockReturnOfWithdrawnItems");
494     }
495     elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
496         if ( $messages->{'IsPermanent'} ne $userenv_branch ) {
497             $err{ispermanent} = 1;
498             $err{msg}         =
499               $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
500         }
501     }
502     elsif ( $code eq 'WrongTransfer' ) {
503         ;    # FIXME... anything to do here?
504     }
505     elsif ( $code eq 'WrongTransferItem' ) {
506         ;    # FIXME... anything to do here?
507     }
508     elsif ( $code eq 'NeedsTransfer' ) {
509     }
510     elsif ( $code eq 'Wrongbranch' ) {
511     }
512     elsif ( $code eq 'Debarred' ) {
513         $err{debarred}            = $messages->{'Debarred'};
514         $err{debarcardnumber}     = $borrower->{cardnumber};
515         $err{debarborrowernumber} = $borrower->{borrowernumber};
516         $err{debarname}           = "$borrower->{firstname} $borrower->{surname}";
517     }
518     elsif ( $code eq 'PrevDebarred' ) {
519         $err{prevdebarred}        = $messages->{'PrevDebarred'};
520     }
521     elsif ( $code eq 'ForeverDebarred' ) {
522         $err{foreverdebarred}        = $messages->{'ForeverDebarred'};
523     }
524     elsif ( $code eq 'NotForLoanStatusUpdated' ) {
525         $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
526     }
527     else {
528         die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
529         # This forces the issue of staying in sync w/ Circulation.pm
530     }
531     if (%err) {
532         push( @errmsgloop, \%err );
533     }
534     last if $exit_required_p;
535 }
536 $template->param( errmsgloop => \@errmsgloop );
537
538 #set up so only the last 8 returned items display (make for faster loading pages)
539 my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C4::Context->preference('numReturnedItemsToShow') : 8;
540 my $count = 0;
541 my @riloop;
542 my $shelflocations = GetKohaAuthorisedValues('items.location','');
543 foreach ( sort { $a <=> $b } keys %returneditems ) {
544     my %ri;
545     if ( $count++ < $returned_counter ) {
546         my $bar_code = $returneditems{$_};
547         if ($riduedate{$_}) {
548             my $duedate = dt_from_string( $riduedate{$_}, 'sql');
549             $ri{year}  = $duedate->year();
550             $ri{month} = $duedate->month();
551             $ri{day}   = $duedate->day();
552             $ri{hour}   = $duedate->hour();
553             $ri{minute}   = $duedate->minute();
554             $ri{duedate} = output_pref($duedate);
555             my ($b)      = GetMemberDetails( $riborrowernumber{$_}, 0 );
556             unless ( $dropboxmode ) {
557                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, DateTime->now()) == -1);
558             } else {
559                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, $dropboxdate) == -1);
560             }
561             $ri{borrowernumber} = $b->{'borrowernumber'};
562             $ri{borcnum}        = $b->{'cardnumber'};
563             $ri{borfirstname}   = $b->{'firstname'};
564             $ri{borsurname}     = $b->{'surname'};
565             $ri{bortitle}       = $b->{'title'};
566             $ri{bornote}        = $b->{'borrowernotes'};
567             $ri{borcategorycode}= $b->{'categorycode'};
568         }
569         else {
570             $ri{borrowernumber} = $riborrowernumber{$_};
571         }
572
573         #        my %ri;
574         my $biblio = GetBiblioFromItemNumber(GetItemnumberFromBarcode($bar_code));
575         my $item   = GetItem( GetItemnumberFromBarcode($bar_code) );
576         # fix up item type for display
577         $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'};
578         $ri{itembiblionumber} = $biblio->{'biblionumber'};
579         $ri{itemtitle}        = $biblio->{'title'};
580         $ri{itemauthor}       = $biblio->{'author'};
581         $ri{itemcallnumber}   = $biblio->{'itemcallnumber'};
582         $ri{itemtype}         = $biblio->{'itemtype'};
583         $ri{itemnote}         = $biblio->{'itemnotes'};
584         $ri{ccode}            = $biblio->{'ccode'};
585         $ri{itemnumber}       = $biblio->{'itemnumber'};
586         $ri{barcode}          = $bar_code;
587         $ri{homebranch}       = $item->{'homebranch'};
588         $ri{holdingbranch}    = $item->{'holdingbranch'};
589
590         $ri{location}         = $biblio->{'location'};
591         my $shelfcode = $ri{'location'};
592         $ri{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
593
594     }
595     else {
596         last;
597     }
598     push @riloop, \%ri;
599 }
600 my ($genbrname, $genprname);
601 if (my $b = $branches->{$userenv_branch}) {
602     $genbrname = $b->{'branchname'};
603 }
604 if (my $p = $printers->{$printer}) {
605     $genprname = $p->{'printername'};
606 }
607 $template->param(
608     riloop         => \@riloop,
609     genbrname      => $genbrname,
610     genprname      => $genprname,
611     branchname     => $genbrname,
612     printer        => $printer,
613     errmsgloop     => \@errmsgloop,
614     exemptfine     => $exemptfine,
615     dropboxmode    => $dropboxmode,
616     dropboxdate    => output_pref($dropboxdate),
617     overduecharges => $overduecharges,
618     soundon        => C4::Context->preference("SoundOn"),
619     BlockReturnOfWithdrawnItems => C4::Context->preference("BlockReturnOfWithdrawnItems"),
620 );
621
622 $itemnumber = GetItemnumberFromBarcode( $query->param('barcode') );
623 if ( $itemnumber ) {
624    my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
625     if ( ! ( $holdingBranch eq $collectionBranch ) ) {
626         $template->param(
627           collectionItemNeedsTransferred => 1,
628           collectionBranch => GetBranchName($collectionBranch),
629         );
630     }
631 }
632
633 # actually print the page!
634 output_html_with_http_headers $query, $cookie, $template->output;