Bug 11577: Code and intranet template changes
authorHolger Meißner <h.meissner.82@web.de>
Thu, 15 May 2014 14:43:00 +0000 (16:43 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Wed, 17 Sep 2014 22:23:14 +0000 (19:23 -0300)
This patch adds a checkbox for "Automatic renewal" to the checkout page.
CanBookBeRenewed is modified to include two new errors:
- auto_renew (renewal shouldn't be done manually)
- auto_too_soon (renewal is premature and shouldn't be done manually)

To test:

1) Add or edit an issuing rule with "Automatic renewal" and another
   one without it.
2) Issue at least three items:
   - automatic renewal by issuing rule
   - automatic renewal by Checkbox on the checkout page
   - no automatic renewal
3) Test the following steps for both:
   Home > Circulation > Checkouts
   Home > Patrons > Patron details
4) Confirm that issues with automatic renewal cannot be renewed manually,
   even if there are still renewals left and it's not too soon to renew.
5) Confirm that "Scheduled for automatic renewal" and the remaining
   renewals are displayed. If no renewals are left "Not renewable" should
   be displayed.
6) Confirm that issues without automatic renewal behave as usual.

Sponsored-by: Hochschule für Gesundheit (hsg), Germany
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
C4/Circulation.pm
circ/circulation.pl
koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc
koha-tmpl/intranet-tmpl/prog/en/js/checkouts.js
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt

index 55f0c27..8c0b208 100644 (file)
@@ -1183,7 +1183,7 @@ AddIssue does the following things :
 =cut
 
 sub AddIssue {
-    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode) = @_;
+    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $auto_renew ) = @_;
     my $dbh = C4::Context->dbh;
        my $barcodecheck=CheckValidBarcode($barcode);
     if ($datedue && ref $datedue ne 'DateTime') {
@@ -1249,12 +1249,18 @@ sub AddIssue {
                 $sth->execute(C4::Context->userenv->{'branch'},$item->{'itemnumber'});
             }
 
+        # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
+        unless ($auto_renew) {
+            my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branch);
+            $auto_renew = $issuingrule->{auto_renew};
+        }
+
         # Record in the database the fact that the book was issued.
         my $sth =
           $dbh->prepare(
                 "INSERT INTO issues
-                    (borrowernumber, itemnumber,issuedate, date_due, branchcode)
-                VALUES (?,?,?,?,?)"
+                    (borrowernumber, itemnumber,issuedate, date_due, branchcode, auto_renew)
+                VALUES (?,?,?,?,?,?)"
           );
         unless ($datedue) {
             my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
@@ -1267,7 +1273,8 @@ sub AddIssue {
             $item->{'itemnumber'},              # itemnumber
             $issuedate->strftime('%Y-%m-%d %H:%M:00'), # issuedate
             $datedue->strftime('%Y-%m-%d %H:%M:00'),   # date_due
-            C4::Context->userenv->{'branch'}    # branchcode
+            C4::Context->userenv->{'branch'},   # branchcode
+            $auto_renew ? 1 : 0                 # automatic renewal
         );
         if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart.
           CartToShelf( $item->{'itemnumber'} );
@@ -2599,7 +2606,9 @@ C<$itemnumber> is the number of the item to renew.
 
 C<$override_limit>, if supplied with a true value, causes
 the limit on the number of times that the loan can be renewed
-(as controlled by the item type) to be ignored.
+(as controlled by the item type) to be ignored. Overriding also allows
+to renew sooner than "No renewal before" and to manually renew loans
+that are automatically renewed.
 
 C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
 item must currently be on loan to the specified borrower; renewals
@@ -2611,10 +2620,8 @@ already renewed the loan. $error will contain the reason the renewal can not pro
 sub CanBookBeRenewed {
     my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
 
-    my $dbh       = C4::Context->dbh;
-    my $renews    = 1;
-    my $renewokay = 1;
-    my $error;
+    my $dbh    = C4::Context->dbh;
+    my $renews = 1;
 
     my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
     my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
@@ -2623,42 +2630,36 @@ sub CanBookBeRenewed {
     my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
       or return;
 
-    my $branchcode  = _GetCircControlBranch($item, $borrower);
+    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
 
-    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
+    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
+
+    return ( 1, undef ) if $override_limit;
+
+    my $branchcode = _GetCircControlBranch( $item, $borrower );
+    my $issuingrule =
+      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
+
+    return ( 0, "too_many" )
+      if $issuingrule->{renewalsallowed} <= $itemissue->{renewals};
 
     if ( $issuingrule->{norenewalbefore} ) {
 
-        # Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal.
+        # Get current time and add norenewalbefore.
+        # If this is smaller than date_due, it's too soon for renewal.
         if (
             DateTime->now( time_zone => C4::Context->tz() )->add(
                 $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
             ) < $itemissue->{date_due}
-        )
+          )
         {
-            $renewokay = 0;
-            $error     = "too_soon";
+            return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew};
+            return ( 0, "too_soon" );
         }
     }
 
-    if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) {
-        $renewokay = 0;
-        $error = "too_many";
-    }
-
-    if ( $override_limit ) {
-        $renewokay = 1;
-        $error     = undef;
-    }
-
-    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber );
-
-    if ( $resfound ) { # '' when no hold was found
-        $renewokay = 0;
-        $error = "on_reserve";
-    }
-
-    return ( $renewokay, $error );
+    return ( 0, "auto_renew" ) if $itemissue->{auto_renew};
+    return ( 1, undef );
 }
 
 =head2 AddRenewal
index c766e88..8f79f71 100755 (executable)
@@ -134,6 +134,10 @@ if ( $barcode ) {
         $stickyduedate  = $query->param('stickyduedate');
         $duedatespec    = $query->param('duedatespec');
     }
+    $session->param('auto_renew', $query->param('auto_renew'));
+}
+else {
+    $session->clear('auto_renew');
 }
 
 my ($datedue,$invalidduedate);
@@ -344,7 +348,8 @@ if ($barcode) {
             }
         }
         unless($confirm_required) {
-            AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
+            AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, $session->param('auto_renew') );
+            $session->clear('auto_renew');
             $inprocess = 1;
         }
     }
index df9ca78..8d1327e 100644 (file)
@@ -14,6 +14,8 @@
     var ON_HOLD = _("On hold");
     var NOT_RENEWABLE = _("Not renewable");
     var NOT_RENEWABLE_TOO_SOON = _("No renewal before %s");
+    var NOT_RENEWABLE_AUTO_TOO_SOON = _("Scheduled for automatic renewal");
+    var NOT_RENEWABLE_AUTO_RENEW = _("Scheduled for automatic renewal");
     var RENEWALS_REMAINING = _("%s of %s renewals remaining");
     var HOLD_IS_SUSPENDED = _("Hold is <strong>suspended</strong>");
     var UNTIL = _("until %s");
index 1755d6c..b2e47e4 100644 (file)
@@ -255,6 +255,20 @@ $(document).ready(function() {
 
                         span_style = "display: none";
                         span_class = "renewals-allowed";
+                    } else if ( oObj.can_renew_error == "auto_too_soon" ) {
+                        content += "<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_renew" ) {
+                        content += "<span class='renewals-disabled'>"
+                                + NOT_RENEWABLE_AUTO_RENEW
+                                + "</span>";
+
+                        span_style = "display: none";
+                        span_class = "renewals-allowed";
                     } else {
                         content += "<span class='renewals-disabled'>"
                                 + oObj.can_renew_error
index ae8ef28..fc61059 100644 (file)
@@ -489,6 +489,15 @@ No patron matched <span class="ex">[% message %]</span>
     [% END %]
     <button type="submit" class="btn">Check out</button>
 
+    <div class="date-select">
+        [% IF NEEDSCONFIRMATION %]
+            <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled" />
+        [% ELSE %]
+            <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" />
+        [% END %]
+        <label for="auto_renew">Automatic renewal</label>
+    </div>
+
     [% IF ( SpecifyDueDate ) %]<div class="date-select">
         <div class="hint">Specify due date [% INCLUDE 'date-format.inc' %]: </div>
         [% IF ( duedatespec ) %]<input type="text" size="13" id="duedatespec" name="duedatespec" value="[% duedatespec %]" readonly="readonly" />[% ELSE %]<input type="text" size="13" id="duedatespec" name="duedatespec" value="" readonly="readonly" />