+
+ $biblioLoopIter{biblionumber} = $biblioData->{biblionumber};
+ $biblioLoopIter{title} = $biblioData->{title};
+ $biblioLoopIter{subtitle} = GetRecordValue('subtitle', $record, GetFrameworkCode($biblioData->{biblionumber}));
+ $biblioLoopIter{author} = $biblioData->{author};
+ $biblioLoopIter{rank} = $biblioData->{rank};
+ $biblioLoopIter{reservecount} = $biblioData->{reservecount};
+ $biblioLoopIter{already_reserved} = $biblioData->{already_reserved};
+
+ if (!$itemLevelTypes && $biblioData->{itemtype}) {
+ $biblioLoopIter{description} = $itemTypes->{$biblioData->{itemtype}}{description};
+ $biblioLoopIter{imageurl} = getitemtypeimagesrc() . "/". $itemTypes->{$biblioData->{itemtype}}{imageurl};
+ }
+
+ foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
+ $debug and warn $itemInfo->{'notforloan'};
+
+ # Get reserve fee.
+ my $fee = GetReserveFee(undef, $borrowernumber, $itemInfo->{'biblionumber'}, 'a',
+ ( $itemInfo->{'biblioitemnumber'} ) );
+ $itemInfo->{'reservefee'} = sprintf "%.02f", ($fee ? $fee : 0.0);
+
+ if ($itemLevelTypes && $itemInfo->{itype}) {
+ $itemInfo->{description} = $itemTypes->{$itemInfo->{itype}}{description};
+ $itemInfo->{imageurl} = getitemtypeimagesrc() . "/". $itemTypes->{$itemInfo->{itype}}{imageurl};
+ }
+
+ if (!$itemInfo->{'notforloan'} && !($itemInfo->{'itemnotforloan'} > 0)) {
+ $biblioLoopIter{forloan} = 1;
+ }
+ }
+
+ $biblioLoopIter{itemTypeDescription} = $itemTypes->{$biblioData->{itemtype}}{description};
+
+ $biblioLoopIter{itemLoop} = [];
+ my $numCopiesAvailable = 0;
+ foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
+ my $itemNum = $itemInfo->{itemnumber};
+ my $itemLoopIter = {};
+
+ $itemLoopIter->{itemnumber} = $itemNum;
+ $itemLoopIter->{barcode} = $itemInfo->{barcode};
+ $itemLoopIter->{homeBranchName} = $branches->{$itemInfo->{homebranch}}{branchname};
+ $itemLoopIter->{callNumber} = $itemInfo->{itemcallnumber};
+ $itemLoopIter->{enumchron} = $itemInfo->{enumchron};
+ $itemLoopIter->{copynumber} = $itemInfo->{copynumber};
+ if ($itemLevelTypes) {
+ $itemLoopIter->{description} = $itemInfo->{description};
+ $itemLoopIter->{imageurl} = $itemInfo->{imageurl};
+ }
+
+ # If the holdingbranch is different than the homebranch, we show the
+ # holdingbranch of the document too.
+ if ( $itemInfo->{homebranch} ne $itemInfo->{holdingbranch} ) {
+ $itemLoopIter->{holdingBranchName} =
+ $branches->{ $itemInfo->{holdingbranch} }{branchname};
+ }
+
+ # If the item is currently on loan, we display its return date and
+ # change the background color.
+ my $issues= GetItemIssue($itemNum);
+ if ( $issues->{'date_due'} ) {
+ $itemLoopIter->{dateDue} = format_date($issues->{'date_due'});
+ $itemLoopIter->{backgroundcolor} = 'onloan';
+ }
+
+ # checking reserve
+ my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemNum);
+ my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
+
+ if ( defined $reservedate ) {
+ $itemLoopIter->{backgroundcolor} = 'reserved';
+ $itemLoopIter->{reservedate} = format_date($reservedate);
+ $itemLoopIter->{ReservedForBorrowernumber} = $reservedfor;
+ $itemLoopIter->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
+ $itemLoopIter->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
+ $itemLoopIter->{ExpectedAtLibrary} = $expectedAt;
+ }
+
+ $itemLoopIter->{notforloan} = $itemInfo->{notforloan};
+ $itemLoopIter->{itemnotforloan} = $itemInfo->{itemnotforloan};
+
+ # Management of the notforloan document
+ if ( $itemLoopIter->{notforloan} || $itemLoopIter->{itemnotforloan}) {
+ $itemLoopIter->{backgroundcolor} = 'other';
+ $itemLoopIter->{notforloanvalue} =
+ $notforloan_label_of->{ $itemLoopIter->{notforloan} };
+ }
+
+ # Management of lost or long overdue items
+ if ( $itemInfo->{itemlost} ) {
+
+ # FIXME localized strings should never be in Perl code
+ $itemLoopIter->{message} =
+ $itemInfo->{itemlost} == 1 ? "(lost)"
+ : $itemInfo->{itemlost} == 2 ? "(long overdue)"
+ : "";
+ $itemInfo->{backgroundcolor} = 'other';
+ }
+
+ # Check of the transfered documents
+ my ( $transfertwhen, $transfertfrom, $transfertto ) =
+ GetTransfers($itemNum);
+ if ( $transfertwhen && ($transfertwhen ne '') ) {
+ $itemLoopIter->{transfertwhen} = format_date($transfertwhen);
+ $itemLoopIter->{transfertfrom} =
+ $branches->{$transfertfrom}{branchname};
+ $itemLoopIter->{transfertto} = $branches->{$transfertto}{branchname};
+ $itemLoopIter->{nocancel} = 1;
+ }
+
+ # If there is no loan, return and transfer, we show a checkbox.
+ $itemLoopIter->{notforloan} = $itemLoopIter->{notforloan} || 0;
+
+ my $branch = C4::Circulation::_GetCircControlBranch($itemLoopIter, $borr);
+
+ my $branchitemrule = GetBranchItemRule( $branch, $itemInfo->{'itype'} );
+ my $policy_holdallowed = 1;
+
+ if ( $branchitemrule->{'holdallowed'} == 0 ||
+ ( $branchitemrule->{'holdallowed'} == 1 && $borr->{'branchcode'} ne $itemInfo->{'homebranch'} ) ) {
+ $policy_holdallowed = 0;
+ }
+
+ if (IsAvailableForItemLevelRequest($itemNum) and $policy_holdallowed and CanItemBeReserved($borrowernumber,$itemNum)) {
+ $itemLoopIter->{available} = 1;
+ $numCopiesAvailable++;
+ }
+
+ # FIXME: move this to a pm
+ my $dbh = C4::Context->dbh;
+ my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
+ $sth2->execute($itemLoopIter->{ReservedForBorrowernumber}, $itemNum);
+ while (my $wait_hashref = $sth2->fetchrow_hashref) {
+ $itemLoopIter->{waitingdate} = format_date($wait_hashref->{waitingdate});
+ }
+ $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} );
+
+ # Show serial enumeration when needed
+ if ($itemLoopIter->{enumchron}) {
+ $itemdata_enumchron = 1;
+ }
+ $template->param( itemdata_enumchron => $itemdata_enumchron );
+
+ push @{$biblioLoopIter{itemLoop}}, $itemLoopIter;
+ }
+
+ if ($numCopiesAvailable > 0) {
+ $numBibsAvailable++;
+ $biblioLoopIter{bib_available} = 1;
+ $biblioLoopIter{holdable} = 1;
+ }
+ if ($biblioLoopIter{already_reserved}) {
+ $biblioLoopIter{holdable} = undef;
+ }
+ if(not CanBookBeReserved($borrowernumber,$biblioNum)){
+ $biblioLoopIter{holdable} = undef;
+ }
+
+ push @$biblioLoop, \%biblioLoopIter;