From 057f5b77e365f862b15cfee06bca137ffec3eabe Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Tue, 21 Jun 2016 09:52:47 -0400
Subject: [PATCH] Bug 16787: 'Too many holds' message appears inappropriately
 and is missing data

This patch alters C4/Reserves.pm to pass back 'noReservesAllowed' when
allowedreserves=0. This allows passing to the user an appropriate
message about the availability of items for holds

To test:
1 - Set an item type to allow no holds
2 - Attempt to place a hold for a patron
3 - Message should be "No holds allowed: [Firstname Surname] cannot
place holds on any of these items"
4 - Try placing a multihold with the record above and a holdable record,
  message should end "...cannot place holds on some of these titles'
  items"
---
 C4/Reserves.pm                                             | 3 +++
 koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt | 7 ++++++-
 reserve/request.pl                                         | 7 +++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index 78f5ca39f2..8b24f3c296 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -397,6 +397,9 @@ sub CanItemBeReserved {
     }
 
     # we check if it's ok or not
+    if( $allowedreserves == 0 ){
+        return 'noReservesAllowed';
+    }
     if ( $reservecount >= $allowedreserves ) {
         return 'tooManyReserves';
     }
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 02c50b9c2d..60fd84bf61 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
@@ -276,7 +276,9 @@ function checkMultiHold() {
     [% UNLESS ( multi_hold ) %]
       <h3>Cannot place hold</h3>
       <ul>
-        [% IF ( exceeded_maxreserves ) %]
+        [% IF ( no_reserves_allowed) %]
+          <li><strong>No holds allowed: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %] </a> cannot place any holds on these items.</li>
+        [% ELSIF ( exceeded_maxreserves ) %]
           <li><strong>Too many holds: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %] </a> can only place a maximum of [% maxreserves %] total holds.</li>
         [% ELSIF ( exceeded_holds_per_record ) %]
           <li><strong>Too many holds for this record: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %] </a> can only place a maximum of [% max_holds_for_record %] hold(s) on this record.</li>
@@ -294,6 +296,9 @@ function checkMultiHold() {
       </ul>
     [% ELSE %]
         <h3>Cannot place hold on some items</h3>
+        [% IF ( no_reserves_allowed) %]
+          <li><strong>No holds allowed: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %] </a> cannot place holds on some of these title's items.</li>
+        [% END %]
         [% IF ( exceeded_maxreserves ) %]
           <li><strong>Too many holds: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %] </a> can place [% new_reserves_allowed %] of the requested [% new_reserves_count %] holds for a maximum of [% maxreserves %] total holds.</li>
         [% ELSIF ( exceeded_holds_per_record ) %]
diff --git a/reserve/request.pl b/reserve/request.pl
index f4cdc16fa7..640abc82ba 100755
--- a/reserve/request.pl
+++ b/reserve/request.pl
@@ -148,6 +148,8 @@ if ($borrowernumber_hold && !$action) {
     my $new_reserves_count = scalar( @biblionumbers );
 
     my $maxreserves = C4::Context->preference('maxreserves');
+    $template->param( maxreserves => $maxreserves );
+
     if ( $maxreserves
         && ( $reserves_count + $new_reserves_count > $maxreserves ) )
     {
@@ -210,6 +212,7 @@ my $logged_in_patron = Koha::Patrons->find( $borrowernumber );
 
 my $itemdata_enumchron = 0;
 my @biblioloop = ();
+my $no_reserves_allowed = 0;
 foreach my $biblionumber (@biblionumbers) {
     next unless $biblionumber =~ m|^\d+$|;
 
@@ -226,6 +229,9 @@ foreach my $biblionumber (@biblionumbers) {
 
                 #All is OK and we can continue
             }
+            elsif ( $canReserve eq 'noReservesAllowed') {
+                $no_reserves_allowed = 1;
+            }
             elsif ( $canReserve eq 'tooManyReserves' ) {
                 $exceeded_maxreserves = 1;
             }
@@ -636,6 +642,7 @@ foreach my $biblionumber (@biblionumbers) {
 
 $template->param( biblioloop => \@biblioloop );
 $template->param( biblionumbers => $biblionumbers );
+$template->param( no_reserves_allowed => $no_reserves_allowed );
 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
 $template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
 
-- 
2.11.0