From 6ceeffd77c091580dcad29e661d5c3e5d35b0b7c Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 22 Feb 2021 18:08:37 +1300 Subject: [PATCH] Bug 15565: Place multiple holds on one record on OPAC Test plan: 1) Apply patch and restart services 2) Set the maxreserves system preference to 3 3) Set the following circulation rules: holds allowed (total) = 10 holds allowed (daily) = 10 holds per record (count) = 10 3) Set up a record with 4 items 4) Go to place a hold on this record 5) Notice that the items table under 'Place a hold on a specific item' now uses checkboxes instead of radio buttons 6) Check all 4 checkboxes. Confirm that when you check the 4th checkbox, an alert pops up warning the you've reached the maximum. Confirm that when you close the alert, the checkbox unchecks itself. 7) Try setting different values for the above circulation rules that are lower than the number of items on this record. Confirm the alert pops up as expected. 8) Set the circulation rules and syspref all to 4+. Check some items and confirm the holds. 9) Confirm that item-level holds are placed on all selected items. Sponsored-by: Catalyst IT Signed-off-by: David Cook --- .../opac-tmpl/bootstrap/en/modules/opac-reserve.tt | 21 +++++++++-- opac/opac-reserve.pl | 41 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt index ec4aaf5b03..a8fcc01acb 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -338,6 +338,10 @@ /> [% END # / IF bibitemloo.itemholdable %] + + [% IF lowest_value %] + + [% END %] [% IF bibitemloo.itemholdable %] @@ -367,7 +371,7 @@ [% IF ( itemLoo.available ) %] - + [% ELSE %] @@ -469,6 +473,8 @@ diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index b90a2061b2..f6116195b7 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -44,6 +44,7 @@ use Koha::Libraries; use Koha::Patrons; use Date::Calc qw/Today Date_to_Days/; use List::MoreUtils qw/uniq/; +use List::Util qw[min max]; my $maxreserves = C4::Context->preference("maxreserves"); @@ -214,6 +215,17 @@ if ( $query->param('place_reserve') ) { $selectedItems = "$bib/$item/$branch/"; } + my @multi_bibs = $query->multi_param('single_bib'); + if ( $query->param('reserve_mode') eq 'multi' and @multi_bibs == 1 ) { + # multiple holds on same record + my $biblionumber = $query->param('single_bib'); + my @itemnumbers = $query->multi_param("checkitem_$biblionumber"); + my $branch = $query->param('branch'); + foreach my $itemnumber ( @itemnumbers ) { + $selectedItems .= "$biblionumber/$itemnumber/$branch/"; + } + } + $selectedItems =~ s!/$!!; my @selectedItems = split /\//, $selectedItems, -1; @@ -464,6 +476,35 @@ foreach my $biblioNum (@biblionumbers) { my $visible_items = { map { $_->itemnumber => $_ } $biblio->items->filter_by_visible_in_opac( { patron => $patron } )->as_list }; + # For a librarian to be able to place multiple record holds for a patron for a record, + # we must find out what the maximum number of holds they can place for the patron is + my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblioNum ); + my $remaining_holds_for_record = $max_holds_for_record - $holds->count(); + + # Determine how many holds the patron can place per day on this biblio record. + # Then calculate how many holds the patron can place subtracting holds already placed today + my $today_holds = Koha::Holds->search({ + borrowernumber => $patron->borrowernumber, + reservedate => dt_from_string->date, + })->count; + + my $holds_allowed_on_record_today = $biblio->allowed_holds( $patron ); + my $remaining_holds_allowed_today = $holds_allowed_on_record_today - $today_holds; + my $maxreserves = C4::Context->preference('maxreserves'); + + $biblioLoopIter{remaining_holds_for_record} = $remaining_holds_for_record; + $biblioLoopIter{remaining_holds_allowed_today} = $remaining_holds_allowed_today; + + # Determine what is the lowest value + my $lowestvalue = min( $maxreserves, $remaining_holds_for_record, $remaining_holds_allowed_today ); + + $template->param( + max_holds_for_record => $max_holds_for_record, + remaining_holds_for_record => $remaining_holds_for_record, + lowest_value => $lowestvalue, + remaining_holds_allowed_today => $remaining_holds_allowed_today, + ); + # Only keep the items that are visible in the opac (i.e. those in %visible_items) # FIXME: We should get rid of itemInfos altogether and use $visible_items $biblioData->{itemInfos} = [ grep { $visible_items->{ $_->{itemnumber} } } @{ $biblioData->{itemInfos} } ]; -- 2.11.0