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