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 2599-2605 C<$itemnumber> is the number of the item to renew. Link Here
2599
2606
2600
C<$override_limit>, if supplied with a true value, causes
2607
C<$override_limit>, if supplied with a true value, causes
2601
the limit on the number of times that the loan can be renewed
2608
the limit on the number of times that the loan can be renewed
2602
(as controlled by the item type) to be ignored.
2609
(as controlled by the item type) to be ignored. Overriding also allows
2610
to renew sooner than "No renewal before" and to manually renew loans
2611
that are automatically renewed.
2603
2612
2604
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
2613
C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
2605
item must currently be on loan to the specified borrower; renewals
2614
item must currently be on loan to the specified borrower; renewals
Lines 2611-2620 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2611
sub CanBookBeRenewed {
2620
sub CanBookBeRenewed {
2612
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2621
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2613
2622
2614
    my $dbh       = C4::Context->dbh;
2623
    my $dbh    = C4::Context->dbh;
2615
    my $renews    = 1;
2624
    my $renews = 1;
2616
    my $renewokay = 1;
2617
    my $error;
2618
2625
2619
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2626
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2620
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
2627
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
Lines 2623-2664 sub CanBookBeRenewed { Link Here
2623
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
2630
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
2624
      or return;
2631
      or return;
2625
2632
2626
    my $branchcode  = _GetCircControlBranch($item, $borrower);
2633
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
2627
2634
2628
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2635
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2636
2637
    return ( 1, undef ) if $override_limit;
2638
2639
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2640
    my $issuingrule =
2641
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
2642
2643
    return ( 0, "too_many" )
2644
      if $issuingrule->{renewalsallowed} <= $itemissue->{renewals};
2629
2645
2630
    if ( $issuingrule->{norenewalbefore} ) {
2646
    if ( $issuingrule->{norenewalbefore} ) {
2631
2647
2632
        # Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal.
2648
        # Get current time and add norenewalbefore.
2649
        # If this is smaller than date_due, it's too soon for renewal.
2633
        if (
2650
        if (
2634
            DateTime->now( time_zone => C4::Context->tz() )->add(
2651
            DateTime->now( time_zone => C4::Context->tz() )->add(
2635
                $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
2652
                $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
2636
            ) < $itemissue->{date_due}
2653
            ) < $itemissue->{date_due}
2637
        )
2654
          )
2638
        {
2655
        {
2639
            $renewokay = 0;
2656
            return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew};
2640
            $error     = "too_soon";
2657
            return ( 0, "too_soon" );
2641
        }
2658
        }
2642
    }
2659
    }
2643
2660
2644
    if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) {
2661
    return ( 0, "auto_renew" ) if $itemissue->{auto_renew};
2645
        $renewokay = 0;
2662
    return ( 1, undef );
2646
        $error = "too_many";
2647
    }
2648
2649
    if ( $override_limit ) {
2650
        $renewokay = 1;
2651
        $error     = undef;
2652
    }
2653
2654
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber );
2655
2656
    if ( $resfound ) { # '' when no hold was found
2657
        $renewokay = 0;
2658
        $error = "on_reserve";
2659
    }
2660
2661
    return ( $renewokay, $error );
2662
}
2663
}
2663
2664
2664
=head2 AddRenewal
2665
=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 255-260 $(document).ready(function() { Link Here
255
255
256
                        span_style = "display: none";
256
                        span_style = "display: none";
257
                        span_class = "renewals-allowed";
257
                        span_class = "renewals-allowed";
258
                    } else if ( oObj.can_renew_error == "auto_too_soon" ) {
259
                        content += "<span class='renewals-disabled'>"
260
                                + NOT_RENEWABLE_AUTO_TOO_SOON
261
                                + "</span>";
262
263
                        span_style = "display: none";
264
                        span_class = "renewals-allowed";
265
                    } else if ( oObj.can_renew_error == "auto_renew" ) {
266
                        content += "<span class='renewals-disabled'>"
267
                                + NOT_RENEWABLE_AUTO_RENEW
268
                                + "</span>";
269
270
                        span_style = "display: none";
271
                        span_class = "renewals-allowed";
258
                    } else {
272
                    } else {
259
                        content += "<span class='renewals-disabled'>"
273
                        content += "<span class='renewals-disabled'>"
260
                                + oObj.can_renew_error
274
                                + oObj.can_renew_error
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 / +9 lines)
Lines 489-494 No patron matched <span class="ex">[% message %]</span> Link Here
489
    [% END %]
489
    [% END %]
490
    <button type="submit" class="btn">Check out</button>
490
    <button type="submit" class="btn">Check out</button>
491
491
492
    <div class="date-select">
493
        [% IF NEEDSCONFIRMATION %]
494
            <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled" />
495
        [% ELSE %]
496
            <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" />
497
        [% END %]
498
        <label for="auto_renew">Automatic renewal</label>
499
    </div>
500
492
    [% IF ( SpecifyDueDate ) %]<div class="date-select">
501
    [% IF ( SpecifyDueDate ) %]<div class="date-select">
493
        <div class="hint">Specify due date [% INCLUDE 'date-format.inc' %]: </div>
502
        <div class="hint">Specify due date [% INCLUDE 'date-format.inc' %]: </div>
494
        [% 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" />
503
        [% 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" />
495
- 

Return to bug 11577