From 29cc910bbe9fe4eae3a5d8de11617041ff0c0285 Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Thu, 23 Jan 2020 02:38:50 +0000
Subject: [PATCH] Bug 24476: Allow patrons to opt out of auto-renewal

To test:
1 - Verify on staff side that patron can be edited to opt in our out of auto renewal
2 - Check out some items to a patron opted in to auto renewal
3 - Ensure the items are checked out and set to autorenew
4 - Login on the opac at the patron
5 - Verify items cannot be renewed as scheduled for auto-renewal
6 - On staff side, opt patron out of auto renewal
7 - Verify on opac items are no longer marked for auto renewal
8 - Run the auto renewal cron job, items are not renewed
9 - Set 'no renewal before' to a setting that would prevent renewal
10 - Verify that opting patron in or out of auto renewal changes only the reason items cannot be renewed
11 - Set 'no renewal before' to a setting that would allow for renewal
12 - Verify that opting patron in/out changes their ability to renew
13 - Verify that when opted out cron does not renew
14 - Verify that when opted in the item is auto renewed
15 - Reset the due date, opt out, verify manual renewal succeeds
---
 .../prog/en/modules/circ/circulation.tt            |  5 +++-
 .../prog/en/modules/members/memberentrygen.tt      | 24 +++++++++++++++++++
 .../prog/en/modules/members/moremember-brief.tt    |  1 +
 .../prog/en/modules/members/moremember.tt          |  6 +++++
 .../bootstrap/en/modules/opac-memberentry.tt       | 27 ++++++++++++++++++++++
 members/memberentry.pl                             |  1 +
 6 files changed, 63 insertions(+), 1 deletion(-)

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 6c5f9ebe7d..a8c59c93b1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
@@ -565,8 +565,11 @@
                                                         <div id="set-automatic-renewal" class="circ-setting">
                                                             [% IF NEEDSCONFIRMATION %]
                                                                 <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled" />
-                                                            [% ELSE %]
+                                                            [% ELSIF patron.autorenewal %]
                                                                 <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" class="circ_setting" />
+                                                            [% ELSE %]
+                                                                <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled"
+                                                                title="Patron has opted out of auto-renewal"/>
                                                             [% END %]
 
                                                             <label for="auto_renew">Automatic renewal</label>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
index 23a32e0785..aeb7965aed 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
@@ -711,6 +711,30 @@
     [% PROCESS 'av-build-dropbox.inc' name="sort2", category="Bsort2", default=sort2, size = 20 %]
     [% IF ( mandatorysort2 ) %]<span class="required">Required</span>[% END %]
     </li>
+    <li class="radio">
+        <label for="yes-autorenewal">
+            Allow auto-renewal of items:
+        </label>
+            [% IF ( autorenewal ) %]
+                <label for="yes-autorenewal">
+                    Yes
+                    <input type="radio" id="yes-autorenewal" name="autorenewal" value="1" checked="checked" />
+                </label>
+                <label for="no-autorenewal">
+                    No
+                    <input type="radio" id="no-autorenewal" name="autorenewal" value="0" />
+                </label>
+            [% ELSE %]
+                <label for="yes-autorenewal">
+                    Yes
+                    <input type="radio" id="yes-autorenewal" name="autorenewal" value="1" />
+                </label>
+                <label for="no-autorenewal">
+                    No
+                    <input type="radio" id="no-autorenewal" name="autorenewal" value="0" checked="checked" />
+                </label>
+            [% END %]
+    </li>
         [% END %]
     [% IF ( Koha.Preference('CheckPrevCheckout') == 'softyes' || Koha.Preference('CheckPrevCheckout') == 'softno' ) %]
       <li><label for="checkprevcheckout">Check for previous checkouts: </label>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-brief.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-brief.tt
index 1c3b2c3b1b..ecac3b7f28 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-brief.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-brief.tt
@@ -84,6 +84,7 @@
             <li><span class="label">Library: </span>[% patron.library.branchname | html %]</li>
             [% IF ( patron.sort1 ) %]<li><span class="label">Sort field 1:</span>[% AuthorisedValues.GetByCode('Bsort1', patron.sort1) | html %]</li>[% END %]
             [% IF ( patron.sort2 ) %]<li><span class="label">Sort field 2:</span>[% AuthorisedValues.GetByCode('Bsort2', patron.sort2) | html %]</li>[% END %]
+            [% UNLESS ( patron.autorenewal ) %]<li>Auto renewal: Patron has opted out</li>[% END %]
         </ol>
     </div>
     </div>
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 0bd690f142..558aac9b24 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
@@ -516,6 +516,12 @@
                                                 [% AuthorisedValues.GetByCode('Bsort2', patron.sort2) | html %]
                                             </li>
                                         [% END %]
+                                        [% UNLESS ( patron.autorenewal ) %]
+                                            <li id="patron-autorenewal">
+                                                <span class="label">Auto renewal:</span>
+                                                Patron has opted out
+                                            </li>
+                                        [% END %]
                                         <li id="patron-username">
                                             <span class="label">Username: </span>
                                             [% patron.userid | html %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
index 8761cc88ae..aa50ec11ab 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
@@ -258,6 +258,33 @@
                                         [% END %]
                                     </li>
                                 [% END %]
+                                [% UNLESS hidden.defined('autorenewal') %]
+                                    <li class="lradio">
+                                        <label for="yes-autorenewal">
+                                            Allow auto-renewal:
+                                        </label>
+                                            [% IF ( borrower.autorenewal ) %]
+                                                <label class="radio inline" for="yes-autorenewal">
+                                                    Yes
+                                                    <input type="radio" id="yes-autorenewal" name="autorenewal" value="1" checked="checked" />
+                                                </label>
+
+                                                <label class="radio inline" for="no-autorenewal">
+                                                    No
+                                                    <input type="radio" id="no-autorenewal" name="autorenewal" value="0" />
+                                                </label>
+                                            [% ELSE %]
+                                                <label class="radio inline" for="yes-autorenewal">
+                                                    Yes
+                                                    <input type="radio" id="yes-autorenewal" name="autorenewal" value="1" />
+                                                </label>
+                                                <label class="radio inline" for="no-autorenewal">
+                                                    No
+                                                    <input type="radio" id="no-autorenewal" name="autorenewal" value="0" checked="checked" />
+                                                </label>
+                                            [% END %]
+                                    </li>
+                                [% END %]
                             </ol>
                         </fieldset>
                 [% END # / defined 'branchcode' %]
diff --git a/members/memberentry.pl b/members/memberentry.pl
index 902beeb0e8..e6f6458cf0 100755
--- a/members/memberentry.pl
+++ b/members/memberentry.pl
@@ -725,6 +725,7 @@ $template->param(no_add => $no_add);
 
 $template->param( sort1 => $data{'sort1'});
 $template->param( sort2 => $data{'sort2'});
+$template->param( autorenew => $data{'autorenew'});
 
 if ($nok) {
     foreach my $error (@errors) {
-- 
2.11.0