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

(-)a/C4/Circulation.pm (-33 / +34 lines)
Lines 1176-1182 AddIssue does the following things : Link Here
1176
=cut
1176
=cut
1177
1177
1178
sub AddIssue {
1178
sub AddIssue {
1179
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode) = @_;
1179
    my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate, $sipmode, $auto_renew ) = @_;
1180
    my $dbh = C4::Context->dbh;
1180
    my $dbh = C4::Context->dbh;
1181
	my $barcodecheck=CheckValidBarcode($barcode);
1181
	my $barcodecheck=CheckValidBarcode($barcode);
1182
    if ($datedue && ref $datedue ne 'DateTime') {
1182
    if ($datedue && ref $datedue ne 'DateTime') {
Lines 1242-1253 sub AddIssue { Link Here
1242
                $sth->execute(C4::Context->userenv->{'branch'},$item->{'itemnumber'});
1242
                $sth->execute(C4::Context->userenv->{'branch'},$item->{'itemnumber'});
1243
            }
1243
            }
1244
1244
1245
        # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1246
        unless ($auto_renew) {
1247
            my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branch);
1248
            $auto_renew = $issuingrule->{auto_renew};
1249
        }
1250
1245
        # Record in the database the fact that the book was issued.
1251
        # Record in the database the fact that the book was issued.
1246
        my $sth =
1252
        my $sth =
1247
          $dbh->prepare(
1253
          $dbh->prepare(
1248
                "INSERT INTO issues
1254
                "INSERT INTO issues
1249
                    (borrowernumber, itemnumber,issuedate, date_due, branchcode)
1255
                    (borrowernumber, itemnumber,issuedate, date_due, branchcode, auto_renew)
1250
                VALUES (?,?,?,?,?)"
1256
                VALUES (?,?,?,?,?,?)"
1251
          );
1257
          );
1252
        unless ($datedue) {
1258
        unless ($datedue) {
1253
            my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
1259
            my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
Lines 1260-1266 sub AddIssue { Link Here
1260
            $item->{'itemnumber'},              # itemnumber
1266
            $item->{'itemnumber'},              # itemnumber
1261
            $issuedate->strftime('%Y-%m-%d %H:%M:00'), # issuedate
1267
            $issuedate->strftime('%Y-%m-%d %H:%M:00'), # issuedate
1262
            $datedue->strftime('%Y-%m-%d %H:%M:00'),   # date_due
1268
            $datedue->strftime('%Y-%m-%d %H:%M:00'),   # date_due
1263
            C4::Context->userenv->{'branch'}    # branchcode
1269
            C4::Context->userenv->{'branch'},   # branchcode
1270
            $auto_renew ? 1 : 0                 # automatic renewal
1264
        );
1271
        );
1265
        if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart.
1272
        if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart.
1266
          CartToShelf( $item->{'itemnumber'} );
1273
          CartToShelf( $item->{'itemnumber'} );
Lines 2584-2590 C<$itemnumber> is the number of the item to renew. Link Here
2584
2591
2585
C<$override_limit>, if supplied with a true value, causes
2592
C<$override_limit>, if supplied with a true value, causes
2586
the limit on the number of times that the loan can be renewed
2593
the limit on the number of times that the loan can be renewed
2587
(as controlled by the item type) to be ignored.
2594
(as controlled by the item type) to be ignored. Overriding also allows
2595
to renew sooner than "No renewal before" und to manually renew loans
2596
that are automatically renewed.
2588
2597
2589
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
2598
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
2590
item must currently be on loan to the specified borrower; renewals
2599
item must currently be on loan to the specified borrower; renewals
Lines 2596-2605 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2596
sub CanBookBeRenewed {
2605
sub CanBookBeRenewed {
2597
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2606
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2598
2607
2599
    my $dbh       = C4::Context->dbh;
2608
    my $dbh    = C4::Context->dbh;
2600
    my $renews    = 1;
2609
    my $renews = 1;
2601
    my $renewokay = 1;
2602
    my $error;
2603
2610
2604
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2611
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2605
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
2612
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
Lines 2608-2649 sub CanBookBeRenewed { Link Here
2608
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
2615
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
2609
      or return;
2616
      or return;
2610
2617
2611
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2618
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
2612
2619
2613
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2620
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2621
2622
    return ( 1, undef ) if $override_limit;
2623
2624
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2625
    my $issuingrule =
2626
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
2627
2628
    return ( 0, "too_many" )
2629
      if $issuingrule->{renewalsallowed} <= $itemissue->{renewals};
2614
2630
2615
    if ( $issuingrule->{norenewalbefore} ) {
2631
    if ( $issuingrule->{norenewalbefore} ) {
2616
2632
2617
        # Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal.
2633
        # Get current time and add norenewalbefore.
2634
        # If this is smaller than date_due, it's too soon for renewal.
2618
        if (
2635
        if (
2619
            DateTime->now( time_zone => C4::Context->tz() )->add(
2636
            DateTime->now( time_zone => C4::Context->tz() )->add(
2620
                $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
2637
                $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
2621
            ) < $itemissue->{date_due}
2638
            ) < $itemissue->{date_due}
2622
        )
2639
          )
2623
        {
2640
        {
2624
            $renewokay = 0;
2641
            return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew};
2625
            $error     = "too_soon";
2642
            return ( 0, "too_soon" );
2626
        }
2643
        }
2627
    }
2644
    }
2628
2645
2629
    if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) {
2646
    return ( 0, "auto_renew" ) if $itemissue->{auto_renew};
2630
        $renewokay = 0;
2647
    return ( 1, undef );
2631
        $error = "too_many";
2632
    }
2633
2634
    if ( $override_limit ) {
2635
        $renewokay = 1;
2636
        $error     = undef;
2637
    }
2638
2639
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber );
2640
2641
    if ( $resfound ) { # '' when no hold was found
2642
        $renewokay = 0;
2643
        $error = "on_reserve";
2644
    }
2645
2646
    return ( $renewokay, $error );
2647
}
2648
}
2648
2649
2649
=head2 AddRenewal
2650
=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