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