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 3141-3146 sub GetSoonestRenewDate { Link Here
3141
    return $now;
3142
    return $now;
3142
}
3143
}
3143
3144
3145
=head2 GetLatestAutoRenewDate
3146
3147
  $NoAutoRenewalAfterThisDate = &GetLatestAutoRenewDate($borrowernumber, $itemnumber);
3148
3149
Find out the latest possible auto renew date of a borrowed item.
3150
3151
C<$borrowernumber> is the borrower number of the patron who currently
3152
has the item on loan.
3153
3154
C<$itemnumber> is the number of the item to renew.
3155
3156
C<$GetLatestAutoRenewDate> returns the DateTime of the latest possible
3157
auto renew date, based on the value "No auto renewal after" of the applicable
3158
issuing rule.
3159
Returns undef if there is no date specify in the circ rules or if the patron, loan,
3160
or item cannot be found.
3161
3162
=cut
3163
3164
sub GetLatestAutoRenewDate {
3165
    my ( $borrowernumber, $itemnumber ) = @_;
3166
3167
    my $dbh = C4::Context->dbh;
3168
3169
    my $item      = GetItem($itemnumber)      or return;
3170
    my $itemissue = GetItemIssue($itemnumber) or return;
3171
3172
    $borrowernumber ||= $itemissue->{borrowernumber};
3173
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
3174
      or return;
3175
3176
    my $branchcode = _GetCircControlBranch( $item, $borrower );
3177
    my $issuingrule =
3178
      GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
3179
3180
    my $now = dt_from_string;
3181
3182
    return if not $issuingrule->{no_auto_renewal_after}
3183
               or $issuingrule->{no_auto_renewal_after} eq '';
3184
3185
    my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
3186
    $maximum_renewal_date->add(
3187
        $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
3188
    );
3189
3190
    return $maximum_renewal_date;
3191
}
3192
3193
3144
=head2 GetIssuingCharges
3194
=head2 GetIssuingCharges
3145
3195
3146
  ($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);
3196
  ($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 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 88;
20
use Test::More tests => 89;
21
21
22
BEGIN {
22
BEGIN {
23
    require_ok('C4::Circulation');
23
    require_ok('C4::Circulation');
Lines 593-598 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
593
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
593
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
594
    };
594
    };
595
595
596
    subtest "GetLatestAutoRenewDate" => sub {
597
        plan tests => 3;
598
        my $item_to_auto_renew = $builder->build(
599
            {   source => 'Item',
600
                value  => {
601
                    biblionumber  => $biblionumber,
602
                    homebranch    => $branch,
603
                    holdingbranch => $branch,
604
                }
605
            }
606
        );
607
608
        my $ten_days_before = dt_from_string->add( days => -10 );
609
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
610
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
611
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""');
612
        my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
613
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' );
614
        my $five_days_before = dt_from_string->add( days => -5 );
615
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5');
616
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
617
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
618
            $five_days_before->truncate( to => 'minute' ),
619
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
620
        );
621
        my $five_days_ahead = dt_from_string->add( days => 5 );
622
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15');
623
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
624
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
625
            $five_days_ahead->truncate( to => 'minute' ),
626
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
627
        );
628
    };
629
596
    # Too many renewals
630
    # Too many renewals
597
631
598
    # set policy to forbid renewals
632
    # set policy to forbid renewals
599
- 

Return to bug 15581