Bug 7088: Allow renew on hold items with due date
authorAndrew Isherwood <andrew.isherwood@ptfs-europe.com>
Fri, 21 Sep 2018 10:09:13 +0000 (11:09 +0100)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 9 May 2019 14:40:49 +0000 (14:40 +0000)
This patch adds the ability for items that are on hold to be renewed with a due date specfied by the user. It is enabled by the new "AllowRenewalOnHoldOverride" syspref. It is manifested in two locations:

1. In the "Checkouts" table on the Patron Details screen. It is now possible to select on loan items that would otherwise fulfil a hold request to be renewed. When such an item is selected, an additional date selection box is displayed to allow the user to specify the due date for all on hold items that are to be renewed.

2. In the Circulation > Renew alert screen. When a barcode of an on loan item that would ordinarily fulfil a hold request is entered, the usual alert is displayed indicating that the item is on hold, it is still possible to override this, and renew, however it is now also possible to specify a due date.

Test plan:

- Go to the Patron Details page for a patron who has an item on loan that would fulfil an outstanding loan request.
- TEST: Observe that it is NOT possible to select this item
- Enable the "AllowRenewalOnHoldOverride" syspref
- Return to the Patron Details page for a patron who has an item on loan that would fulfil an outstanding loan request.
- TEST: Observe that it IS possible to select this item
- Select the item
- TEST: Observe that an additional "On hold due date" input box is displayed
- De-select the item
- TEST: Observe that an additional "On hold due date" input box is hidden
- Select the item
- In the "On hold due date" input box, select a due date for the item
- Click "Renew or check in selected items"
- TEST: Observe that the item is renewed as usual
- In the "Renewal due date" input box, select a due date
- Remove the contents of the "On hold due date" input box
- Click "Renew or check in selected items"
- TEST: Observe that the item is renewed by falling back to the "Renewal due date" value if a value is not specified in the "On hold due date" input box
- Remove the contents of the "Renewal due date" input box
- Click "Renew or check in selected items"
- TEST: Observe that the standard loan period is used for the renewal period if no due date is specified in either box
- In the "On hold due date" input box, select a due date for the item
- In the "Renewal due date" input box, select a different due date
- Click "Renew all"
- TEST: Observe that all non on hold items are renewed using the value in "Renewal due date" and on hold items are renewed using the value in "On hold due date"
- From the main staff client from page, choose "Circulation", then choose "Renew"
- Enter the barcode of an item that you know to be on hold and submit
- TEST: In the alert box that appears, observe that a date picker is
displayed
- Choose a due date for this item, then click "Override and renew"
- TEST: In the "Item renewed" box, observe that the item has been
renewed to the date specified

Sponsored-by: Cheshire Libraries Shared Services
Sponsored-by: Halton Borough Council
Sponsored-by: Sefton Council

Signed-off-by: Andrew Farthing <Andrew.Farthing@sefton.gov.uk>

Signed-off-by: Liz Rea <wizzyrea@gmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

circ/renew.pl
koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table-footer.inc
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
koha-tmpl/intranet-tmpl/prog/js/checkouts.js
koha-tmpl/intranet-tmpl/prog/js/pages/circulation.js
svc/renew

index 1f3254a..a431a2c 100755 (executable)
@@ -95,7 +95,7 @@ if ($barcode) {
                 }
                 if ($can_renew) {
                     my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
-                    my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode );
+                    my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode, dt_from_string( scalar $cgi->param('renewonholdduedate')) );
                     $template->param( date_due => $date_due );
                 }
             }
index c0f13ae..1dd3c6c 100644 (file)
@@ -3827,12 +3827,31 @@ span {
     }
 }
 
+input.renew {
+    margin-right: 1em;
+}
+
 .renewals {
     display: block;
     font-size: .8em;
     padding: .5em;
 }
 
+.dialog input#renewonholdduedate {
+    padding: 2px;
+}
+
+.date-select {
+    label {
+        display: inline-block;
+        width: 40%;
+    }
+}
+
+#newonholdduedate {
+    display: none;
+}
+
 #transport-types {
     padding-top: .5px;
 }
index ab8c447..931d92f 100644 (file)
@@ -4,10 +4,12 @@
         <td id="totaldue" style="text-align: right;"></td>
         <td id="totalfine" style="text-align: right;"></td>
         <td id="totalprice" style="text-align: right;"></td>
-                <td colspan="3"><div class="date-select">
-            <p><label for="newduedate">Renewal due date:</label> <input type="text" size="12" id="newduedate" name="newduedate" value="" />
-</p>
-            <p><label for="exemptfine">Forgive fines on return: <input type="checkbox" id="exemptfine" name="exemptfine" value="1" /></label></p></div>
+        <td colspan="3">
+            <div class="date-select">
+                <p><label for="newduedate">Renewal due date:</label> <input type="text" size="12" id="newduedate" name="newduedate" value="" /></p>
+                <p id="newonholdduedate"><label for="newonholdduedate">On hold due date:</label> <input type="text" size="12" name="newonholdduedate" value="" /></p>
+                <p><label for="exemptfine">Forgive fines on return:</label> <input type="checkbox" id="exemptfine" name="exemptfine" value="1" /></p>
+            </div>
                </td>
        </tr>
 </tfoot>
index 1b327b5..5ddcb78 100644 (file)
         var branchcode = "[% branch | html %]";
         var exports_enabled = "[% Koha.Preference('ExportCircHistory') | html %]";
         var AllowRenewalLimitOverride = [% (CAN_user_circulate_override_renewals && Koha.Preference('AllowRenewalLimitOverride') )? 1: 0 | html %];
+        var AllowRenewalOnHoldOverride = [% (CAN_user_circulate_override_renewals && Koha.Preference('AllowRenewalOnHoldOverride') )? 1: 0 | html %];
         var AllowCirculate = [% (CAN_user_circulate_circulate_remaining_permissions)? 1 : 0 | html %];
         var script = "circulation";
         var relatives_borrowernumbers = new Array();
index c0542db..9d38670 100644 (file)
@@ -1,3 +1,5 @@
+[% USE raw %]
+[% USE Asset %]
 [% USE Koha %]
 [% USE KohaDates %]
 [% SET footerjs = 1 %]
                                     <input type="hidden" name="barcode" value="[% item.barcode | html %]"/>
                                     <input type="hidden" name="override_limit" value="1" />
                                     <input type="hidden" name="override_holds" value="1" />
+                                    <div>
+                                        <label for="renewonholdduedate">Renewal due date:</label> <input type="text" size="12" id="renewonholdduedate" name="renewonholdduedate" value="" />
+                                    </div>
                                     <button type="submit" class="approve"><i class="fa fa-check"></i> Override and renew</button>
                                 </form>
 
     </div> <!-- /.row -->
 
 [% MACRO jsinclude BLOCK %]
+    [% INCLUDE 'calendar.inc' %]
+    [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %]
+    [% INCLUDE 'timepicker.inc' %]
     [% IF error %]
         <script>
             $( document ).ready(function() {
             });
         </script>
     [% END %]
+    <script type="text/javascript">
+        $( document ).ready(function() {
+            $("#renewonholdduedate").datetimepicker({
+                onClose: function(dateText, inst) {
+                    validate_date(dateText, inst);
+                },
+                minDate: 1, // require that renewal date is after today
+                hour: 23,
+                minute: 59
+            }).on('change', function(e) {
+                if ( ! is_valid_date( $(this).val() ) ) {$(this).val('');}
+            });
+        });
+    </script>
 [% END %]
 
 [% INCLUDE 'intranet-bottom.inc' %]
index d14e1bd..2b70f8d 100644 (file)
         var exports_enabled = "[% Koha.Preference('ExportCircHistory') | html %]";
         var AllowCirculate = [% (CAN_user_circulate_circulate_remaining_permissions)? 1 : 0 | html %]
         var AllowRenewalLimitOverride = [% (CAN_user_circulate_override_renewals && Koha.Preference('AllowRenewalLimitOverride') )? 1: 0 | html %];
+        var AllowRenewalOnHoldOverride = [% (CAN_user_circulate_override_renewals && Koha.Preference('AllowRenewalOnHoldOverride') )? 1: 0 | html %];
         var script = "moremember";
         var relatives_borrowernumbers = new Array();
         [% FOREACH b IN relatives_borrowernumbers %]
index 4fbaea6..4ca568c 100644 (file)
@@ -3,14 +3,37 @@ $(document).ready(function() {
 
     var barcodefield = $("#barcode");
 
+    var onHoldDueDateSet = false;
+
+    var onHoldChecked = function() {
+        var isChecked = false;
+        $('input[data-on-reserve]').each(function() {
+            if ($(this).is(':checked')) {
+                isChecked=true;
+            }
+        });
+        return isChecked;
+    };
+
+    var showHideOnHoldRenewal = function() {
+        // Display the date input
+        if (onHoldChecked()) {
+            $('#newonholdduedate').show()
+        } else {
+            $('#newonholdduedate').hide();
+        }
+    };
+
     // Handle the select all/none links for checkouts table columns
     $("#CheckAllRenewals").on("click",function(){
         $("#UncheckAllCheckins").click();
         $(".renew:visible").prop("checked", true);
+        showHideOnHoldRenewal();
         return false;
     });
     $("#UncheckAllRenewals").on("click",function(){
         $(".renew:visible").prop("checked", false);
+        showHideOnHoldRenewal();
         return false;
     });
 
@@ -24,6 +47,16 @@ $(document).ready(function() {
         return false;
     });
 
+    $("#newduedate").on("change", function() {
+        if (!onHoldDueDateSet) {
+            $('#newonholdduedate input').val($('#newduedate').val());
+        }
+    });
+
+    $("#newonholdduedate").on("change", function() {
+        onHoldDueDateSet = true;
+    });
+
     // Don't allow both return and renew checkboxes to be checked
     $(document).on("change", '.renew', function(){
         if ( $(this).is(":checked") ) {
@@ -36,6 +69,12 @@ $(document).ready(function() {
         }
     });
 
+    // Display on hold due dates input when an on hold item is
+    // selected
+    $(document).on('change', '.renew', function(){
+        showHideOnHoldRenewal();
+    });
+
     $("#output_format > option:first-child").attr("selected", "selected");
     $("select[name='csv_profile_id']").hide();
     $(document).on("change", '#issues-table-output-format', function(){
@@ -92,18 +131,28 @@ $(document).ready(function() {
         $(".renew:checked:visible").each(function() {
             var override_limit = $("#override_limit").is(':checked') ? 1 : 0;
 
+            var isOnReserve = $(this).data().hasOwnProperty('onReserve');
+
             var itemnumber = $(this).val();
 
             $(this).parent().parent().replaceWith("<img id='renew_" + itemnumber + "' src='" + interface + "/" + theme + "/img/spinner-small.gif' />");
 
             var params = {
-                itemnumber:     itemnumber,
-                borrowernumber: borrowernumber,
-                branchcode:     branchcode,
-                override_limit: override_limit,
-                date_due:       $("#newduedate").val()
+                itemnumber:      itemnumber,
+                borrowernumber:  borrowernumber,
+                branchcode:      branchcode,
+                override_limit:  override_limit,
             };
 
+            // Determine which due date we need to use
+            var dueDate = isOnReserve ?
+                $("#newonholdduedate input").val() :
+                $("#newduedate").val();
+
+            if (dueDate && dueDate.length > 0) {
+                params.date_due = dueDate
+            }
+
             $.post( "/cgi-bin/koha/svc/renew", params, function( data ) {
                 var id = "#renew_" + data.itemnumber;
 
@@ -146,6 +195,7 @@ $(document).ready(function() {
     $("#RenewAll").on("click",function(){
         $("#CheckAllRenewals").click();
         $("#UncheckAllCheckins").click();
+        showHideOnHoldRenewal();
         $("#RenewCheckinChecked").click();
 
         // Prevent form submit
@@ -351,79 +401,77 @@ $(document).ready(function() {
                     "bVisible": AllowCirculate ? true : false,
                     "mDataProp": function ( oObj ) {
                         var content = "";
+                        var msg = "";
                         var span_style = "";
                         var span_class = "";
 
-                        content += "<span>";
-                        content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
-
                         if ( oObj.can_renew ) {
                             // Do nothing
                         } else if ( oObj.can_renew_error == "on_reserve" ) {
-                            content += "<span class='renewals-disabled-no-override'>"
+                            msg += "<span class='renewals-disabled-no-override'>"
                                     + "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber=" + oObj.biblionumber + "'>" + ON_HOLD + "</a>"
                                     + "</span>";
 
-                            span_style = "display: none";
+                            span_style = AllowRenewalLimitOverride ? "" : "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "too_many" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE
                                     + "</span>";
 
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "restriction" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE_RESTRICTION
                                     + "</span>";
 
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "overdue" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE_OVERDUE
                                     + "</span>";
 
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "too_soon" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE_TOO_SOON.format( oObj.can_renew_date )
                                     + "</span>";
 
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "auto_too_soon" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE_AUTO_TOO_SOON
                                     + "</span>";
 
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "auto_too_late" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE_AUTO_TOO_LATE
                                     + "</span>";
 
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "auto_too_much_oweing" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE_AUTO_TOO_MUCH_OWEING
                                     + "</span>";
 
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "auto_account_expired" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE_AUTO_ACCOUNT_EXPIRED
                                     + "</span>";
 
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "auto_renew" ) {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + NOT_RENEWABLE_AUTO_RENEW
                                     + "</span>";
 
@@ -439,7 +487,7 @@ $(document).ready(function() {
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else {
-                            content += "<span class='renewals-disabled'>"
+                            msg += "<span class='renewals-disabled'>"
                                     + oObj.can_renew_error
                                     + "</span>";
 
@@ -447,17 +495,26 @@ $(document).ready(function() {
                             span_class = "renewals-allowed";
                         }
 
-                        var can_force_renew = ( oObj.onsite_checkout == 0 ) && ( oObj.can_renew_error != "on_reserve" );
+                        var can_force_renew = ( oObj.onsite_checkout == 0 ) &&
+                            ( oObj.can_renew_error != "on_reserve" || (oObj.can_renew_error == "on_reserve" && AllowRenewalOnHoldOverride))
+                            ? true : false;
                         var can_renew = ( oObj.renewals_remaining > 0  && !oObj.can_renew_error );
+                        content += "<span>";
                         if ( can_renew || can_force_renew ) {
+                            content += "<span style='padding: 0 1em;'>" + oObj.renewals_count + "</span>";
                             content += "<span class='" + span_class + "' style='" + span_style + "'>"
                                     +  "<input type='checkbox' ";
                             if ( oObj.date_due_overdue && can_renew ) {
                                 content += "checked='checked' ";
                             }
+                            if (oObj.can_renew_error == "on_reserve") {
+                                content += "data-on-reserve ";
+                            }
                             content += "class='renew' id='renew_" + oObj.itemnumber + "' name='renew' value='" + oObj.itemnumber +"'/>"
                                     +  "</span>";
-
+                        }
+                        content += msg;
+                        if ( can_renew || can_force_renew ) {
                             content += "<span class='renewals'>("
                                     + RENEWALS_REMAINING.format( oObj.renewals_remaining, oObj.renewals_allowed )
                                     + ")</span>";
index cd2ca9b..9602550 100644 (file)
@@ -28,7 +28,7 @@ $(document).ready(function() {
         radioCheckBox($(this));
     });
 
-    $("#newduedate").datetimepicker({
+    $("#newduedate, #newonholdduedate input").datetimepicker({
         onClose: function(dateText, inst) {
             validate_date(dateText, inst);
         },
index 1aa9a28..29e51d8 100755 (executable)
--- a/svc/renew
+++ b/svc/renew
@@ -59,6 +59,12 @@ $data->{branchcode} = $branchcode;
 ( $data->{renew_okay}, $data->{error} ) =
   CanBookBeRenewed( $borrowernumber, $itemnumber, $override_limit );
 
+# If we're allowing reserved items to be renewed...
+if ( $data->{error} && $data->{error} eq 'on_reserve' && C4::Context->preference('AllowRenewalOnHoldOverride')) {
+    $data->{renew_okay} = 1;
+    $data->{error} = undef;
+}
+
 if ( $data->{renew_okay} ) {
     $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due );
     $data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );