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