From b50051a8e533c86e1f453b24fa6d97669b84910d Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 30 Jan 2009 15:21:29 -0600 Subject: [PATCH] holds policies fixes * use item branch instead of patron's branch to look up the applicable hold policies - this makes requesting in the OPAC consistent with the intranet. * when generating pick list using build_holds_queue.pl, only match items to patrons if request is allowed. Signed-off-by: Galen Charlton --- misc/cronjobs/holds/build_holds_queue.pl | 18 ++++++++++++++---- opac/opac-reserve.pl | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/misc/cronjobs/holds/build_holds_queue.pl b/misc/cronjobs/holds/build_holds_queue.pl index e9054da8ff..57e11830fa 100755 --- a/misc/cronjobs/holds/build_holds_queue.pl +++ b/misc/cronjobs/holds/build_holds_queue.pl @@ -108,6 +108,7 @@ priority branchcode reservedate reservenotes +borrowerbranch The arrayref is sorted in order of increasing priority. @@ -118,8 +119,10 @@ sub GetPendingHoldRequestsForBib { my $dbh = C4::Context->dbh; - my $request_query = "SELECT biblionumber, borrowernumber, itemnumber, priority, branchcode, reservedate, reservenotes + my $request_query = "SELECT biblionumber, borrowernumber, itemnumber, priority, reserves.branchcode, + reservedate, reservenotes, borrowers.branchcode AS borrowerbranch FROM reserves + JOIN borrowers USING (borrowernumber) WHERE biblionumber = ? AND found IS NULL AND priority > 0 @@ -190,7 +193,9 @@ sub GetItemsAvailableToFillHoldRequestsForBib { $sth->execute(@params); my $items = $sth->fetchall_arrayref({}); - return [ grep { my @transfers = GetTransfers($_->{itemnumber}); $#transfers == -1; } @$items ]; + $items = [ grep { my @transfers = GetTransfers($_->{itemnumber}); $#transfers == -1; } @$items ]; + map { my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype}); $_->{holdallowed} = $rule->{holdallowed}; $rule->{holdallowed} != 0 } @$items; + return [ grep { $_->{holdallowed} != 0 } @$items ]; } =head2 MapItemsToHoldRequests @@ -268,7 +273,10 @@ sub MapItemsToHoldRequests { # look for local match first my $pickup_branch = $request->{branchcode}; - if (exists $items_by_branch{$pickup_branch}) { + if (exists $items_by_branch{$pickup_branch} and + not ($items_by_branch{$pickup_branch}->[0]->{holdallowed} == 1 and + $request->{borrowerbranch} ne $items_by_branch{$pickup_branch}->[0]->{homebranch}) + ) { my $item = pop @{ $items_by_branch{$pickup_branch} }; delete $items_by_branch{$pickup_branch} if scalar(@{ $items_by_branch{$pickup_branch} }) == 0; $item_map{$item->{itemnumber}} = { @@ -289,7 +297,9 @@ sub MapItemsToHoldRequests { @pull_branches = sort keys %items_by_branch; } foreach my $branch (@pull_branches) { - next unless exists $items_by_branch{$branch}; + next unless exists $items_by_branch{$branch} and + not ($items_by_branch{$branch}->[0]->{holdallowed} == 1 and + $request->{borrowerbranch} ne $items_by_branch{$branch}->[0]->{homebranch}); my $item = pop @{ $items_by_branch{$branch} }; delete $items_by_branch{$branch} if scalar(@{ $items_by_branch{$branch} }) == 0; $item_map{$item->{itemnumber}} = { diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 445da2ba0c..5f22a5a99b 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -332,7 +332,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) { # If there is no loan, return and transfer, we show a checkbox. $item->{notforloan} = $item->{notforloan} || 0; - my $branchitemrule = GetBranchItemRule( $borr->{'branchcode'}, $item->{'itype'} ); + my $branchitemrule = GetBranchItemRule( $item->{'homebranch'}, $item->{'itype'} ); my $policy_holdallowed = 1; if ( $branchitemrule->{'holdallowed'} == 0 || -- 2.39.5