Bug 19840: Fix - display patron note on checkin
[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 # FIXME There are weird things going on with $patron and $borrowernumber in this script
34
35 use CGI qw ( -utf8 );
36 use DateTime;
37 use C4::Context;
38 use C4::Auth qw/:DEFAULT get_session/;
39 use C4::Output;
40 use C4::Circulation;
41 use C4::Print;
42 use C4::Reserves;
43 use C4::Biblio;
44 use C4::Items;
45 use C4::Members;
46 use C4::Members::Messaging;
47 use C4::Koha;   # FIXME : is it still useful ?
48 use C4::RotatingCollections;
49 use Koha::AuthorisedValues;
50 use Koha::DateUtils;
51 use Koha::Calendar;
52 use Koha::BiblioFrameworks;
53 use Koha::Checkouts;
54 use Koha::Holds;
55 use Koha::Items;
56 use Koha::Patrons;
57
58 my $query = new CGI;
59
60 #getting the template
61 my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
62     {
63         template_name   => "circ/returns.tt",
64         query           => $query,
65         type            => "intranet",
66         authnotrequired => 0,
67         flagsrequired   => { circulate => "circulate_remaining_permissions" },
68     }
69 );
70
71 my $sessionID = $query->cookie("CGISESSID");
72 my $session = get_session($sessionID);
73 if ($session->param('branch') eq 'NO_LIBRARY_SET'){
74     # no branch set we can't return
75     print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
76     exit;
77 }
78
79 # Print a reserve slip on this page
80 if ( $query->param('print_slip') ) {
81     $template->param(
82         print_slip     => 1,
83         borrowernumber => scalar $query->param('borrowernumber'),
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         my $hold = Koha::Holds->find( $reserve_id );
161         if ( $hold ) {
162             $hold->cancel( { charge_cancel_fee => !$forgivemanualholdsexpire } );
163         } # FIXME else?
164     } else {
165         my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
166         # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
167         # i.e., whether to apply waiting status
168         ModReserveAffect( $itemnumber, $borrowernumber, $diffBranchSend, $reserve_id );
169     }
170 #   check if we have other reserves for this document, if we have a return send the message of transfer
171     my ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
172
173     my $patron = Koha::Patrons->find( $nextreservinfo );
174     my $name   = $patron ? $patron->surname . ", " . $patron->title . " " . $patron->firstname : '';
175     if ( $messages->{'transfert'} ) {
176         $template->param(
177             itemtitle      => $biblio->title,
178             itemnumber     => $item->itemnumber,
179             itembiblionumber => $biblio->biblionumber,
180             iteminfo       => $biblio->author,
181             name           => $name,
182             borrowernumber => $borrowernumber,
183             borcnum        => $patron->cardnumber,
184             borfirstname   => $patron->firstname,
185             borsurname     => $patron->surname,
186             borcategory    => $patron->category->description,
187             diffbranch     => 1,
188         );
189     }
190 }
191
192 my $borrower;
193 my $returned = 0;
194 my $messages;
195 my $issue;
196 my $itemnumber;
197 my $barcode     = $query->param('barcode');
198 my $exemptfine  = $query->param('exemptfine');
199 if (
200   $exemptfine &&
201   !C4::Auth::haspermission(C4::Context->userenv->{'id'}, {'updatecharges' => 'writeoff'})
202 ) {
203     # silently prevent unauthorized operator from forgiving overdue
204     # fines by manually tweaking form parameters
205     undef $exemptfine;
206 }
207 my $dropboxmode = $query->param('dropboxmode');
208 my $dotransfer  = $query->param('dotransfer');
209 my $canceltransfer = $query->param('canceltransfer');
210 my $dest = $query->param('dest');
211 my $calendar    = Koha::Calendar->new( branchcode => $userenv_branch );
212 #dropbox: get last open day (today - 1)
213 my $today       = DateTime->now( time_zone => C4::Context->tz());
214 my $dropboxdate = $calendar->addDate($today, -1);
215
216 my $return_date_override = $query->param('return_date_override');
217 my $return_date_override_remember =
218   $query->param('return_date_override_remember');
219 if ($return_date_override) {
220     if ( C4::Context->preference('SpecifyReturnDate') ) {
221         my $return_date_override_dt = eval {dt_from_string( $return_date_override ) };
222         if ( $return_date_override_dt ) {
223             # note that we've overriden the return date
224             $template->param( return_date_was_overriden => 1);
225             # Save the original format if we are remembering for this series
226             $template->param(
227                 return_date_override          => $return_date_override,
228                 return_date_override_remember => 1
229             ) if ($return_date_override_remember);
230
231             $return_date_override =
232               DateTime::Format::MySQL->format_datetime( $return_date_override_dt );
233         }
234     }
235     else {
236         $return_date_override = q{};
237     }
238 }
239
240 if ($dotransfer){
241 # An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer
242     my $transferitem = $query->param('transferitem');
243     my $tobranch     = $query->param('tobranch');
244     ModItemTransfer($transferitem, $userenv_branch, $tobranch);
245 }
246
247 if ($canceltransfer){
248     $itemnumber=$query->param('itemnumber');
249     DeleteTransfer($itemnumber);
250     if($dest eq "ttr"){
251         print $query->redirect("/cgi-bin/koha/circ/transferstoreceive.pl");
252         exit;
253     } else {
254         $template->param( transfercancelled => 1);
255     }
256 }
257
258 # actually return book and prepare item table.....
259 my $returnbranch;
260 if ($barcode) {
261     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
262     $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter');
263     my $item = Koha::Items->find({ barcode => $barcode });
264
265     if ( $item ) {
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( $item->effective_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($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
278         $returnbranch = $item->$hbr;
279
280         my $materials = $item->materials;
281         my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
282         $materials = $descriptions->{lib} // $materials;
283
284         my $checkout = $item->checkout;
285         my $biblio   = $item->biblio;
286         $template->param(
287             title            => $biblio->title,
288             homebranch       => $item->homebranch,
289             holdingbranch    => $item->holdingbranch,
290             returnbranch     => $returnbranch,
291             author           => $biblio->author,
292             itembarcode      => $item->barcode,
293             itemtype         => $item->effective_itemtype,
294             ccode            => $item->ccode,
295             itembiblionumber => $biblio->biblionumber,
296             biblionumber     => $biblio->biblionumber,
297             borrower         => $borrower,
298             additional_materials => $materials,
299             issue            => $checkout,
300         );
301     } # FIXME else we should not call AddReturn but set BadBarcode directly instead
302
303     my %input = (
304         counter => 0,
305         first   => 1,
306         barcode => $barcode,
307     );
308
309
310     # do the return
311     ( $returned, $messages, $issue, $borrower ) =
312       AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override, $dropboxdate );
313
314     if ($returned) {
315         my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
316         my $date_due_dt = dt_from_string( $issue->date_due, 'sql' );
317         my $duedate = $date_due_dt->strftime('%Y-%m-%d %H:%M');
318         $returneditems{0}      = $barcode;
319         $riborrowernumber{0}   = $borrower->{'borrowernumber'};
320         $riduedate{0}          = $duedate;
321         $input{borrowernumber} = $borrower->{'borrowernumber'};
322         $input{duedate}        = $duedate;
323         unless ( $dropboxmode ) {
324             $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, DateTime->now()) == -1);
325         } else {
326             $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, $dropboxdate) == -1);
327         }
328         push( @inputloop, \%input );
329
330         if ( C4::Context->preference("FineNotifyAtCheckin") ) {
331             my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
332             my $balance = $patron->account->balance;
333
334             if ($balance > 0) {
335                 $template->param( fines => sprintf("%.2f", $balance) );
336                 $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
337             }
338         }
339
340         if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
341             #Check for waiting holds
342             my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
343             my $waiting_holds = $patron->holds->search({ found => 'W', branchcode => $userenv_branch })->count;
344             if ($waiting_holds > 0) {
345                 $template->param(
346                     waiting_holds       => $waiting_holds,
347                     holdsborrowernumber => $borrower->{'borrowernumber'},
348                     holdsfirstname => $borrower->{'firstname'},
349                     holdssurname => $borrower->{'surname'},
350                 );
351             }
352         }
353     } elsif ( C4::Context->preference('ShowAllCheckins') and !$messages->{'BadBarcode'} ) {
354         $input{duedate}   = 0;
355         $returneditems{0} = $barcode;
356         $riduedate{0}     = 0;
357         push( @inputloop, \%input );
358     }
359     $template->param( privacy => $borrower->{privacy} );
360 }
361 $template->param( inputloop => \@inputloop );
362
363 my $found    = 0;
364 my $waiting  = 0;
365 my $reserved = 0;
366
367 # new op dev : we check if the document must be returned to his homebranch directly,
368 #  if the document is transfered, we have warning message .
369
370 if ( $messages->{'WasTransfered'} ) {
371     $template->param(
372         found          => 1,
373         transfer       => 1,
374         itemnumber     => $itemnumber,
375     );
376 }
377
378 if ( $messages->{'NeedsTransfer'} ){
379     $template->param(
380         found          => 1,
381         needstransfer  => $messages->{'NeedsTransfer'},
382         itemnumber     => $itemnumber,
383     );
384 }
385
386 if ( $messages->{'Wrongbranch'} ){
387     $template->param(
388         wrongbranch => 1,
389         rightbranch => $messages->{'Wrongbranch'}->{'Rightbranch'},
390     );
391 }
392
393 # case of wrong transfert, if the document wasn't transfered to the right library (according to branchtransfer (tobranch) BDD)
394
395 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
396     $template->param(
397         WrongTransfer  => 1,
398         TransferWaitingAt => $messages->{'WrongTransfer'},
399         WrongTransferItem => $messages->{'WrongTransferItem'},
400         itemnumber => $itemnumber,
401     );
402
403     my $reserve    = $messages->{'ResFound'};
404     if ( $reserve ) {
405         my $patron = Koha::Patrons->find( $reserve->{'borrowernumber'} );
406         my $name = $patron->surname . ", " . $patron->title . " " . $patron->firstname;
407         $template->param(
408             # FIXME The full patron object should be passed to the template
409                 wname           => $name,
410                 wborfirstname   => $patron->firstname,
411                 wborsurname     => $patron->surname,
412                 wborcategory    => $patron->category->description,
413                 wbortitle       => $patron->title,
414                 wborphone       => $patron->phone,
415                 wboremail       => $patron->email,
416                 streetnumber    => $patron->streetnumber,
417                 address         => $patron->address,
418                 address2        => $patron->address2,
419                 city            => $patron->city,
420                 zipcode         => $patron->zipcode,
421                 state           => $patron->state,
422                 country         => $patron->country,
423                 wborrowernumber => $reserve->{'borrowernumber'},
424                 wborcnum        => $patron->cardnumber,
425         );
426     }
427     $template->param(
428         wtransfertFrom  => $userenv_branch,
429     );
430 }
431
432 #
433 # reserve found and item arrived at the expected branch
434 #
435 if ( $messages->{'ResFound'}) {
436     my $reserve    = $messages->{'ResFound'};
437     my $patron = Koha::Patrons->find( $reserve->{borrowernumber} );
438     my $holdmsgpreferences =  C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name   => 'Hold_Filled' } );
439     if ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
440         if ( $reserve->{'ResFound'} eq "Waiting" ) {
441             $template->param(
442                 waiting      => ($userenv_branch eq $reserve->{'branchcode'} ? 1 : 0 ),
443             );
444         } elsif ( $reserve->{'ResFound'} eq "Reserved" ) {
445             $template->param(
446                 intransit    => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
447                 transfertodo => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
448                 reserve_id   => $reserve->{reserve_id},
449                 reserved     => 1,
450             );
451         }
452
453         # same params for Waiting or Reserved
454         $template->param(
455             # FIXME The full patron object should be passed to the template
456             found          => 1,
457             name           => $patron->surname . ", " . $patron->title . " " . $patron->firstname,
458             borfirstname   => $patron->firstname,
459             borsurname     => $patron->surname,
460             borcategory    => $patron->category->description,
461             bortitle       => $patron->title,
462             borphone       => $patron->phone,
463             boremail       => $patron->email,
464             boraddress     => $patron->address,
465             boraddress2    => $patron->address2,
466             streetnumber   => $patron->streetnumber,
467             city           => $patron->city,
468             zipcode        => $patron->zipcode,
469             state          => $patron->state,
470             country        => $patron->country,
471             borcnum        => $patron->cardnumber,
472             debarred       => $patron->debarred,
473             gonenoaddress  => $patron->gonenoaddress,
474             barcode        => $barcode,
475             destbranch     => $reserve->{'branchcode'},
476             borrowernumber => $reserve->{'borrowernumber'},
477             itemnumber     => $reserve->{'itemnumber'},
478             reservenotes   => $reserve->{'reservenotes'},
479             reserve_id     => $reserve->{reserve_id},
480             bormessagepref => $holdmsgpreferences->{'transports'},
481         );
482     } # else { ; }  # error?
483 }
484
485 # Error Messages
486 my @errmsgloop;
487 foreach my $code ( keys %$messages ) {
488     my %err;
489     my $exit_required_p = 0;
490     if ( $code eq 'BadBarcode' ) {
491         $err{badbarcode} = 1;
492         $err{msg}        = $messages->{'BadBarcode'};
493     }
494     elsif ( $code eq 'NotIssued' ) {
495         $err{notissued} = 1;
496         $err{msg} = '';
497         $err{msg} = $messages->{'IsPermanent'} if $messages->{'IsPermanent'};
498     }
499     elsif ( $code eq 'LocalUse' ) {
500         $err{localuse} = 1;
501     }
502     elsif ( $code eq 'WasLost' ) {
503         $err{waslost} = 1;
504         $exit_required_p = 1 if C4::Context->preference("BlockReturnOfLostItems");
505     }
506     elsif ( $code eq 'LostItemFeeRefunded' ) {
507         $template->param( LostItemFeeRefunded => 1 );
508     }
509     elsif ( $code eq 'ResFound' ) {
510         ;    # FIXME... anything to do here?
511     }
512     elsif ( $code eq 'WasReturned' ) {
513         ;    # FIXME... anything to do here?
514     }
515     elsif ( $code eq 'WasTransfered' ) {
516         ;    # FIXME... anything to do here?
517     }
518     elsif ( $code eq 'withdrawn' ) {
519         $err{withdrawn} = 1;
520         $exit_required_p = 1 if C4::Context->preference("BlockReturnOfWithdrawnItems");
521     }
522     elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
523         if ( $messages->{'IsPermanent'} ne $userenv_branch ) {
524             $err{ispermanent} = 1;
525             $err{msg}         = $messages->{'IsPermanent'};
526         }
527     }
528     elsif ( $code eq 'WrongTransfer' ) {
529         ;    # FIXME... anything to do here?
530     }
531     elsif ( $code eq 'WrongTransferItem' ) {
532         ;    # FIXME... anything to do here?
533     }
534     elsif ( $code eq 'NeedsTransfer' ) {
535     }
536     elsif ( $code eq 'Wrongbranch' ) {
537     }
538     elsif ( $code eq 'Debarred' ) {
539         $err{debarred}            = $messages->{'Debarred'};
540         $err{debarcardnumber}     = $borrower->{cardnumber};
541         $err{debarborrowernumber} = $borrower->{borrowernumber};
542         $err{debarname}           = "$borrower->{firstname} $borrower->{surname}";
543     }
544     elsif ( $code eq 'PrevDebarred' ) {
545         $err{prevdebarred}        = $messages->{'PrevDebarred'};
546     }
547     elsif ( $code eq 'ForeverDebarred' ) {
548         $err{foreverdebarred}        = $messages->{'ForeverDebarred'};
549     }
550     elsif ( $code eq 'NotForLoanStatusUpdated' ) {
551         $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
552     }
553     elsif ( $code eq 'DataCorrupted' ) {
554         $err{data_corrupted} = 1;
555     }
556     else {
557         die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
558         # This forces the issue of staying in sync w/ Circulation.pm
559     }
560     if (%err) {
561         push( @errmsgloop, \%err );
562     }
563     last if $exit_required_p;
564 }
565 $template->param( errmsgloop => \@errmsgloop );
566
567 #set up so only the last 8 returned items display (make for faster loading pages)
568 my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C4::Context->preference('numReturnedItemsToShow') : 8;
569 my $count = 0;
570 my @riloop;
571 my $shelflocations =
572   { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) };
573 foreach ( sort { $a <=> $b } keys %returneditems ) {
574     my %ri;
575     if ( $count++ < $returned_counter ) {
576         my $bar_code = $returneditems{$_};
577         if ($riduedate{$_}) {
578             my $duedate = dt_from_string( $riduedate{$_}, 'sql');
579             $ri{year}  = $duedate->year();
580             $ri{month} = $duedate->month();
581             $ri{day}   = $duedate->day();
582             $ri{hour}   = $duedate->hour();
583             $ri{minute}   = $duedate->minute();
584             $ri{duedate} = output_pref($duedate);
585             my $patron = Koha::Patrons->find( $riborrowernumber{$_} );
586             unless ( $dropboxmode ) {
587                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, DateTime->now()) == -1);
588             } else {
589                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, $dropboxdate) == -1);
590             }
591             $ri{borrowernumber} = $patron->borrowernumber;
592             $ri{borcnum}        = $patron->cardnumber;
593             $ri{borfirstname}   = $patron->firstname;
594             $ri{borsurname}     = $patron->surname;
595             $ri{bortitle}       = $patron->title;
596             $ri{bornote}        = $patron->borrowernotes;
597             $ri{borcategorycode}= $patron->categorycode;
598             $ri{borissuescount} = Koha::Checkouts->count( { borrowernumber => $b->{'borrowernumber'} } );
599         }
600         else {
601             $ri{borrowernumber} = $riborrowernumber{$_};
602         }
603
604         my $item = Koha::Items->find({ barcode => $bar_code });
605         my $biblio = $item->biblio;
606         # FIXME pass $item to the template and we are done here...
607         $ri{itembiblionumber}    = $biblio->biblionumber;
608         $ri{itemtitle}           = $biblio->title;
609         $ri{itemauthor}          = $biblio->author;
610         $ri{itemcallnumber}      = $item->itemcallnumber;
611         $ri{dateaccessioned}     = $item->dateaccessioned;
612         $ri{itemtype}            = $item->effective_itemtype;
613         $ri{itemnote}            = $item->itemnotes;
614         $ri{itemnotes_nonpublic} = $item->itemnotes_nonpublic;
615         $ri{ccode}               = $item->ccode;
616         $ri{enumchron}           = $item->enumchron;
617         $ri{itemnumber}          = $item->itemnumber;
618         $ri{barcode}             = $bar_code;
619         $ri{homebranch}          = $item->homebranch;
620         $ri{holdingbranch}       = $item->holdingbranch;
621
622         $ri{location}         = $biblio->{'location'};
623         my $shelfcode = $ri{'location'};
624         $ri{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
625
626     }
627     else {
628         last;
629     }
630     push @riloop, \%ri;
631 }
632
633 $template->param(
634     riloop         => \@riloop,
635     printer        => $printer,
636     errmsgloop     => \@errmsgloop,
637     exemptfine     => $exemptfine,
638     dropboxmode    => $dropboxmode,
639     dropboxdate    => output_pref($dropboxdate),
640     forgivemanualholdsexpire => $forgivemanualholdsexpire,
641     overduecharges => $overduecharges,
642     AudioAlerts        => C4::Context->preference("AudioAlerts"),
643 );
644
645 $itemnumber = GetItemnumberFromBarcode( $barcode );
646 if ( $itemnumber ) {
647     my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
648     if ( $holdingBranch and $collectionBranch ) {
649         $holdingBranch //= '';
650         $collectionBranch //= $returnbranch;
651         if ( ! ( $holdingBranch eq $collectionBranch ) ) {
652             $template->param(
653               collectionItemNeedsTransferred => 1,
654               collectionBranch => $collectionBranch,
655               itemnumber => $itemnumber,
656             );
657         }
658     }
659 }
660
661 # Checking if there is a Fast Cataloging Framework
662 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
663
664 # actually print the page!
665 output_html_with_http_headers $query, $cookie, $template->output;