From e7b559145b5d783c5dad557acfd5d563d1878d9f Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 6 May 2014 11:32:02 -0400 Subject: [PATCH] Bug 12197: enforce the maxreserves preference when staff members place hold requests This patch ensures that the global maxreserves preference is enforced when staff members place hold requests. For example: Create 3 items to place holds on. Set the circulation rule to allow 50 holds for all items. Set maxreserves to 2. Place a hold on 3 different items. On the third item, it will give a warning, but you can still place the hold. Despite what the circulation rule is set for (which is only a specific case rule), maxreserves is a global rule and should stop this from happening, not just give a warning. Test Plan: 1) Reproduce the bug by following the steps above 2) Verify the bug exists 3) Apply this patch 4) Verify the librarian cannot place the hold now 5) Enable AllowHoldPolicyOverride 6) Verify the librarian can forcefully place the hold Signed-off-by: Galen Charlton Bug 12197: (follow-up) rename variable for greater clarity "maxreserves" was referring both to the system preference and to the condition of having exceeded the number of hold requests allowed. This patch renames a variable to remove the ambguity. Test plan: * Same as the main patch. Signed-off-by: Galen Charlton --- .../prog/en/modules/reserve/request.tt | 11 ++- reserve/request.pl | 73 +++++++++++++------- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index cafc072..3c7da64 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -237,14 +237,14 @@ function checkMultiHold() { [% ELSE %] -[% IF ( maxreserves || alreadyreserved || none_available || alreadypossession ) %] +[% IF ( exceeded_maxreserves || alreadyreserved || none_available || alreadypossession ) %]
[% UNLESS ( multi_hold ) %]

Cannot place hold

[% ELSE %] -

Cannot place hold on some items

+

Cannot place hold on some items

+ [% IF ( exceeded_maxreserves ) %] +
  • Too many holds: [% borrowerfirstname %] [% borrowersurname %] can place [% new_reserves_allowed %] of the requested [% new_reserves_count %] holds for a maximum of [% maxreserves %] total holds.
  • + [% END %] [% END %]
    diff --git a/reserve/request.pl b/reserve/request.pl index 05321b8..e31aaca 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -77,9 +77,9 @@ $findborrower = '' unless defined $findborrower; $findborrower =~ s|,| |g; my $borrowernumber_hold = $input->param('borrowernumber') || ''; my $messageborrower; -my $maxreserves; my $warnings; my $messages; +my $exceeded_maxreserves; my $date = C4::Dates->today('iso'); my $action = $input->param('action'); @@ -116,23 +116,46 @@ if ($findborrower) { } } +my @biblionumbers = (); +my $biblionumbers = $input->param('biblionumbers'); +if ($multihold) { + @biblionumbers = split '/', $biblionumbers; +} else { + push @biblionumbers, $input->param('biblionumber'); +} + + # If we have the borrowernumber because we've performed an action, then we # don't want to try to place another reserve. if ($borrowernumber_hold && !$action) { my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold ); my $diffbranch; my @getreservloop; - my $count_reserv = 0; # we check the reserves of the borrower, and if he can reserv a document # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ... - my $number_reserves = + my $reserves_count = GetReserveCount( $borrowerinfo->{'borrowernumber'} ); - if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) { - $warnings = 1; - $maxreserves = 1; + my $new_reserves_count = scalar( @biblionumbers ); + + my $maxreserves = C4::Context->preference('maxreserves'); + if ( $maxreserves + && ( $reserves_count + $new_reserves_count > $maxreserves ) ) + { + my $new_reserves_allowed = + $maxreserves - $reserves_count > 0 + ? $maxreserves - $reserves_count + : 0; + $warnings = 1; + $exceeded_maxreserves = 1; + $template->param( + new_reserves_allowed => $new_reserves_allowed, + new_reserves_count => $new_reserves_count, + reserves_count => $reserves_count, + maxreserves => $maxreserves, + ); } # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn) @@ -161,7 +184,6 @@ if ($borrowernumber_hold && !$action) { borroweremail => $borrowerinfo->{'email'}, borroweremailpro => $borrowerinfo->{'emailpro'}, borrowercategory => $borrowerinfo->{'category'}, - borrowerreservs => $count_reserv, cardnumber => $borrowerinfo->{'cardnumber'}, expiry => $expiry, diffbranch => $diffbranch, @@ -175,14 +197,6 @@ $template->param( messageborrower => $messageborrower ); # FIXME launch another time GetMember perhaps until my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold ); -my @biblionumbers = (); -my $biblionumbers = $input->param('biblionumbers'); -if ($multihold) { - @biblionumbers = split '/', $biblionumbers; -} else { - push @biblionumbers, $input->param('biblionumber'); -} - my $itemdata_enumchron = 0; my @biblioloop = (); foreach my $biblionumber (@biblionumbers) { @@ -192,7 +206,9 @@ foreach my $biblionumber (@biblionumbers) { my $dat = GetBiblioData($biblionumber); unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) { - $maxreserves = 1; + $exceeded_maxreserves = 1; # note that exceeding the circ policy's hold + # limit is not the only reason CanBookBeReserved() + # can return false } my $alreadypossession; @@ -289,15 +305,21 @@ foreach my $biblionumber (@biblionumbers) { my $num_override = 0; my $hiddencount = 0; - $biblioitem->{description} = - $itemtypes->{ $biblioitem->{itemtype} }{description}; - if($biblioitem->{biblioitemnumber} ne $biblionumber){ - $biblioitem->{hostitemsflag}=1; - } + if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) { + $biblioitem->{hostitemsflag} = 1; + } + $biblioloopiter{description} = $biblioitem->{description}; - $biblioloopiter{itypename} = $biblioitem->{description}; - $biblioloopiter{imageurl} = - getitemtypeimagelocation('intranet', $itemtypes->{$biblioitem->{itemtype}}{imageurl}); + $biblioloopiter{itypename} = $biblioitem->{description}; + if ( $biblioitem->{itemtype} ) { + + $biblioitem->{description} = + $itemtypes->{ $biblioitem->{itemtype} }{description}; + + $biblioloopiter{imageurl} = + getitemtypeimagelocation( 'intranet', + $itemtypes->{ $biblioitem->{itemtype} }{imageurl} ); + } foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } ) { my $item = $iteminfos_of->{$itemnumber}; @@ -411,6 +433,7 @@ foreach my $biblionumber (@biblionumbers) { if ( $policy_holdallowed + && !$exceeded_maxreserves && !$item->{cantreserve} && IsAvailableForItemLevelRequest($itemnumber) && CanItemBeReserved( @@ -575,7 +598,7 @@ foreach my $biblionumber (@biblionumbers) { $template->param( biblioloop => \@biblioloop ); $template->param( biblionumbers => $biblionumbers ); -$template->param( maxreserves => $maxreserves ); +$template->param( exceeded_maxreserves => $exceeded_maxreserves ); if ($multihold) { $template->param( multi_hold => 1 ); -- 1.7.2.5