+
+ $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;