From 99a77df2fc7fff1c59f03422762211c54cd10cca Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Fri, 4 Sep 2020 13:18:53 +0000
Subject: [PATCH] Bug 26388: Do not show 'Renew all' or 'Renew selected' if no
 renewable items

Additionally, only include renewable items in 'Renew all'

To test:
1 - Check out some items to a patron, ideally:
    Some not renewable because set for auto renewal
    Some not renewable because of holds
    Some renewable
 2 - Confirm 'Renew selected' and 'Renew all' show on the opac
 3 - Click 'Renew all'
 4 - You get errors about the non-renewable items?
 5 - Check in all renewable items
 6 - Confirm you still see renew buttons
 7 - Apply patch
 8 - Refresh and you shoudl not see renew buttons
 9 - Check out a renewable item
10 - Click 'Renew all'
11 - Renewable item is renewed with no error
12 - Try again with 'Renew selected'
13 - Confirm it works as expected

https://bugs.koha-community.org/show_bug.cgi?id=26374
---
 installer/data/mysql/updatedatabase.pl                | 2 +-
 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt | 4 +++-
 opac/opac-user.pl                                     | 4 +++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 87e8db444c..7379d1b921 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -15894,7 +15894,7 @@ if( CheckVersion( $DBversion ) ) {
                 value="batchmod,moredetail,cronjob,additem"
             WHERE variable="MarkLostItemsAsReturned"
         });
-    } elsif ( $original_value = 0 || !defined($original_value) )  {
+    } elsif ( $original_value == 0 || !defined($original_value) )  {
         $dbh->do(q{
             UPDATE systempreferences
             SET type="multiple",
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
index 5e72d21891..1691f9dbfa 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
@@ -414,7 +414,9 @@
                                     <input type="hidden" name="from" value="opac_user" />
                                     <input type="hidden" name="borrowernumber" value="[% borrowernumber | html %]" />
                                     [% FOREACH ISSUE IN ISSUES %]
-                                        <input type="hidden" name="item" value="[% ISSUE.itemnumber | html %]" />
+                                        [% IF ISSUE.status %]
+                                            <input type="hidden" name="item" value="[% ISSUE.itemnumber | html %]" />
+                                        [% END %]
                                     [% END %]
                                     <input type="submit" class="btn" value="Renew all" />
                                 </form>
diff --git a/opac/opac-user.pl b/opac/opac-user.pl
index 18c983fa35..a380d88f01 100755
--- a/opac/opac-user.pl
+++ b/opac/opac-user.pl
@@ -190,6 +190,7 @@ my @overdues;
 my @issuedat;
 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
 my $pending_checkouts = $patron->pending_checkouts->search({}, { order_by => [ { -desc => 'date_due' }, { -asc => 'issue_id' } ] });
+my $are_renewable_items = 0;
 if ( $pending_checkouts->count ) { # Useless test
     while ( my $c = $pending_checkouts->next ) {
         my $issue = $c->unblessed_all_relateds;
@@ -226,6 +227,7 @@ if ( $pending_checkouts->count ) { # Useless test
         ( $issue->{'renewalfee'}, $issue->{'renewalitemtype'} ) = GetIssuingCharges( $issue->{'itemnumber'}, $borrowernumber );
         $issue->{itemtype_object} = Koha::ItemTypes->find( Koha::Items->find( $issue->{itemnumber} )->effective_itemtype );
         if($status && C4::Context->preference("OpacRenewalAllowed")){
+            $are_renewable_items = 1;
             $issue->{'status'} = $status;
         }
 
@@ -299,7 +301,7 @@ if ( $pending_checkouts->count ) { # Useless test
     }
 }
 my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
-$canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count);
+$canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count) || !$are_renewable_items;
 
 $template->param( ISSUES       => \@issuedat );
 $template->param( issues_count => $count );
-- 
2.11.0