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