| Lines 854-860
          sub CheckReserves {
      
      
        Link Here | 
        
          | 854 |            items.biblioitemnumber, | 854 |            items.biblioitemnumber, | 
        
          | 855 |            itemtypes.notforloan, | 855 |            itemtypes.notforloan, | 
        
          | 856 |            items.notforloan AS itemnotforloan, | 856 |            items.notforloan AS itemnotforloan, | 
          
            
              | 857 |            items.itemnumber | 857 |            items.itemnumber, | 
            
              |  |  | 858 |            items.homebranch, | 
            
              | 859 |            items.holdingbranch | 
        
          | 858 |            FROM   items | 860 |            FROM   items | 
        
          | 859 |            LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber | 861 |            LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber | 
        
          | 860 |            LEFT JOIN itemtypes   ON items.itype   = itemtypes.itemtype | 862 |            LEFT JOIN itemtypes   ON items.itype   = itemtypes.itemtype | 
  
    | Lines 866-872
          sub CheckReserves {
      
      
        Link Here | 
        
          | 866 |            items.biblioitemnumber, | 868 |            items.biblioitemnumber, | 
        
          | 867 |            itemtypes.notforloan, | 869 |            itemtypes.notforloan, | 
        
          | 868 |            items.notforloan AS itemnotforloan, | 870 |            items.notforloan AS itemnotforloan, | 
          
            
              | 869 |            items.itemnumber | 871 |            items.itemnumber, | 
            
              |  |  | 872 |            items.homebranch, | 
            
              | 873 |            items.holdingbranch | 
        
          | 870 |            FROM   items | 874 |            FROM   items | 
        
          | 871 |            LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber | 875 |            LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber | 
        
          | 872 |            LEFT JOIN itemtypes   ON biblioitems.itemtype   = itemtypes.itemtype | 876 |            LEFT JOIN itemtypes   ON biblioitems.itemtype   = itemtypes.itemtype | 
  
    | Lines 882-893
          sub CheckReserves {
      
      
        Link Here | 
        
          | 882 |         $sth->execute($barcode); | 886 |         $sth->execute($barcode); | 
        
          | 883 |     } | 887 |     } | 
        
          | 884 |     # note: we get the itemnumber because we might have started w/ just the barcode.  Now we know for sure we have it. | 888 |     # note: we get the itemnumber because we might have started w/ just the barcode.  Now we know for sure we have it. | 
          
            
              | 885 |     my ( $biblio, $bibitem, $notforloan_per_itemtype, $notforloan_per_item, $itemnumber ) = $sth->fetchrow_array; | 889 |     my ( $biblio, $bibitem, $notforloan_per_itemtype, $notforloan_per_item, | 
            
              |  |  | 890 |         $itemnumber, $item_homebranch, $item_holdingbranch ) | 
            
              | 891 |       = $sth->fetchrow_array; | 
        
          | 886 |  | 892 |  | 
        
          | 887 |     return ( '' ) unless $itemnumber; # bail if we got nothing. | 893 |     return ( '' ) unless $itemnumber; # bail if we got nothing. | 
        
          | 888 |  | 894 |  | 
        
          | 889 |     # if item is not for loan it cannot be reserved either..... | 895 |     # if item is not for loan it cannot be reserved either..... | 
          
            
              | 890 |     #    execpt where items.notforloan < 0 :  This indicates the item is holdable.  | 896 |     # except where items.notforloan < 0 :  This indicates the item is holdable. | 
        
          | 891 |     return ( '' ) if  ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype; | 897 |     return ( '' ) if  ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype; | 
        
          | 892 |  | 898 |  | 
        
          | 893 |     # Find this item in the reserves | 899 |     # Find this item in the reserves | 
  
    | Lines 899-919
          sub CheckReserves {
      
      
        Link Here | 
        
          | 899 |     # $highest is the most important item we've seen so far. | 905 |     # $highest is the most important item we've seen so far. | 
        
          | 900 |     my $highest; | 906 |     my $highest; | 
        
          | 901 |     if (scalar @reserves) { | 907 |     if (scalar @reserves) { | 
            
              |  |  | 908 |         my $LocalHoldsPriority = C4::Context->preference('LocalHoldsPriority'); | 
            
              | 909 |         my $LocalHoldsPriorityPatronControl = C4::Context->preference('LocalHoldsPriorityPatronControl'); | 
            
              | 910 |         my $LocalHoldsPriorityItemControl = C4::Context->preference('LocalHoldsPriorityItemControl'); | 
            
              | 911 |  | 
        
          | 902 |         my $priority = 10000000; | 912 |         my $priority = 10000000; | 
        
          | 903 |         foreach my $res (@reserves) { | 913 |         foreach my $res (@reserves) { | 
        
          | 904 |             if ( $res->{'itemnumber'} == $itemnumber && $res->{'priority'} == 0) { | 914 |             if ( $res->{'itemnumber'} == $itemnumber && $res->{'priority'} == 0) { | 
        
          | 905 |                 return ( "Waiting", $res, \@reserves ); # Found it | 915 |                 return ( "Waiting", $res, \@reserves ); # Found it | 
        
          | 906 |             } else { | 916 |             } else { | 
            
              |  |  | 917 |                 # Lazy fetch for borrower and item. We only need to know about the patron and item | 
            
              | 918 |                 # each and every time if we are using LocalHoldsPriority. This is a great place to | 
            
              | 919 |                 # leverage the inherent lazy fetching of DBIx::Class. | 
            
              | 920 |                 my $borrowerinfo; | 
            
              | 921 |                 my $iteminfo; | 
            
              | 922 |  | 
            
              | 923 |                 my $local_hold_match; | 
            
              | 924 |                 if ($LocalHoldsPriority) { | 
            
              | 925 |                     $borrowerinfo = C4::Members::GetMember( borrowernumber => $res->{'borrowernumber'} ); | 
            
              | 926 |                     $iteminfo = C4::Items::GetItem($itemnumber); | 
            
              | 927 |  | 
            
              | 928 |                     my $local_holds_priority_item_branchcode = | 
            
              | 929 |                       $iteminfo->{$LocalHoldsPriorityItemControl}; | 
            
              | 930 |                     my $local_holds_priority_patron_branchcode = | 
            
              | 931 |                       ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' ) | 
            
              | 932 |                       ? $res->{branchcode} | 
            
              | 933 |                       : ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' ) | 
            
              | 934 |                       ? $borrowerinfo->{branchcode} | 
            
              | 935 |                       : undef; | 
            
              | 936 |                     $local_hold_match = | 
            
              | 937 |                       $local_holds_priority_item_branchcode eq | 
            
              | 938 |                       $local_holds_priority_patron_branchcode; | 
            
              | 939 |                 } | 
            
              | 940 |  | 
        
          | 907 |                 # See if this item is more important than what we've got so far | 941 |                 # See if this item is more important than what we've got so far | 
          
            
              | 908 |                 if ( $res->{'priority'} && $res->{'priority'} < $priority ) { | 942 |                 if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) { | 
            
              | 909 |                     my $borrowerinfo=C4::Members::GetMember(borrowernumber => $res->{'borrowernumber'}); | 943 |                     $borrowerinfo ||= C4::Members::GetMember( borrowernumber => $res->{'borrowernumber'} ); | 
            
              | 910 |                     my $iteminfo=C4::Items::GetItem($itemnumber); | 944 |                     $iteminfo ||= C4::Items::GetItem($itemnumber); | 
        
          | 911 |                     my $branch = GetReservesControlBranch( $iteminfo, $borrowerinfo ); | 945 |                     my $branch = GetReservesControlBranch( $iteminfo, $borrowerinfo ); | 
        
          | 912 |                     my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'}); | 946 |                     my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'}); | 
        
          | 913 |                     next if ($branchitemrule->{'holdallowed'} == 0); | 947 |                     next if ($branchitemrule->{'holdallowed'} == 0); | 
        
          | 914 |                     next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'})); | 948 |                     next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'})); | 
        
          | 915 |                     $priority = $res->{'priority'}; | 949 |                     $priority = $res->{'priority'}; | 
        
          | 916 |                     $highest  = $res; | 950 |                     $highest  = $res; | 
            
              |  |  | 951 |                     last if $local_hold_match; | 
        
          | 917 |                 } | 952 |                 } | 
        
          | 918 |             } | 953 |             } | 
        
          | 919 |         } | 954 |         } |