From e503dc9590ef7ef58ee26bef2bd9f53593014602 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: See previous commit about the staff interface Sponsored-by: Catalyst IT Signed-off-by: David Cook Signed-off-by: Victor Grousset/tuxayo --- .../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 2cd468650d..4512db0337 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -339,6 +339,10 @@ /> [% END # / IF bibitemloo.itemholdable %] + + [% IF lowest_value %] + + [% END %] [% IF bibitemloo.itemholdable %] @@ -368,7 +372,7 @@ [% IF ( itemLoo.available ) %] - + [% ELSE %] @@ -470,6 +474,8 @@ diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index a6182400ad..585ab9f61c 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; @@ -466,6 +478,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.31.1