&ReserveSlip
&ToggleSuspend
&SuspendAll
+
+ &GetReservesControlBranch
);
@EXPORT_OK = qw( MergeHolds );
}
if ( $res->{'priority'} && $res->{'priority'} < $priority ) {
my $borrowerinfo=C4::Members::GetMember(borrowernumber => $res->{'borrowernumber'});
my $iteminfo=C4::Items::GetItem($itemnumber);
- my $branch=C4::Circulation::_GetCircControlBranch($iteminfo,$borrowerinfo);
+ my $branch = GetReservesControlBranch( $iteminfo, $borrowerinfo );
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
next if ($branchitemrule->{'holdallowed'} == 0);
next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
);
}
+=head2 GetReservesControlBranch
+
+ my $reserves_control_branch = GetReservesControlBranch($item, $borrower);
+
+ Return the branchcode to be used to determine which reserves
+ policy applies to a transaction.
+
+ C<$item> is a hashref for an item. Only 'homebranch' is used.
+
+ C<$borrower> is a hashref to borrower. Only 'branchcode' is used.
+
+=cut
+
+sub GetReservesControlBranch {
+ my ( $item, $borrower ) = @_;
+
+ my $reserves_control = C4::Context->preference('ReservesControlBranch');
+
+ my $branchcode =
+ ( $reserves_control eq 'ItemHomeLibrary' ) ? $item->{'homebranch'}
+ : ( $reserves_control eq 'PatronLibrary' ) ? $borrower->{'branchcode'}
+ : undef;
+
+ return $branchcode;
+}
+
=head1 AUTHOR
Koha Development Team <http://koha-community.org/>
# If there is no loan, return and transfer, we show a checkbox.
$itemLoopIter->{notforloan} = $itemLoopIter->{notforloan} || 0;
- my $branch = ( C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary' ) ? $itemInfo->{'homebranch'} : $borr->{'branchcode'};
+ my $branch = GetReservesControlBranch( $itemInfo, $borr );
my $branchitemrule = GetBranchItemRule( $branch, $itemInfo->{'itype'} );
my $policy_holdallowed = 1;
use Modern::Perl;
-use Test::More tests => 4;
+use Test::More tests => 6;
use MARC::Record;
use C4::Branch;
($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
is($status, "Reserved", "CheckReserves Test 3");
+
+my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch');
+C4::Context->set_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
+ok(
+ 'ItemHomeLib' eq GetReservesControlBranch(
+ { homebranch => 'ItemHomeLib' },
+ { branchcode => 'PatronHomeLib' }
+ ), "GetReservesControlBranch returns item home branch when set to ItemHomeLibrary"
+);
+C4::Context->set_preference( 'ReservesControlBranch', 'PatronLibrary' );
+ok(
+ 'PatronHomeLib' eq GetReservesControlBranch(
+ { homebranch => 'ItemHomeLib' },
+ { branchcode => 'PatronHomeLib' }
+ ), "GetReservesControlBranch returns patron home branch when set to PatronLibrary"
+);
+C4::Context->set_preference( 'ReservesControlBranch', $ReservesControlBranch );