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

(-)a/C4/Circulation.pm (-4 / +69 lines)
Lines 79-84 BEGIN { Link Here
79
		&AddIssue
79
		&AddIssue
80
		&AddRenewal
80
		&AddRenewal
81
		&GetRenewCount
81
		&GetRenewCount
82
        &GetSoonestRenewDate
82
		&GetItemIssue
83
		&GetItemIssue
83
		&GetItemIssues
84
		&GetItemIssues
84
		&GetIssuingCharges
85
		&GetIssuingCharges
Lines 2472-2478 sub CanBookBeRenewed { Link Here
2472
2473
2473
    my $dbh       = C4::Context->dbh;
2474
    my $dbh       = C4::Context->dbh;
2474
    my $renews    = 1;
2475
    my $renews    = 1;
2475
    my $renewokay = 0;
2476
    my $renewokay = 1;
2476
    my $error;
2477
    my $error;
2477
2478
2478
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2479
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
Lines 2486-2497 sub CanBookBeRenewed { Link Here
2486
2487
2487
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2488
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2488
2489
2489
    if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) {
2490
    if ( $issuingrule->{norenewalbefore} ) {
2490
        $renewokay = 1;
2491
2491
    } else {
2492
        # Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal.
2493
        if (
2494
            DateTime->now( time_zone => C4::Context->tz() )->add(
2495
                $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore}
2496
            ) < $itemissue->{date_due}
2497
        )
2498
        {
2499
            $renewokay = 0;
2500
            $error     = "too_soon";
2501
        }
2502
    }
2503
2504
    if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) {
2505
        $renewokay = 0;
2492
        $error = "too_many";
2506
        $error = "too_many";
2493
    }
2507
    }
2494
2508
2509
    if ( $override_limit ) {
2510
        $renewokay = 1;
2511
        $error     = undef;
2512
    }
2513
2495
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber );
2514
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber );
2496
2515
2497
    if ( $resfound ) { # '' when no hold was found
2516
    if ( $resfound ) { # '' when no hold was found
Lines 2668-2673 sub GetRenewCount { Link Here
2668
    return ( $renewcount, $renewsallowed, $renewsleft );
2687
    return ( $renewcount, $renewsallowed, $renewsleft );
2669
}
2688
}
2670
2689
2690
=head2 GetSoonestRenewDate
2691
2692
  $NoRenewalBeforeThisDate = &GetSoonestRenewDate($borrowernumber, $itemnumber);
2693
2694
Find out the soonest possible renew date of a borrowed item.
2695
2696
C<$borrowernumber> is the borrower number of the patron who currently
2697
has the item on loan.
2698
2699
C<$itemnumber> is the number of the item to renew.
2700
2701
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible renew date,
2702
based on the value "No renewal before" of the applicable issuing rule. Returns the
2703
current date if the item can already be renewed.
2704
2705
=cut
2706
2707
sub GetSoonestRenewDate {
2708
    my ( $borrowernumber, $itemnumber ) = @_;
2709
2710
    my $dbh = C4::Context->dbh;
2711
2712
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2713
    my $itemissue = GetItemIssue($itemnumber) or return ( 0, 'no_checkout' );
2714
2715
    $borrowernumber ||= $itemissue->{borrowernumber};
2716
    my $borrower = C4::Members::GetMemberDetails($borrowernumber)
2717
      or return;
2718
2719
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2720
    my $issuingrule =
2721
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
2722
2723
    my $now = DateTime->now( time_zone => C4::Context->tz() );
2724
2725
    if ( $issuingrule->{norenewalbefore} ) {
2726
        my $soonestrenewal =
2727
          $itemissue->{date_due}->subtract(
2728
            $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} );
2729
2730
        $soonestrenewal = $now > $soonestrenewal ? $now : $soonestrenewal;
2731
        return $soonestrenewal;
2732
    }
2733
    return $now;
2734
}
2735
2671
=head2 GetIssuingCharges
2736
=head2 GetIssuingCharges
2672
2737
2673
  ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
2738
  ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
(-)a/circ/circulation.pl (+6 lines)
Lines 514-519 sub build_issue_data { Link Here
514
            (!$relatives) ? push @previousissues, $it : push @relprevissues, $it;
514
            (!$relatives) ? push @previousissues, $it : push @relprevissues, $it;
515
        }
515
        }
516
        ($it->{'renewcount'},$it->{'renewsallowed'},$it->{'renewsleft'}) = C4::Circulation::GetRenewCount($it->{'borrowernumber'},$it->{'itemnumber'}); #Add renewal count to item data display
516
        ($it->{'renewcount'},$it->{'renewsallowed'},$it->{'renewsleft'}) = C4::Circulation::GetRenewCount($it->{'borrowernumber'},$it->{'itemnumber'}); #Add renewal count to item data display
517
518
        $it->{'soonestrenewdate'} = output_pref(
519
            C4::Circulation::GetSoonestRenewDate(
520
                $it->{borrowernumber}, $it->{itemnumber}
521
            )
522
        );
517
    }
523
    }
518
}
524
}
519
525
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-14 / +18 lines)
Lines 779-795 No patron matched <span class="ex">[% message %]</span> Link Here
779
                    <input type="checkbox" class="radio" name="items[]" value="[% todayissue.itemnumber %]" />
779
                    <input type="checkbox" class="radio" name="items[]" value="[% todayissue.itemnumber %]" />
780
                [% END %]
780
                [% END %]
781
                </span>
781
                </span>
782
                [% IF todayissue.renewsallowed && todayissue.renewsleft %]
782
                [% IF todayissue.renewsallowed && todayissue.renewsleft && !todayissue.renew_error_too_soon %]
783
                    <span class="renewals">([% todayissue.renewsleft %] of [% todayissue.renewsallowed %] renewals remaining)</span>
783
                    <span class="renewals">([% todayissue.renewsleft %] of [% todayissue.renewsallowed %] renewals remaining)</span>
784
                [% END %]
784
                [% END %]
785
                <span class="renewals-disabled">
785
                <span class="renewals-disabled">
786
            [% END %]
786
            [% END %]
787
		[% IF ( todayissue.renew_error_on_reserve ) %]
787
            [% IF ( todayissue.renew_error_on_reserve ) %]
788
            <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% todayissue.biblionumber %]">On hold</a>
788
                <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% todayissue.biblionumber %]">On hold</a>
789
		[% END %]
789
            [% ELSIF ( todayissue.renew_error_too_many ) %]
790
                [% IF ( todayissue.renew_error_too_many ) %]
790
                Not renewable
791
            Not renewable
791
            [% ELSIF ( todayissue.renew_error_too_soon ) %]
792
                [% END %]
792
                No renewal before [% todayissue.soonestrenewdate %]
793
                <span class="renewals">([% todayissue.renewsleft %] of [% todayissue.renewsallowed %] renewals remaining)</span>
794
            [% END %]
793
            [% IF ( todayissue.can_confirm ) %]
795
            [% IF ( todayissue.can_confirm ) %]
794
                </span>
796
                </span>
795
            [% END %]
797
            [% END %]
Lines 874-890 No patron matched <span class="ex">[% message %]</span> Link Here
874
                    <input type="checkbox" class="radio" name="items[]" value="[% previssue.itemnumber %]" />
876
                    <input type="checkbox" class="radio" name="items[]" value="[% previssue.itemnumber %]" />
875
                [% END %]
877
                [% END %]
876
                </span>
878
                </span>
877
                [% IF previssue.renewsallowed && previssue.renewsleft %]
879
                [% IF previssue.renewsallowed && previssue.renewsleft && !previssue.renew_error_too_soon %]
878
                    <span class="renewals">([% previssue.renewsleft %] of [% previssue.renewsallowed %] renewals remaining)</span>
880
                    <span class="renewals">([% previssue.renewsleft %] of [% previssue.renewsallowed %] renewals remaining)</span>
879
                [% END %]
881
                [% END %]
880
                <span class="renewals-disabled">
882
                <span class="renewals-disabled">
881
            [% END %]
883
            [% END %]
882
		[% IF ( previssue.renew_error_on_reserve ) %]
884
            [% IF ( previssue.renew_error_on_reserve ) %]
883
            <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% previssue.biblionumber %]">On hold</a>
885
                <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% previssue.biblionumber %]">On Hold</a>
884
		[% END %]
886
            [% ELSIF ( previssue.renew_error_too_many ) %]
885
                [% IF ( previssue.renew_error_too_many ) %]
887
                Not renewable
886
            Not renewable
888
            [% ELSIF ( previssue.renew_error_too_soon ) %]
887
                [% END %]
889
                No renewal before [% previssue.soonestrenewdate %]
890
                <span class="renewals">([% previssue.renewsleft %] of [% previssue.renewsallowed %] renewals remaining)</span>
891
            [% END %]
888
            [% IF ( previssue.can_confirm ) %]
892
            [% IF ( previssue.can_confirm ) %]
889
                </span>
893
                </span>
890
            [% END %]
894
            [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-5 / +7 lines)
Lines 497-513 function validate1(date) { Link Here
497
                        <input type="checkbox" name="items[]" value="[% issueloo.itemnumber %]" />
497
                        <input type="checkbox" name="items[]" value="[% issueloo.itemnumber %]" />
498
                    [% END %]
498
                    [% END %]
499
                    </span>
499
                    </span>
500
                    [% IF issueloo.renewsallowed && issueloo.renewsleft %]
500
                    [% IF issueloo.renewsallowed && issueloo.renewsleft && !issueloo.norenew_reason_too_soon %]
501
                        <span class="renewals">([% issueloo.renewsleft %] of [% issueloo.renewsallowed %] renewals remaining)</span>
501
                        <span class="renewals">([% issueloo.renewsleft %] of [% issueloo.renewsallowed %] renewals remaining)</span>
502
                    [% END %]
502
                    [% END %]
503
                    <span class="renewals-disabled">
503
                    <span class="renewals-disabled">
504
                [% END %]
504
                [% END %]
505
                [% IF ( issueloo.norenew_reason_on_reserve ) %]
505
                [% IF ( issueloo.norenew_reason_on_reserve ) %]
506
                <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% issueloo.biblionumber %]">On Hold</a>
506
                    <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% issueloo.biblionumber %]">On Hold</a>
507
                [% ELSIF ( issueloo.norenew_reason_too_many ) %]
508
                    Not renewable
509
                [% ELSIF ( issueloo.norenew_reason_too_soon ) %]
510
                    No renewal before [% issueloo.soonestrenewdate %]
511
                    <span class="renewals">([% issueloo.renewsleft %] of [% issueloo.renewsallowed %] renewals remaining)</span>
507
                [% END %]
512
                [% END %]
508
                    [% IF ( issueloo.norenew_reason_too_many ) %]
509
                        Not renewable
510
                    [% END %]
511
                [% IF ( issueloo.can_confirm ) %]
513
                [% IF ( issueloo.can_confirm ) %]
512
                    </span>
514
                    </span>
513
                [% END %]
515
                [% END %]
(-)a/members/moremember.pl (-1 / +8 lines)
Lines 521-526 sub build_issue_data { Link Here
521
        $row{renew_failed}  = $renew_failed{ $issue->{itemnumber} };
521
        $row{renew_failed}  = $renew_failed{ $issue->{itemnumber} };
522
        $row{return_failed} = $return_failed{ $issue->{barcode} };
522
        $row{return_failed} = $return_failed{ $issue->{barcode} };
523
        ($row{'renewcount'},$row{'renewsallowed'},$row{'renewsleft'}) = C4::Circulation::GetRenewCount($issue->{'borrowernumber'},$issue->{'itemnumber'}); #Add renewal count to item data display
523
        ($row{'renewcount'},$row{'renewsallowed'},$row{'renewsleft'}) = C4::Circulation::GetRenewCount($issue->{'borrowernumber'},$issue->{'itemnumber'}); #Add renewal count to item data display
524
525
        $row{'soonestrenewdate'} = output_pref(
526
            C4::Circulation::GetSoonestRenewDate(
527
                $issue->{borrowernumber},
528
                $issue->{itemnumber}
529
            )
530
        );
531
524
        push( @{$localissue}, \%row );
532
        push( @{$localissue}, \%row );
525
    }
533
    }
526
    return $localissue;
534
    return $localissue;
527
- 

Return to bug 7413