Bug 18276: barcode may be nonexistent when checking out/in
[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::Members::Messaging;
48 use C4::Koha;   # FIXME : is it still useful ?
49 use C4::RotatingCollections;
50 use Koha::AuthorisedValues;
51 use Koha::DateUtils;
52 use Koha::Calendar;
53 use Koha::BiblioFrameworks;
54 use Koha::Checkouts;
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'),
84         biblionumber   => scalar $query->param('biblionumber'),
85     );
86 }
87
88 #####################
89 #Global vars
90 my $printers = GetPrinters();
91 my $userenv = C4::Context->userenv;
92 my $userenv_branch = $userenv->{'branch'} // '';
93 my $printer = $userenv->{'branchprinter'} // '';
94 my $forgivemanualholdsexpire = $query->param('forgivemanualholdsexpire');
95
96 my $overduecharges = (C4::Context->preference('finesMode') && C4::Context->preference('finesMode') ne 'off');
97  #
98 # Some code to handle the error if there is no branch or printer setting.....
99 #
100
101 # Set up the item stack ....
102 my %returneditems;
103 my %riduedate;
104 my %riborrowernumber;
105 my @inputloop;
106 foreach ( $query->param ) {
107     my $counter;
108     if (/ri-(\d*)/) {
109         $counter = $1;
110         if ($counter > 20) {
111             next;
112         }
113     }
114     else {
115         next;
116     }
117
118     my %input;
119     my $barcode        = $query->param("ri-$counter");
120     my $duedate        = $query->param("dd-$counter");
121     my $borrowernumber = $query->param("bn-$counter");
122     $counter++;
123
124     # decode barcode    ## Didn't we already decode them before passing them back last time??
125     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
126     $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter'));
127
128     ######################
129     #Are these lines still useful ?
130     $returneditems{$counter}    = $barcode;
131     $riduedate{$counter}        = $duedate;
132     $riborrowernumber{$counter} = $borrowernumber;
133
134     #######################
135     $input{counter}        = $counter;
136     $input{barcode}        = $barcode;
137     $input{duedate}        = $duedate;
138     $input{borrowernumber} = $borrowernumber;
139     push( @inputloop, \%input );
140 }
141
142 ############
143 # Deal with the requests....
144
145 if ($query->param('WT-itemNumber')){
146         updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From'));
147 }
148
149 if ( $query->param('reserve_id') ) {
150     my $itemnumber     = $query->param('itemnumber');
151     my $borrowernumber = $query->param('borrowernumber');
152     my $reserve_id     = $query->param('reserve_id');
153     my $diffBranchReturned = $query->param('diffBranch');
154     my $cancel_reserve = $query->param('cancel_reserve');
155     # fix up item type for display
156     my $item = Koha::Items->find( $itemnumber );
157     my $biblio = $item->biblio;
158
159     if ( $cancel_reserve ) {
160         CancelReserve({ reserve_id => $reserve_id, charge_cancel_fee => !$forgivemanualholdsexpire });
161     } else {
162         my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
163         # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
164         # i.e., whether to apply waiting status
165         ModReserveAffect( $itemnumber, $borrowernumber, $diffBranchSend, $reserve_id );
166     }
167 #   check if we have other reserves for this document, if we have a return send the message of transfer
168     my ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
169
170     my $borr = GetMember( borrowernumber => $nextreservinfo );
171     my $name   = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
172     if ( $messages->{'transfert'} ) {
173         $template->param(
174             itemtitle      => $biblio->title,
175             itemnumber     => $item->itemnumber,
176             itembiblionumber => $biblio->biblionumber,
177             iteminfo       => $biblio->author,
178             name           => $name,
179             borrowernumber => $borrowernumber,
180             borcnum        => $borr->{'cardnumber'},
181             borfirstname   => $borr->{'firstname'},
182             borsurname     => $borr->{'surname'},
183             borcategory    => $borr->{'description'},
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 my $calendar    = Koha::Calendar->new( branchcode => $userenv_branch );
209 #dropbox: get last open day (today - 1)
210 my $today       = DateTime->now( time_zone => C4::Context->tz());
211 my $dropboxdate = $calendar->addDate($today, -1);
212
213 my $return_date_override = $query->param('return_date_override');
214 my $return_date_override_remember =
215   $query->param('return_date_override_remember');
216 if ($return_date_override) {
217     if ( C4::Context->preference('SpecifyReturnDate') ) {
218         my $return_date_override_dt = eval {dt_from_string( $return_date_override ) };
219         if ( $return_date_override_dt ) {
220             # note that we've overriden the return date
221             $template->param( return_date_was_overriden => 1);
222             # Save the original format if we are remembering for this series
223             $template->param(
224                 return_date_override          => $return_date_override,
225                 return_date_override_remember => 1
226             ) if ($return_date_override_remember);
227
228             $return_date_override =
229               DateTime::Format::MySQL->format_datetime( $return_date_override_dt );
230         }
231     }
232     else {
233         $return_date_override = q{};
234     }
235 }
236
237 if ($dotransfer){
238 # An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer
239     my $transferitem = $query->param('transferitem');
240     my $tobranch     = $query->param('tobranch');
241     ModItemTransfer($transferitem, $userenv_branch, $tobranch);
242 }
243
244 if ($canceltransfer){
245     $itemnumber=$query->param('itemnumber');
246     DeleteTransfer($itemnumber);
247     if($dest eq "ttr"){
248         print $query->redirect("/cgi-bin/koha/circ/transferstoreceive.pl");
249         exit;
250     } else {
251         $template->param( transfercancelled => 1);
252     }
253 }
254
255 # actually return book and prepare item table.....
256 my $returnbranch;
257 if ($barcode) {
258     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
259     $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter');
260     my $item = Koha::Items->find({ barcode => $barcode });
261
262     if ( $item ) {
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 = $item->$hbr;
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 $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
282
283         my $biblio = $item->biblio;
284         $template->param(
285             title            => $biblio->title,
286             homebranch       => $item->homebranch,
287             holdingbranch    => $item->holdingbranch,
288             returnbranch     => $returnbranch,
289             author           => $biblio->author,
290             itembarcode      => $item->barcode,
291             itemtype         => $item->effective_itemtype,
292             ccode            => $item->ccode,
293             itembiblionumber => $biblio->biblionumber,
294             biblionumber     => $biblio->biblionumber,
295             borrower         => $borrower,
296             additional_materials => $materials,
297             issue            => $issue,
298         );
299     } # FIXME else we should not call AddReturn but set BadBarcode directly instead
300
301     my %input = (
302         counter => 0,
303         first   => 1,
304         barcode => $barcode,
305     );
306
307
308     # do the return
309     ( $returned, $messages, $issue, $borrower ) =
310       AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override, $dropboxdate );
311
312     if ($returned) {
313         my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
314         my $date_due_dt = dt_from_string( $issue->date_due, 'sql' );
315         my $duedate = $date_due_dt->strftime('%Y-%m-%d %H:%M');
316         $returneditems{0}      = $barcode;
317         $riborrowernumber{0}   = $borrower->{'borrowernumber'};
318         $riduedate{0}          = $duedate;
319         $input{borrowernumber} = $borrower->{'borrowernumber'};
320         $input{duedate}        = $duedate;
321         unless ( $dropboxmode ) {
322             $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, DateTime->now()) == -1);
323         } else {
324             $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, $dropboxdate) == -1);
325         }
326         push( @inputloop, \%input );
327
328         if ( C4::Context->preference("FineNotifyAtCheckin") ) {
329             my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
330             my $balance = $patron->account->balance;
331
332             if ($balance > 0) {
333                 $template->param( fines => sprintf("%.2f", $balance) );
334                 $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
335             }
336         }
337
338         if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
339             #Check for waiting holds
340             my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
341             my $waiting_holds = $patron->holds->search({ found => 'W', branchcode => $userenv_branch })->count;
342             if ($waiting_holds > 0) {
343                 $template->param(
344                     waiting_holds       => $waiting_holds,
345                     holdsborrowernumber => $borrower->{'borrowernumber'},
346                     holdsfirstname => $borrower->{'firstname'},
347                     holdssurname => $borrower->{'surname'},
348                 );
349             }
350         }
351     } elsif ( C4::Context->preference('ShowAllCheckins') and !$messages->{'BadBarcode'} ) {
352         $input{duedate}   = 0;
353         $returneditems{0} = $barcode;
354         $riduedate{0}     = 0;
355         push( @inputloop, \%input );
356     }
357     $template->param( privacy => $borrower->{privacy} );
358 }
359 $template->param( inputloop => \@inputloop );
360
361 my $found    = 0;
362 my $waiting  = 0;
363 my $reserved = 0;
364
365 # new op dev : we check if the document must be returned to his homebranch directly,
366 #  if the document is transfered, we have warning message .
367
368 if ( $messages->{'WasTransfered'} ) {
369     $template->param(
370         found          => 1,
371         transfer       => 1,
372         itemnumber     => $itemnumber,
373     );
374 }
375
376 if ( $messages->{'NeedsTransfer'} ){
377     $template->param(
378         found          => 1,
379         needstransfer  => $messages->{'NeedsTransfer'},
380         itemnumber     => $itemnumber,
381     );
382 }
383
384 if ( $messages->{'Wrongbranch'} ){
385     $template->param(
386         wrongbranch => 1,
387         rightbranch => $messages->{'Wrongbranch'}->{'Rightbranch'},
388     );
389 }
390
391 # case of wrong transfert, if the document wasn't transfered to the right library (according to branchtransfer (tobranch) BDD)
392
393 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
394     $template->param(
395         WrongTransfer  => 1,
396         TransferWaitingAt => $messages->{'WrongTransfer'},
397         WrongTransferItem => $messages->{'WrongTransferItem'},
398         itemnumber => $itemnumber,
399     );
400
401     my $reserve    = $messages->{'ResFound'};
402     my $borr = C4::Members::GetMember( borrowernumber => $reserve->{'borrowernumber'} );
403     my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
404     $template->param(
405             wname           => $name,
406             wborfirstname   => $borr->{'firstname'},
407             wborsurname     => $borr->{'surname'},
408             wborcategory    => $borr->{'description'},
409             wbortitle       => $borr->{'title'},
410             wborphone       => $borr->{'phone'},
411             wboremail       => $borr->{'email'},
412             streetnumber    => $borr->{streetnumber},
413             streettype      => $borr->{streettype},
414             address         => $borr->{'address'},
415             address2        => $borr->{'address2'},
416             city            => $borr->{'city'},
417             zipcode         => $borr->{'zipcode'},
418             state           => $borr->{'state'},
419             country         => $borr->{'country'},
420             wborrowernumber => $reserve->{'borrowernumber'},
421             wborcnum        => $borr->{'cardnumber'},
422             wtransfertFrom  => $userenv_branch,
423     );
424 }
425
426 #
427 # reserve found and item arrived at the expected branch
428 #
429 if ( $messages->{'ResFound'}) {
430     my $reserve    = $messages->{'ResFound'};
431     my $borr = C4::Members::GetMember( borrowernumber => $reserve->{'borrowernumber'} );
432     my $holdmsgpreferences =  C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name   => 'Hold_Filled' } );
433     if ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
434         if ( $reserve->{'ResFound'} eq "Waiting" ) {
435             $template->param(
436                 waiting      => ($userenv_branch eq $reserve->{'branchcode'} ? 1 : 0 ),
437             );
438         } elsif ( $reserve->{'ResFound'} eq "Reserved" ) {
439             $template->param(
440                 intransit    => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
441                 transfertodo => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
442                 reserve_id   => $reserve->{reserve_id},
443                 reserved     => 1,
444             );
445         }
446
447         # same params for Waiting or Reserved
448         $template->param(
449             found          => 1,
450             name           => $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'},
451             borfirstname   => $borr->{'firstname'},
452             borsurname     => $borr->{'surname'},
453             borcategory    => $borr->{'description'},
454             bortitle       => $borr->{'title'},
455             borphone       => $borr->{'phone'},
456             boremail       => $borr->{'email'},
457             streetnumber   => $borr->{streetnumber},
458             streettype     => $borr->{streettype},
459             address        => $borr->{'address'},
460             address2       => $borr->{'address2'},
461             city           => $borr->{'city'},
462             zipcode        => $borr->{'zipcode'},
463             state          => $borr->{'state'},
464             country        => $borr->{'country'},
465             borcnum        => $borr->{'cardnumber'},
466             debarred       => $borr->{'debarred'},
467             gonenoaddress  => $borr->{'gonenoaddress'},
468             barcode        => $barcode,
469             destbranch     => $reserve->{'branchcode'},
470             borrowernumber => $reserve->{'borrowernumber'},
471             itemnumber     => $reserve->{'itemnumber'},
472             reservenotes   => $reserve->{'reservenotes'},
473             reserve_id     => $reserve->{reserve_id},
474             bormessagepref => $holdmsgpreferences->{'transports'},
475         );
476     } # else { ; }  # error?
477 }
478
479 # Error Messages
480 my @errmsgloop;
481 foreach my $code ( keys %$messages ) {
482     my %err;
483     my $exit_required_p = 0;
484     if ( $code eq 'BadBarcode' ) {
485         $err{badbarcode} = 1;
486         $err{msg}        = $messages->{'BadBarcode'};
487     }
488     elsif ( $code eq 'NotIssued' ) {
489         $err{notissued} = 1;
490         $err{msg} = '';
491         $err{msg} = $messages->{'IsPermanent'} if $messages->{'IsPermanent'};
492     }
493     elsif ( $code eq 'LocalUse' ) {
494         $err{localuse} = 1;
495     }
496     elsif ( $code eq 'WasLost' ) {
497         $err{waslost} = 1;
498     }
499     elsif ( $code eq 'LostItemFeeRefunded' ) {
500         $template->param( LostItemFeeRefunded => 1 );
501     }
502     elsif ( $code eq 'ResFound' ) {
503         ;    # FIXME... anything to do here?
504     }
505     elsif ( $code eq 'WasReturned' ) {
506         ;    # FIXME... anything to do here?
507     }
508     elsif ( $code eq 'WasTransfered' ) {
509         ;    # FIXME... anything to do here?
510     }
511     elsif ( $code eq 'withdrawn' ) {
512         $err{withdrawn} = 1;
513         $exit_required_p = 1 if C4::Context->preference("BlockReturnOfWithdrawnItems");
514     }
515     elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
516         if ( $messages->{'IsPermanent'} ne $userenv_branch ) {
517             $err{ispermanent} = 1;
518             $err{msg}         = $messages->{'IsPermanent'};
519         }
520     }
521     elsif ( $code eq 'WrongTransfer' ) {
522         ;    # FIXME... anything to do here?
523     }
524     elsif ( $code eq 'WrongTransferItem' ) {
525         ;    # FIXME... anything to do here?
526     }
527     elsif ( $code eq 'NeedsTransfer' ) {
528     }
529     elsif ( $code eq 'Wrongbranch' ) {
530     }
531     elsif ( $code eq 'Debarred' ) {
532         $err{debarred}            = $messages->{'Debarred'};
533         $err{debarcardnumber}     = $borrower->{cardnumber};
534         $err{debarborrowernumber} = $borrower->{borrowernumber};
535         $err{debarname}           = "$borrower->{firstname} $borrower->{surname}";
536     }
537     elsif ( $code eq 'PrevDebarred' ) {
538         $err{prevdebarred}        = $messages->{'PrevDebarred'};
539     }
540     elsif ( $code eq 'ForeverDebarred' ) {
541         $err{foreverdebarred}        = $messages->{'ForeverDebarred'};
542     }
543     elsif ( $code eq 'NotForLoanStatusUpdated' ) {
544         $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
545     }
546     else {
547         die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
548         # This forces the issue of staying in sync w/ Circulation.pm
549     }
550     if (%err) {
551         push( @errmsgloop, \%err );
552     }
553     last if $exit_required_p;
554 }
555 $template->param( errmsgloop => \@errmsgloop );
556
557 #set up so only the last 8 returned items display (make for faster loading pages)
558 my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C4::Context->preference('numReturnedItemsToShow') : 8;
559 my $count = 0;
560 my @riloop;
561 my $shelflocations =
562   { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) };
563 foreach ( sort { $a <=> $b } keys %returneditems ) {
564     my %ri;
565     if ( $count++ < $returned_counter ) {
566         my $bar_code = $returneditems{$_};
567         if ($riduedate{$_}) {
568             my $duedate = dt_from_string( $riduedate{$_}, 'sql');
569             $ri{year}  = $duedate->year();
570             $ri{month} = $duedate->month();
571             $ri{day}   = $duedate->day();
572             $ri{hour}   = $duedate->hour();
573             $ri{minute}   = $duedate->minute();
574             $ri{duedate} = output_pref($duedate);
575             my $b      = C4::Members::GetMember( borrowernumber => $riborrowernumber{$_} );
576             unless ( $dropboxmode ) {
577                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, DateTime->now()) == -1);
578             } else {
579                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, $dropboxdate) == -1);
580             }
581             $ri{borrowernumber} = $b->{'borrowernumber'};
582             $ri{borcnum}        = $b->{'cardnumber'};
583             $ri{borfirstname}   = $b->{'firstname'};
584             $ri{borsurname}     = $b->{'surname'};
585             $ri{bortitle}       = $b->{'title'};
586             $ri{bornote}        = $b->{'borrowernotes'};
587             $ri{borcategorycode}= $b->{'categorycode'};
588             $ri{borissuescount} = Koha::Checkouts->count( { borrowernumber => $b->{'borrowernumber'} } );
589         }
590         else {
591             $ri{borrowernumber} = $riborrowernumber{$_};
592         }
593
594         my $item = Koha::Items->find({ barcode => $bar_code });
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{itemauthor}          = $biblio->author;
600         $ri{itemcallnumber}      = $item->itemcallnumber;
601         $ri{dateaccessioned}     = $item->dateaccessioned;
602         $ri{itemtype}            = $item->effective_itemtype;
603         $ri{itemnote}            = $item->itemnotes;
604         $ri{itemnotes_nonpublic} = $item->itemnotes_nonpublic;
605         $ri{ccode}               = $item->ccode;
606         $ri{enumchron}           = $item->enumchron;
607         $ri{itemnumber}          = $item->itemnumber;
608         $ri{barcode}             = $bar_code;
609         $ri{homebranch}          = $item->homebranch;
610         $ri{holdingbranch}       = $item->holdingbranch;
611
612         $ri{location}         = $biblio->{'location'};
613         my $shelfcode = $ri{'location'};
614         $ri{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
615
616     }
617     else {
618         last;
619     }
620     push @riloop, \%ri;
621 }
622
623 $template->param(
624     riloop         => \@riloop,
625     printer        => $printer,
626     errmsgloop     => \@errmsgloop,
627     exemptfine     => $exemptfine,
628     dropboxmode    => $dropboxmode,
629     dropboxdate    => output_pref($dropboxdate),
630     forgivemanualholdsexpire => $forgivemanualholdsexpire,
631     overduecharges => $overduecharges,
632     AudioAlerts        => C4::Context->preference("AudioAlerts"),
633     BlockReturnOfWithdrawnItems => C4::Context->preference("BlockReturnOfWithdrawnItems"),
634 );
635
636 $itemnumber = GetItemnumberFromBarcode( $barcode );
637 if ( $itemnumber ) {
638     my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
639     if ( $holdingBranch and $collectionBranch ) {
640         $holdingBranch //= '';
641         $collectionBranch //= $returnbranch;
642         if ( ! ( $holdingBranch eq $collectionBranch ) ) {
643             $template->param(
644               collectionItemNeedsTransferred => 1,
645               collectionBranch => $collectionBranch,
646               itemnumber => $itemnumber,
647             );
648         }
649     }
650 }
651
652 # Checking if there is a Fast Cataloging Framework
653 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
654
655 # actually print the page!
656 output_html_with_http_headers $query, $cookie, $template->output;