From 798e8486ead67aa43895204c09b4fd519b87037b Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 7 Jan 2016 14:14:18 +0100 Subject: [PATCH] Bug 15516: Allow to reserve first available item from a group of titles It can be useful, for instance, if a library have the same title from different publishers (so 1 title but several biblio records) but the user only wants a copy of the book, regardless of the publisher. This patch is only for staff interface. Test plan: 0. Run updatedatabase.pl and misc/devel/update_dbix_class_files.pl 1. Go to intranet search, display some results, click on some checkboxes and click on 'Place hold' button at the top of the results. 2. Enter a patron cardnumber and click Search 3. Check the box for 'Place a hold on the next available item' (it's usually hidden when placing a hold on multiple biblios) 4. Click on 'Place hold' 5. In the next screen you should see all the holds you placed with the additional text '(part of a reserve group)' in Details column. 6. Click on the "reserve group" link. A modal window should appear with the content of the reserve group (a list of holds) 7. Check in an item of one of the reserved biblios and confirm the hold 8. The hold status is changed to Waiting, and all other holds are deleted. Note: the "reserve group" link is displayed in the following pages: - reserve/request.pl - circ/circulation.pl - members/moremember.pl - circ/pendingreserves.pl Signed-off-by: Josef Moravec Signed-off-by: Benjamin Rokseth Signed-off-by: Michal Denar Signed-off-by: Michal Denar Signed-off-by: Michal Denar --- C4/Reserves.pm | 69 ++++++++++++++++++++++ Koha/Template/Plugin/Biblio.pm | 8 +++ circ/pendingreserves.pl | 2 + installer/data/mysql/atomicupdate/bug_15516.sql | 11 ++++ installer/data/mysql/kohastructure.sql | 18 +++++- .../intranet-tmpl/prog/en/includes/holds_table.inc | 3 + .../prog/en/includes/reserve-group-modal.inc | 27 +++++++++ .../prog/en/modules/circ/circulation.tt | 1 + .../prog/en/modules/circ/pendingreserves.tt | 5 ++ .../prog/en/modules/members/moremember.tt | 1 + .../prog/en/modules/reserve/request.tt | 14 +++-- .../prog/en/modules/reserve/reserve-group.tt | 30 ++++++++++ koha-tmpl/intranet-tmpl/prog/js/holds.js | 6 ++ reserve/placerequest.pl | 7 +++ reserve/request.pl | 1 + reserve/reserve-group.pl | 42 +++++++++++++ svc/holds | 1 + 17 files changed, 240 insertions(+), 6 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_15516.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/reserve-group-modal.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reserve/reserve-group.tt create mode 100755 reserve/reserve-group.pl diff --git a/C4/Reserves.pm b/C4/Reserves.pm index a658646407..d23c0924a8 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -140,6 +140,10 @@ BEGIN { IsItemOnHoldAndFound GetMaxPatronHoldsForRecord + + &AddReserveGroup + &DeleteReserveGroup + &GetReserveGroupReserves ); @EXPORT_OK = qw( MergeHolds ); } @@ -189,6 +193,7 @@ sub AddReserve { my $found = $params->{found}; my $itemtype = $params->{itemtype}; my $non_priority = $params->{non_priority}; + my $reserve_group_id = $params->{reserve_group_id}; $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' }) or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' }); @@ -253,6 +258,7 @@ sub AddReserve { itemtype => $itemtype, item_level_hold => $checkitem ? 1 : 0, non_priority => $non_priority ? 1 : 0, + reserve_group_id => $reserve_group_id, } )->store(); $hold->set_waiting() if $found && $found eq 'W'; @@ -1209,6 +1215,15 @@ sub ModReserveAffect { }; } + if ($hold->reserve_group_id) { + # Delete other reserves from same group + $dbh->do(q{ + DELETE FROM reserves + WHERE reserve_group_id = ? + AND reserve_id != ? + }, undef, $hold->reserve_group_id, $hold->reserve_id); + DeleteReserveGroup($hold->reserve_group_id); + } _FixPriority( { biblionumber => $biblionumber } ); my $item = Koha::Items->find($itemnumber); @@ -2268,6 +2283,60 @@ sub GetMaxPatronHoldsForRecord { return $max; } +=head2 AddReserveGroup + + my $reserve_group_id = AddReserveGroup(); + +Creates a new reserve group and returns its ID + +=cut + +sub AddReserveGroup { + my $dbh = C4::Context->dbh; + + $dbh->do('INSERT INTO reserve_group VALUES ()'); + return $dbh->last_insert_id(undef, undef, 'reserve_group', undef); +} + +=head2 DeleteReserveGroup + + DeleteReserveGroup($reserve_group_id); + +Delete a reserve group. Reserves that belong to this group are not removed. + +=cut + +sub DeleteReserveGroup { + my ($reserve_group_id) = @_; + + my $dbh = C4::Context->dbh; + my $query = 'DELETE FROM reserve_group WHERE reserve_group_id = ?'; + $dbh->do($query, undef, $reserve_group_id); +} + +=head2 GetReserveGroupReserves + + my @reserves = GetReserveGroupReserves($reserve_group_id); + +Fetch all reserve from a reserve group. + +=cut + +sub GetReserveGroupReserves { + my ($reserve_group_id) = @_; + + my $dbh = C4::Context->dbh; + + my $reserves = $dbh->selectall_arrayref(q{ + SELECT * FROM reserves + WHERE reserve_group_id = ? + }, { Slice => {} }, $reserve_group_id); + + return () unless defined $reserves; + + return @$reserves; +} + =head1 AUTHOR Koha Development Team diff --git a/Koha/Template/Plugin/Biblio.pm b/Koha/Template/Plugin/Biblio.pm index e9d7a73009..ab6a716a0e 100644 --- a/Koha/Template/Plugin/Biblio.pm +++ b/Koha/Template/Plugin/Biblio.pm @@ -63,4 +63,12 @@ sub CanArticleRequest { return $biblio ? $biblio->can_article_request( $borrower ) : 0; } +sub Get { + my ($self, $biblionumber) = @_; + + my $biblio = Koha::Biblios->find($biblionumber); + + return $biblio; +} + 1; diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 01cf877b55..1a59bb4ecf 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -202,6 +202,7 @@ my $strsth = ORDER BY items.itemnumber SEPARATOR '|') l_copynumber, GROUP_CONCAT(DISTINCT items.barcode ORDER BY items.itemnumber SEPARATOR '|') l_barcode, + reserves.reserve_group_id, biblio.title, biblio.copyrightdate, biblioitems.publicationyear, @@ -279,6 +280,7 @@ while ( my $data = $sth->fetchrow_hashref ) { homebranch => $data->{homebranch}, itemnumber => $data->{itemnumber}, publicationyear => C4::Context->preference('marcflavour') eq "MARC21" ? $data->{copyrightdate} : $data->{publicationyear}, + reserve_group_id => $data->{reserve_group_id}, } ); } diff --git a/installer/data/mysql/atomicupdate/bug_15516.sql b/installer/data/mysql/atomicupdate/bug_15516.sql new file mode 100644 index 0000000000..cad3cc5f5e --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_15516.sql @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS reserve_group; +CREATE TABLE reserve_group ( + reserve_group_id int unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (reserve_group_id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +ALTER TABLE reserves ADD COLUMN reserve_group_id int unsigned NULL DEFAULT NULL; +ALTER TABLE reserves ADD CONSTRAINT reserves_ibfk_6 FOREIGN KEY (reserve_group_id) REFERENCES reserve_group (reserve_group_id) ON DELETE SET NULL ON UPDATE CASCADE; + +ALTER TABLE old_reserves ADD COLUMN reserve_group_id int unsigned NULL DEFAULT NULL; +ALTER TABLE old_reserves ADD CONSTRAINT old_reserves_ibfk_5 FOREIGN KEY (reserve_group_id) REFERENCES reserve_group (reserve_group_id) ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index ef3bff04b0..87c710d4a0 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1704,7 +1704,8 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL, - CONSTRAINT `old_issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer_id`) REFERENCES `borrowers` (`borrowernumber`) + CONSTRAINT `old_issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer_id`) REFERENCES `borrowers` (`borrowernumber`), + CONSTRAINT `old_reserves_ibfk_5` FOREIGN KEY (reserve_group_id) REFERENCES reserve_group (reserve_group_id) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -1813,6 +1814,7 @@ CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha `itemtype` VARCHAR(10) NULL DEFAULT NULL, -- If record level hold, the optional itemtype of the item the patron is requesting `item_level_hold` tinyint(1) NOT NULL DEFAULT 0, -- Is the hpld placed at item level `non_priority` tinyint(1) NOT NULL DEFAULT 0, -- Is this a non priority hold + `reserve_group_id` int unsigned NULL DEFAULT NULL, -- Id used on reservations spanning multiple titles PRIMARY KEY (`reserve_id`), KEY priorityfoundidx (priority,found), KEY `borrowernumber` (`borrowernumber`), @@ -1826,7 +1828,18 @@ CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha CONSTRAINT `reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `reserves_ibfk_4` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `reserves_ibfk_5` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `reserves_ibfk_6` FOREIGN KEY (`desk_id`) REFERENCES `desks` (`desk_id`) ON DELETE SET NULL ON UPDATE CASCADE + CONSTRAINT `reserves_ibfk_6` FOREIGN KEY (`desk_id`) REFERENCES `desks` (`desk_id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `reserves_ibfk_7` FOREIGN KEY (`reserve_group_id`) REFERENCES `reserve_group` (`reserve_group_id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- +-- Table structure for table reserve_group +-- + +DROP TABLE IF EXISTS `reserve_group`; +CREATE TABLE `reserve_group` ( + `reserve_group_id` int unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY(`reserve_group_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- @@ -1858,6 +1871,7 @@ CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b `itemtype` VARCHAR(10) NULL DEFAULT NULL, -- If record level hold, the optional itemtype of the item the patron is requesting `item_level_hold` tinyint(1) NOT NULL DEFAULT 0, -- Is the hpld placed at item level `non_priority` tinyint(1) NOT NULL DEFAULT 0, -- Is this a non priority hold + `reserve_group_id` int unsigned NULL DEFAULT NULL, -- The id of a group of titles reservations fulfilled when one title is picked PRIMARY KEY (`reserve_id`), KEY `old_reserves_borrowernumber` (`borrowernumber`), KEY `old_reserves_biblionumber` (`biblionumber`), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc index 59f33cd2a0..6975087216 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc @@ -177,6 +177,9 @@ [% IF hold.non_priority %]
Non priority hold [% END %] + [% IF hold.reserve_group_id %] +
(part of a reserve group)
+ [% END %] [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reserve-group-modal.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reserve-group-modal.inc new file mode 100644 index 0000000000..2a3e68b157 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reserve-group-modal.inc @@ -0,0 +1,27 @@ + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 0a7d40c8a8..99fe2edf22 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -1190,4 +1190,5 @@ [% Asset.js("js/members-menu.js") | $raw %] [% END %] +[% INCLUDE 'reserve-group-modal.inc' %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt index 1ee212e321..343fd29ab7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt @@ -82,6 +82,9 @@ [% IF ( reserveloo.author ) %]

by [% reserveloo.author | html %]

[% END %] [% IF ( reserveloo.editionstatement ) %]

[% reserveloo.editionstatement | html %]

[% END %] [% IF ( reserveloo.publicationyear ) %]

[% reserveloo.publicationyear | html %]

[% END %] + [% IF reserveloo.reserve_group_id %] +

(part of a reserve group)

+ [% END %] [% ELSE %] " @@ -324,4 +327,6 @@ [% END %] +[%# TODO: this module needs to be separated to html and js part to be included correctly %] +[% INCLUDE 'reserve-group-modal.inc' %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 7b7fd26e67..208bd4b1bf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -1030,4 +1030,5 @@ [% END %] +[% INCLUDE 'reserve-group-modal.inc' %] [% INCLUDE 'intranet-bottom.inc' %] 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 f479387c7e..b27c2f0eed 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -452,21 +452,25 @@ Clear date - [% UNLESS ( multi_hold ) %]
  • - [% IF force_hold_level == 'item' %] + [% IF multi_hold %] + + [% ELSE %] + [% IF force_hold_level == 'item' %] - [% ELSIF force_hold_level == 'record' %] + [% ELSIF force_hold_level == 'record' %] - [% ELSE %] + [% ELSE %] + [% END %] [% END %]
  • + [% UNLESS multi_hold %] [% IF remaining_holds_for_record > 1 %]
  • @@ -1351,4 +1355,6 @@ [% END %] +[% INCLUDE 'reserve-group-modal.inc' %] + [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/reserve-group.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/reserve-group.tt new file mode 100644 index 0000000000..8926c0a4ca --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/reserve-group.tt @@ -0,0 +1,30 @@ +[% USE Biblio %] +[% INCLUDE 'doc-head-open.inc' %] + Koha › Circulation › Holds › Holds group ([% reserve_group_id %]) + [% INCLUDE 'doc-head-close.inc' %] + + +

    Holds group ([% reserve_group_id %])

    +
    + [% IF reserves.size %] + + + + + + + + + + [% FOREACH reserve IN reserves %] + [% biblio = Biblio.Get(reserve.biblionumber) %] + + + + + + [% END %] + +
    TitlePriorityNotes
    [% biblio.title %][% reserve.priority %][% reserve.reservenotes %]
    + [% END %] + [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js index 66dd265a14..c1be59a58d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/holds.js +++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js @@ -50,6 +50,12 @@ $(document).ready(function() { title += " - " + oObj.itemnotes.escapeHtml() + "" } + if (oObj.reserve_group_id) { + title += '
    '; + var link = '' + RESERVE_GROUP +'' + title += '' + PART_OF_A.format(link) + ''; + } + return title; } }, diff --git a/reserve/placerequest.pl b/reserve/placerequest.pl index ea81592ef0..469226ac79 100755 --- a/reserve/placerequest.pl +++ b/reserve/placerequest.pl @@ -53,6 +53,7 @@ my $checkitem = $input->param('checkitem'); my $expirationdate = $input->param('expiration_date'); my $itemtype = $input->param('itemtype') || undef; my $non_priority = $input->param('non_priority'); +my $requestany = $input->param('requestany'); my $borrower = Koha::Patrons->find( $borrowernumber ); $borrower = $borrower->unblessed if $borrower; @@ -76,6 +77,11 @@ my $found; if ( $type eq 'str8' && $borrower ) { + my $reserve_group_id; + if ($multi_hold && $requestany) { + $reserve_group_id = AddReserveGroup(); + } + foreach my $biblionumber ( keys %bibinfos ) { my $count = @bibitems; @bibitems = sort @bibitems; @@ -138,6 +144,7 @@ if ( $type eq 'str8' && $borrower ) { found => $found, itemtype => $itemtype, non_priority => $non_priority, + reserve_group_id => $reserve_group_id, } ); } diff --git a/reserve/request.pl b/reserve/request.pl index 38d6f56ed2..c6ab400d5c 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -690,6 +690,7 @@ foreach my $biblionumber (@biblionumbers) { $reserve{branchcode} = $res->branchcode(); $reserve{non_priority} = $res->non_priority(); $reserve{object} = $res; + $reserve{'reserve_group_id'} = $res->reserve_group_id; push( @reserveloop, \%reserve ); } diff --git a/reserve/reserve-group.pl b/reserve/reserve-group.pl new file mode 100755 index 0000000000..91ed958538 --- /dev/null +++ b/reserve/reserve-group.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use CGI qw( -utf8 ); + +use C4::Auth; +use C4::Output; +use C4::Reserves; + +my $cgi = new CGI; +my ($template, $loggedinuser, $cookie) = get_template_and_user({ + template_name => "reserve/reserve-group.tt", + query => $cgi, + type => "intranet", + authnotrequired => 0, + flagsrequired => { circulate => 'circulate_remaining_permissions' }, +}); + +my $reserve_group_id = $cgi->param('reserve_group_id'); +my @reserves = GetReserveGroupReserves($reserve_group_id); + +$template->param( + reserve_group_id => $reserve_group_id, + reserves => \@reserves, +); + +output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/svc/holds b/svc/holds index 5e0a9d91fb..db50cbdc10 100755 --- a/svc/holds +++ b/svc/holds @@ -114,6 +114,7 @@ while ( my $h = $holds_rs->next() ) { waiting_here => $h->branch()->branchcode() eq $branch, priority => $h->priority(), itemtype_limit => $itemtype_limit, + reserve_group_id => $h->reserve_group_id, reservedate_formatted => $h->reservedate() ? output_pref( { dt => dt_from_string( $h->reservedate() ), dateonly => 1 } ) -- 2.11.0