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

(-)a/C4/Circulation.pm (+50 lines)
Lines 86-91 BEGIN { Link Here
86
		&AddRenewal
86
		&AddRenewal
87
		&GetRenewCount
87
		&GetRenewCount
88
        &GetSoonestRenewDate
88
        &GetSoonestRenewDate
89
        &GetLatestAutoRenewDate
89
		&GetItemIssue
90
		&GetItemIssue
90
		&GetItemIssues
91
		&GetItemIssues
91
		&GetIssuingCharges
92
		&GetIssuingCharges
Lines 3171-3176 sub GetSoonestRenewDate { Link Here
3171
    return $now;
3172
    return $now;
3172
}
3173
}
3173
3174
3175
=head2 GetLatestAutoRenewDate
3176
3177
  $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate($borrowernumber, $itemnumber);
3178
3179
Find out the latest possible auto renew date of a borrowed item.
3180
3181
C<$borrowernumber> is the borrower number of the patron who currently
3182
has the item on loan.
3183
3184
C<$itemnumber> is the number of the item to renew.
3185
3186
C<$GetLatestAutoRenewDate> returns the DateTime of the latest possible
3187
auto renew date, based on the value "No auto renewal after" of the applicable
3188
issuing rule.
3189
Returns undef if there is no date specify in the circ rules or if the patron, loan,
3190
or item cannot be found.
3191
3192
=cut
3193
3194
sub GetLatestAutoRenewDate {
3195
    my ( $borrowernumber, $itemnumber ) = @_;
3196
3197
    my $dbh = C4::Context->dbh;
3198
3199
    my $item      = GetItem($itemnumber)      or return;
3200
    my $itemissue = GetItemIssue($itemnumber) or return;
3201
3202
    $borrowernumber ||= $itemissue->{borrowernumber};
3203
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
3204
      or return;
3205
3206
    my $branchcode = _GetCircControlBranch( $item, $borrower );
3207
    my $issuingrule =
3208
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
3209
3210
    my $now = dt_from_string;
3211
3212
    return if not $issuingrule->{no_auto_renewal_after}
3213
               or $issuingrule->{no_auto_renewal_after} eq '';
3214
3215
    my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
3216
    $maximum_renewal_date->add(
3217
        $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
3218
    );
3219
3220
    return $maximum_renewal_date;
3221
}
3222
3223
3174
=head2 GetIssuingCharges
3224
=head2 GetIssuingCharges
3175
3225
3176
  ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
3226
  ($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 30-36 use Koha::Database; Link Here
30
30
31
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
32
32
33
use Test::More tests => 83;
33
use Test::More tests => 84;
34
34
35
BEGIN {
35
BEGIN {
36
    use_ok('C4::Circulation');
36
    use_ok('C4::Circulation');
Lines 573-578 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
573
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
573
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
574
    };
574
    };
575
575
576
    subtest "GetLatestAutoRenewDate" => sub {
577
        plan tests => 3;
578
        my $item_to_auto_renew = $builder->build(
579
            {   source => 'Item',
580
                value  => {
581
                    biblionumber  => $biblionumber,
582
                    homebranch    => $branch,
583
                    holdingbranch => $branch,
584
                }
585
            }
586
        );
587
588
        my $ten_days_before = dt_from_string->add( days => -10 );
589
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
590
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
591
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""');
592
        my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
593
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' );
594
        my $five_days_before = dt_from_string->add( days => -5 );
595
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5');
596
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
597
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
598
            $five_days_before->truncate( to => 'minute' ),
599
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
600
        );
601
        my $five_days_ahead = dt_from_string->add( days => 5 );
602
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15');
603
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
604
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
605
            $five_days_ahead->truncate( to => 'minute' ),
606
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
607
        );
608
    };
609
576
    # Too many renewals
610
    # Too many renewals
577
611
578
    # set policy to forbid renewals
612
    # set policy to forbid renewals
579
- 

Return to bug 15581