- # last check for norequest : if itemtype is notforloan, it can't be reserved either, whatever the items
- $norequests = 1 if $itemtypes{$oldbiblio->{itemtype}}->{notforloan};
-
- for my $key ( sort keys %$items ) {
- my $this_item = {
- branchname => $branches{$items->{$key}->{branchcode}},
- branchcode => $items->{$key}->{branchcode},
- count => $items->{$key}->{count},
- itemcallnumber => $items->{$key}->{itemcallnumber},
- location => $items->{$key}->{location},
- onloancount => $items->{$key}->{onloancount},
- due_date => $items->{$key}->{due_date},
- wthdrawn => $items->{$key}->{wthdrawn},
- lost => $items->{$key}->{itemlost},
- };
- push @items_loop, $this_item;
+# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
+ if ( $item->{onloan} ) {
+ $onloan_count++;
+ $onloan_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{due_date} }->{due_date} = format_date( $item->{onloan} );
+ $onloan_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{due_date} }->{count}++ if $item->{'homebranch'};
+ $onloan_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{due_date} }->{branchname} = $item->{'branchname'};
+ $onloan_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{due_date} }->{location} = $locations{ $item->{location} };
+ $onloan_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{due_date} }->{itemcallnumber} = $item->{itemcallnumber};
+ $onloan_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{due_date} }->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
+ # if something's checked out and lost, mark it as 'long overdue'
+ if ( $item->{itemlost} ) {
+ $onloan_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{due_date} }->{longoverdue}++;
+ $longoverdue_count++;
+ }
+
+ # can place holds as long as this item isn't lost
+ else {
+ $can_place_holds = 1;
+ }
+ }
+
+ # items not on loan, but still unavailable ( lost, withdrawn, damaged )
+ else {
+
+ # item is on order
+ if ( $item->{notforloan} == -1 ) {
+ $ordered_count++;
+ }
+
+ # item is withdrawn, lost or damaged
+ if ( $item->{wthdrawn}
+ || $item->{itemlost}
+ || $item->{damaged}
+ || $item->{notforloan} )
+ {
+ $wthdrawn_count++ if $item->{wthdrawn};
+ $itemlost_count++ if $item->{itemlost};
+ $itemdamaged_count++ if $item->{damaged};
+ $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
+ $other_count++;
+
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{wthdrawn} = $item->{wthdrawn};
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{itemlost} = $item->{itemlost};
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{damaged} = $item->{damaged};
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{notforloan} = GetAuthorisedValueDesc( '', '', $item->{notforloan}, '', '', $notforloan_authorised_value ) if $notforloan_authorised_value;
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{count}++ if $item->{'homebranch'};
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{branchname} = $item->{'branchname'};
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{location} = $locations{ $item->{location} };
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{itemcallnumber} = $item->{itemcallnumber};
+ $other_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} . $item->{status} }->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
+ }
+
+ # item is available
+ else {
+ $can_place_holds = 1;
+ $available_count++;
+ $available_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} }->{count}++ if $item->{'homebranch'};
+ $available_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} }->{branchname} = $item->{'branchname'};
+ $available_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} }->{location} = $locations{ $item->{location} };
+ $available_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} }->{itemcallnumber} = $item->{itemcallnumber};
+ $available_items->{ $item->{'homebranch'} . '--' . $item->{location} . $item->{'itype'} . $item->{'itemcallnumber'} }->{imageurl} = getitemtypeimagesrc() . "/" . $itemtypes{ $item->{itype} }->{imageurl};
+ }
+ }
+ } # notforloan, item level and biblioitem level
+ my ( $availableitemscount, $onloanitemscount, $otheritemscount );
+ my $maxitems =
+ ( C4::Context->preference('maxItemsinSearchResults') )
+ ? C4::Context->preference('maxItemsinSearchResults') - 1
+ : 1;
+ for my $key ( sort keys %$onloan_items ) {
+ $onloanitemscount++;
+ push @onloan_items_loop, $onloan_items->{$key}
+ unless $onloanitemscount > $maxitems;
+ }
+ for my $key ( sort keys %$other_items ) {
+ $otheritemscount++;
+ push @other_items_loop, $other_items->{$key}
+ unless $otheritemscount > $maxitems;
+ }
+ for my $key ( sort keys %$available_items ) {
+ $availableitemscount++;
+ push @available_items_loop, $available_items->{$key}
+ unless $availableitemscount > $maxitems;