View | Details | Raw Unified | Return to bug 11577
Collapse All | Expand All

(-)a/C4/Circulation.pm (-33 / +34 lines)
Lines 1183-1189 AddIssue does the following things : Link Here
1183
=cut
1183
=cut
1184
1184
1185
sub AddIssue {
1185
sub AddIssue {
1186
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode) = @_;
1186
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $auto_renew ) = @_;
1187
    my $dbh = C4::Context->dbh;
1187
    my $dbh = C4::Context->dbh;
1188
	my $barcodecheck=CheckValidBarcode($barcode);
1188
	my $barcodecheck=CheckValidBarcode($barcode);
1189
    if ($datedue && ref $datedue ne 'DateTime') {
1189
    if ($datedue && ref $datedue ne 'DateTime') {
Lines 1249-1260 sub AddIssue { Link Here
1249
                $sth->execute(C4::Context->userenv->{'branch'},$item->{'itemnumber'});
1249
                $sth->execute(C4::Context->userenv->{'branch'},$item->{'itemnumber'});
1250
            }
1250
            }
1251
1251
1252
        # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1253
        unless ($auto_renew) {
1254
            my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branch);
1255
            $auto_renew = $issuingrule->{auto_renew};
1256
        }
1257
1252
        # Record in the database the fact that the book was issued.
1258
        # Record in the database the fact that the book was issued.
1253
        my $sth =
1259
        my $sth =
1254
          $dbh->prepare(
1260
          $dbh->prepare(
1255
                "INSERT INTO issues
1261
                "INSERT INTO issues
1256
                    (borrowernumber, itemnumber,issuedate, date_due, branchcode)
1262
                    (borrowernumber, itemnumber,issuedate, date_due, branchcode, auto_renew)
1257
                VALUES (?,?,?,?,?)"
1263
                VALUES (?,?,?,?,?,?)"
1258
          );
1264
          );
1259
        unless ($datedue) {
1265
        unless ($datedue) {
1260
            my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
1266
            my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
Lines 1267-1273 sub AddIssue { Link Here
1267
            $item->{'itemnumber'},              # itemnumber
1273
            $item->{'itemnumber'},              # itemnumber
1268
            $issuedate->strftime('%Y-%m-%d %H:%M:00'), # issuedate
1274
            $issuedate->strftime('%Y-%m-%d %H:%M:00'), # issuedate
1269
            $datedue->strftime('%Y-%m-%d %H:%M:00'),   # date_due
1275
            $datedue->strftime('%Y-%m-%d %H:%M:00'),   # date_due
1270
            C4::Context->userenv->{'branch'}    # branchcode
1276
            C4::Context->userenv->{'branch'},   # branchcode
1277
            $auto_renew ? 1 : 0                 # automatic renewal
1271
        );
1278
        );
1272
        if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart.
1279
        if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart.
1273
          CartToShelf( $item->{'itemnumber'} );
1280
          CartToShelf( $item->{'itemnumber'} );
Lines 2597-2603 C<$itemnumber> is the number of the item to renew. Link Here
2597
2604
2598
C<$override_limit>, if supplied with a true value, causes
2605
C<$override_limit>, if supplied with a true value, causes
2599
the limit on the number of times that the loan can be renewed
2606
the limit on the number of times that the loan can be renewed
2600
(as controlled by the item type) to be ignored.
2607
(as controlled by the item type) to be ignored. Overriding also allows
2608
to renew sooner than "No renewal before" und to manually renew loans
2609
that are automatically renewed.
2601
2610
2602
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
2611
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
2603
item must currently be on loan to the specified borrower; renewals
2612
item must currently be on loan to the specified borrower; renewals
Lines 2609-2618 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2609
sub CanBookBeRenewed {
2618
sub CanBookBeRenewed {
2610
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2619
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2611
2620
2612
    my $dbh       = C4::Context->dbh;
2621
    my $dbh    = C4::Context->dbh;
2613
    my $renews    = 1;
2622
    my $renews = 1;
2614
    my $renewokay = 1;
2615
    my $error;
2616
2623
2617
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2624
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2618
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
2625
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
Lines 2621-2662 sub CanBookBeRenewed { Link Here
2621
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
2628
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
2622
      or return;
2629
      or return;
2623
2630
2624
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2631
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
2625
2632
2626
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2633
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2634
2635
    return ( 1, undef ) if $override_limit;
2636
2637
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2638
    my $issuingrule =
2639
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
2640
2641
    return ( 0, "too_many" )
2642
      if $issuingrule->{renewalsallowed} <= $itemissue->{renewals};
2627
2643
2628
    if ( $issuingrule->{norenewalbefore} ) {
2644
    if ( $issuingrule->{norenewalbefore} ) {
2629
2645
2630
        # Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal.
2646
        # Get current time and add norenewalbefore.
2647
        # If this is smaller than date_due, it's too soon for renewal.
2631
        if (
2648
        if (
2632
            DateTime->now( time_zone => C4::Context->tz() )->add(
2649
            DateTime->now( time_zone => C4::Context->tz() )->add(
2633
                $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
2650
                $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
2634
            ) < $itemissue->{date_due}
2651
            ) < $itemissue->{date_due}
2635
        )
2652
          )
2636
        {
2653
        {
2637
            $renewokay = 0;
2654
            return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew};
2638
            $error     = "too_soon";
2655
            return ( 0, "too_soon" );
2639
        }
2656
        }
2640
    }
2657
    }
2641
2658
2642
    if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) {
2659
    return ( 0, "auto_renew" ) if $itemissue->{auto_renew};
2643
        $renewokay = 0;
2660
    return ( 1, undef );
2644
        $error = "too_many";
2645
    }
2646
2647
    if ( $override_limit ) {
2648
        $renewokay = 1;
2649
        $error     = undef;
2650
    }
2651
2652
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber );
2653
2654
    if ( $resfound ) { # '' when no hold was found
2655
        $renewokay = 0;
2656
        $error = "on_reserve";
2657
    }
2658
2659
    return ( $renewokay, $error );
2660
}
2661
}
2661
2662
2662
=head2 AddRenewal
2663
=head2 AddRenewal
(-)a/circ/circulation.pl (-1 / +6 lines)
Lines 134-139 if ( $barcode ) { Link Here
134
        $stickyduedate  = $query->param('stickyduedate');
134
        $stickyduedate  = $query->param('stickyduedate');
135
        $duedatespec    = $query->param('duedatespec');
135
        $duedatespec    = $query->param('duedatespec');
136
    }
136
    }
137
    $session->param('auto_renew', $query->param('auto_renew'));
138
}
139
else {
140
    $session->clear('auto_renew');
137
}
141
}
138
142
139
my ($datedue,$invalidduedate);
143
my ($datedue,$invalidduedate);
Lines 344-350 if ($barcode) { Link Here
344
            }
348
            }
345
        }
349
        }
346
        unless($confirm_required) {
350
        unless($confirm_required) {
347
            AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
351
            AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, $session->param('auto_renew') );
352
            $session->clear('auto_renew');
348
            $inprocess = 1;
353
            $inprocess = 1;
349
        }
354
        }
350
    }
355
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc (+2 lines)
Lines 14-19 Link Here
14
    var ON_HOLD = _("On hold");
14
    var ON_HOLD = _("On hold");
15
    var NOT_RENEWABLE = _("Not renewable");
15
    var NOT_RENEWABLE = _("Not renewable");
16
    var NOT_RENEWABLE_TOO_SOON = _("No renewal before %s");
16
    var NOT_RENEWABLE_TOO_SOON = _("No renewal before %s");
17
    var NOT_RENEWABLE_AUTO_TOO_SOON = _("Scheduled for automatic renewal");
18
    var NOT_RENEWABLE_AUTO_RENEW = _("Scheduled for automatic renewal");
17
    var RENEWALS_REMAINING = _("%s of %s renewals remaining");
19
    var RENEWALS_REMAINING = _("%s of %s renewals remaining");
18
    var HOLD_IS_SUSPENDED = _("Hold is <strong>suspended</strong>");
20
    var HOLD_IS_SUSPENDED = _("Hold is <strong>suspended</strong>");
19
    var UNTIL = _("until %s");
21
    var UNTIL = _("until %s");
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/checkouts.js (+14 lines)
Lines 248-253 $(document).ready(function() { Link Here
248
248
249
                        span_style = "display: none";
249
                        span_style = "display: none";
250
                        span_class = "renewals-allowed";
250
                        span_class = "renewals-allowed";
251
                    } else if ( oObj.can_renew_error == "auto_too_soon" ) {
252
                        content += "<span class='renewals-disabled'>"
253
                                + NOT_RENEWABLE_AUTO_TOO_SOON
254
                                + "</span>";
255
256
                        span_style = "display: none";
257
                        span_class = "renewals-allowed";
258
                    } else if ( oObj.can_renew_error == "auto_renew" ) {
259
                        content += "<span class='renewals-disabled'>"
260
                                + NOT_RENEWABLE_AUTO_RENEW
261
                                + "</span>";
262
263
                        span_style = "display: none";
264
                        span_class = "renewals-allowed";
251
                    } else {
265
                    } else {
252
                        content += "<span class='renewals-disabled'>"
266
                        content += "<span class='renewals-disabled'>"
253
                                + oObj.can_renew_error
267
                                + oObj.can_renew_error
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +9 lines)
Lines 485-490 No patron matched <span class="ex">[% message %]</span> Link Here
485
    [% END %]
485
    [% END %]
486
    <button type="submit" class="btn">Check out</button>
486
    <button type="submit" class="btn">Check out</button>
487
487
488
    <div class="date-select">
489
        [% IF NEEDSCONFIRMATION %]
490
            <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled" />
491
        [% ELSE %]
492
            <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" />
493
        [% END %]
494
        <label for="auto_renew">Automatic renewal</label>
495
    </div>
496
488
    [% IF ( SpecifyDueDate ) %]<div class="date-select">
497
    [% IF ( SpecifyDueDate ) %]<div class="date-select">
489
        <div class="hint">Specify due date [% INCLUDE 'date-format.inc' %]: </div>
498
        <div class="hint">Specify due date [% INCLUDE 'date-format.inc' %]: </div>
490
        [% 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" />
499
        [% 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" />
491
- 

Return to bug 11577