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