+ # if the holdingbranch is different than the homebranch, we show the
+ # holdingbranch of the document too
+ if ( $item->{homebranch} ne $item->{holdingbranch} ) {
+ $item->{holdingbranchname} =
+ $branches->{ $item->{holdingbranch} }{branchname};
+ }
+
+ if($item->{biblionumber} ne $biblionumber){
+ $item->{hostitemsflag}=1;
+ $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
+ }
+
+ # add information
+ $item->{itemcallnumber} = $item->{itemcallnumber};
+
+ # if the item is currently on loan, we display its return date and
+ # change the background color
+ my $issues= GetItemIssue($itemnumber);
+ if ( $issues->{'date_due'} ) {
+ $item->{date_due} = format_date($issues->{'date_due'});
+ $item->{backgroundcolor} = 'onloan';
+ }
+
+ # checking reserve
+ my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemnumber);
+ my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
+
+ if ( defined $reservedate ) {
+ $item->{backgroundcolor} = 'reserved';
+ $item->{reservedate} = format_date($reservedate);
+ $item->{ReservedForBorrowernumber} = $reservedfor;
+ $item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
+ $item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
+ $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
+
+ }
+
+ # Management of the notforloan document
+ if ( $item->{notforloan} ) {
+ $item->{backgroundcolor} = 'other';
+ $item->{notforloanvalue} =
+ $notforloan_label_of->{ $item->{notforloan} };
+ }
+
+ # Management of lost or long overdue items
+ if ( $item->{itemlost} ) {
+
+ # FIXME localized strings should never be in Perl code
+ $item->{message} =
+ $item->{itemlost} == 1 ? "(lost)"
+ : $item->{itemlost} == 2 ? "(long overdue)"
+ : "";
+ $item->{backgroundcolor} = 'other';
+ if (GetHideLostItemsPreference($borrowernumber) && !$showallitems) {
+ $item->{hide} = 1;
+ $hiddencount++;
+ }
+ }
+
+ # Check the transit status
+ my ( $transfertwhen, $transfertfrom, $transfertto ) =
+ GetTransfers($itemnumber);
+
+ if ( defined $transfertwhen && $transfertwhen ne '' ) {
+ $item->{transfertwhen} = format_date($transfertwhen);
+ $item->{transfertfrom} =
+ $branches->{$transfertfrom}{branchname};
+ $item->{transfertto} = $branches->{$transfertto}{branchname};
+ $item->{nocancel} = 1;
+ }
+
+ # If there is no loan, return and transfer, we show a checkbox.
+ $item->{notforloan} = $item->{notforloan} || 0;
+
+ # if independent branches is on we need to check if the person can reserve
+ # for branches they arent logged in to
+ if ( C4::Context->preference("IndependantBranches") ) {
+ if (! C4::Context->preference("canreservefromotherbranches")){
+ # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
+ my $userenv = C4::Context->userenv;
+ if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
+ $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
+ }
+ }
+ }
+
+ my $branch = C4::Circulation::_GetCircControlBranch($item, $borrowerinfo);
+
+ my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
+ my $policy_holdallowed = 1;
+
+ $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
+
+ if ( $branchitemrule->{'holdallowed'} == 0 ||
+ ( $branchitemrule->{'holdallowed'} == 1 &&
+ $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} ) ) {
+ $policy_holdallowed = 0;
+ }