@@ -, +, @@ rules $ kshell t/db_dependent/Reserves.t --- C4/Reserves.pm | 64 +++++++++++++++++-- .../bootstrap/en/modules/opac-reserve.tt | 6 +- opac/opac-reserve.pl | 25 ++++++-- 3 files changed, 80 insertions(+), 15 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -330,6 +330,38 @@ sub CanBookBeReserved{ return { status =>'alreadypossession' }; } + if ( $params->{itemtype} + and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) + { + # biblio-level, item type-contrained + my $patron = Koha::Patrons->find($borrowernumber); + my $reservesallowed = Koha::CirculationRules->get_effective_rule( + { + itemtype => $params->{itemtype}, + categorycode => $patron->categorycode, + branchcode => $pickup_branchcode, + rule_name => 'reservesallowed', + } + )->rule_value; + + $reservesallowed = ($reservesallowed eq '') ? undef : $reservesallowed; + + my $count = $patron->holds->search( + { + '-or' => [ + { 'me.itemtype' => $params->{itemtype} }, + { 'item.itype' => $params->{itemtype} } + ] + }, + { + join => ['item'] + } + )->count; + + return { status => '' } + if defined $reservesallowed and $reservesallowed < $count + 1; + } + my $items; #get items linked via host records my @hostitemnumbers = get_hostitemnumbers_of($biblionumber); @@ -510,15 +542,35 @@ sub CanItemBeReserved { # If using item-level itypes, fall back to the record # level itemtype if the hold has no associated item - $querycount .= - C4::Context->preference('item-level_itypes') - ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?" - : " AND biblioitems.itemtype = ?" - if defined $ruleitemtype; + if ( defined $ruleitemtype and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) { + if ( C4::Context->preference('item-level_itypes') ) { + $querycount .= q{ + AND ( COALESCE( items.itype, biblioitems.itemtype ) = ? + OR reserves.itemtype = ? ) + }; + } + else { + $querycount .= q{ + AND ( biblioitems.itemtype = ? + OR reserves.itemtype = ? ) + }; + } + } + elsif ( defined $ruleitemtype ) { + # If using item-level itypes, fall back to the record + # level itemtype if the hold has no associated item + $querycount .= + C4::Context->preference('item-level_itypes') + ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?" + : " AND biblioitems.itemtype = ?"; + } my $sthcount = $dbh->prepare($querycount); - if ( defined $ruleitemtype ) { + if ( defined $ruleitemtype and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) { + $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype, $ruleitemtype ); + } + elsif ( defined $ruleitemtype ) { $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype ); } else { --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -295,15 +295,11 @@ [% IF Koha.Preference('AllowHoldItemTypeSelection') %] - [% itemtypes = [] %] - [% FOREACH item IN bibitemloo.itemLoop %] - [% itemtypes.push( item.itype ) %] - [%- END %]