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