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

(-)a/C4/Circulation.pm (+50 lines)
Lines 85-90 BEGIN { Link Here
85
		&AddRenewal
85
		&AddRenewal
86
		&GetRenewCount
86
		&GetRenewCount
87
        &GetSoonestRenewDate
87
        &GetSoonestRenewDate
88
        &GetLatestAutoRenewDate
88
		&GetItemIssue
89
		&GetItemIssue
89
		&GetItemIssues
90
		&GetItemIssues
90
		&GetIssuingCharges
91
		&GetIssuingCharges
Lines 3097-3102 sub GetSoonestRenewDate { Link Here
3097
    return $now;
3098
    return $now;
3098
}
3099
}
3099
3100
3101
=head2 GetLatestAutoRenewDate
3102
3103
  $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate($borrowernumber, $itemnumber);
3104
3105
Find out the latest possible auto renew date of a borrowed item.
3106
3107
C<$borrowernumber> is the borrower number of the patron who currently
3108
has the item on loan.
3109
3110
C<$itemnumber> is the number of the item to renew.
3111
3112
C<$GetLatestAutoRenewDate> returns the DateTime of the latest possible
3113
auto renew date, based on the value "No auto renewal after" of the applicable
3114
issuing rule.
3115
Returns undef if there is no date specify in the circ rules or if the patron, loan,
3116
or item cannot be found.
3117
3118
=cut
3119
3120
sub GetLatestAutoRenewDate {
3121
    my ( $borrowernumber, $itemnumber ) = @_;
3122
3123
    my $dbh = C4::Context->dbh;
3124
3125
    my $item      = GetItem($itemnumber)      or return;
3126
    my $itemissue = GetItemIssue($itemnumber) or return;
3127
3128
    $borrowernumber ||= $itemissue->{borrowernumber};
3129
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
3130
      or return;
3131
3132
    my $branchcode = _GetCircControlBranch( $item, $borrower );
3133
    my $issuingrule =
3134
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
3135
3136
    my $now = dt_from_string;
3137
3138
    return if not $issuingrule->{no_auto_renewal_after}
3139
               or $issuingrule->{no_auto_renewal_after} eq '';
3140
3141
    my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
3142
    $maximum_renewal_date->add(
3143
        $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
3144
    );
3145
3146
    return $maximum_renewal_date;
3147
}
3148
3149
3100
=head2 GetIssuingCharges
3150
=head2 GetIssuingCharges
3101
3151
3102
  ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
3152
  ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
(-)a/circ/renew.pl (-1 / +8 lines)
Lines 47-53 my $override_holds = $cgi->param('override_holds'); Link Here
47
47
48
my ( $item, $issue, $borrower );
48
my ( $item, $issue, $borrower );
49
my $error = q{};
49
my $error = q{};
50
my $soonest_renew_date;
50
my ( $soonest_renew_date, $latest_auto_renew_date );
51
51
52
if ($barcode) {
52
if ($barcode) {
53
    $item = $schema->resultset("Item")->single( { barcode => $barcode } );
53
    $item = $schema->resultset("Item")->single( { barcode => $barcode } );
Lines 82-87 if ($barcode) { Link Here
82
                        $item->itemnumber(),
82
                        $item->itemnumber(),
83
                    );
83
                    );
84
                }
84
                }
85
                if ( $error && ( $error eq 'auto_too_late' ) ) {
86
                    $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
87
                        $borrower->borrowernumber(),
88
                        $item->itemnumber(),
89
                    );
90
                }
85
                if ($can_renew) {
91
                if ($can_renew) {
86
                    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
92
                    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
87
                    my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode );
93
                    my $date_due = AddRenewal( undef, $item->itemnumber(), $branchcode );
Lines 106-111 if ($barcode) { Link Here
106
        borrower => $borrower,
112
        borrower => $borrower,
107
        error    => $error,
113
        error    => $error,
108
        soonestrenewdate => $soonest_renew_date,
114
        soonestrenewdate => $soonest_renew_date,
115
        latestautorenewdate => $latest_auto_renew_date,
109
    );
116
    );
110
}
117
}
111
118
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt (-1 / +1 lines)
Lines 79-85 Link Here
79
79
80
                            [% ELSIF error == "auto_too_late" %]
80
                            [% ELSIF error == "auto_too_late" %]
81
81
82
                                <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal and cannot be renewed since [% latestrenewdate | $KohaDates %]. </p>
82
                                <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal and cannot be renewed anymore since [% latestautorenewdate | $KohaDates %]. </p>
83
83
84
                                [% IF Koha.Preference('AllowRenewalLimitOverride') %]
84
                                [% IF Koha.Preference('AllowRenewalLimitOverride') %]
85
                                    <form method="post" action="/cgi-bin/koha/circ/renew.pl">
85
                                    <form method="post" action="/cgi-bin/koha/circ/renew.pl">
(-)a/t/db_dependent/Circulation.t (-2 / +35 lines)
Lines 29-35 use Koha::Database; Link Here
29
29
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
32
use Test::More tests => 83;
32
use Test::More tests => 84;
33
33
34
BEGIN {
34
BEGIN {
35
    use_ok('C4::Circulation');
35
    use_ok('C4::Circulation');
Lines 555-560 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
555
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
555
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
556
    };
556
    };
557
557
558
    subtest "GetLatestAutoRenewDate" => sub {
559
        plan tests => 3;
560
        my $item_to_auto_renew = $builder->build(
561
            {   source => 'Item',
562
                value  => {
563
                    biblionumber  => $biblionumber,
564
                    homebranch    => $branch,
565
                    holdingbranch => $branch,
566
                }
567
            }
568
        );
569
570
        my $ten_days_before = dt_from_string->add( days => -10 );
571
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
572
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
573
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""');
574
        my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
575
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' );
576
        my $five_days_before = dt_from_string->add( days => -5 );
577
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5');
578
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
579
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
580
            $five_days_before->truncate( to => 'minute' ),
581
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
582
        );
583
        my $five_days_ahead = dt_from_string->add( days => 5 );
584
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15');
585
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
586
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
587
            $five_days_ahead->truncate( to => 'minute' ),
588
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
589
        );
590
    };
591
558
    # Too many renewals
592
    # Too many renewals
559
593
560
    # set policy to forbid renewals
594
    # set policy to forbid renewals
561
- 

Return to bug 15581