+unless ($noreserves) {
+ $template->param( select_item_types => 1 );
+}
+
+
+#
+#
+# Build the template parameters that will show the info
+# and items for each biblionumber.
+#
+#
+my $notforloan_label_of = get_notforloan_label_of();
+
+my $biblioLoop = [];
+my $numBibsAvailable = 0;
+my $itemdata_enumchron = 0;
+my $anyholdable;
+my $itemLevelTypes = C4::Context->preference('item-level_itypes');
+$template->param('item_level_itypes' => $itemLevelTypes);
+
+foreach my $biblioNum (@biblionumbers) {
+
+ my $record = GetMarcBiblio($biblioNum);
+ # Init the bib item with the choices for branch pickup
+ my %biblioLoopIter = ( branchChoicesLoop => $CGIbranchloop );
+
+ # Get relevant biblio data.
+ my $biblioData = $biblioDataHash{$biblioNum};
+ if (! $biblioData) {
+ $template->param(message=>1, bad_biblionumber=>$biblioNum);
+ &get_out($query, $cookie, $template->output);
+ }
+
+ $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{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_sqlduedatetime($issues->{date_due});
+ $itemLoopIter->{backgroundcolor} = 'onloan';
+ }
+
+ # checking reserve
+ my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemNum);
+ my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
+
+ # the item could be reserved for this borrower vi a host record, flag this
+ if ($reservedfor eq $borrowernumber){
+ $itemLoopIter->{already_reserved} = 1;