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

(-)a/C4/Circulation.pm (+50 lines)
Lines 88-93 BEGIN { Link Here
88
		&AddRenewal
88
		&AddRenewal
89
		&GetRenewCount
89
		&GetRenewCount
90
        &GetSoonestRenewDate
90
        &GetSoonestRenewDate
91
        &GetLatestAutoRenewDate
91
		&GetItemIssue
92
		&GetItemIssue
92
		&GetItemIssues
93
		&GetItemIssues
93
		&GetIssuingCharges
94
		&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 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 => 87;
32
use Test::More tests => 88;
33
33
34
BEGIN {
34
BEGIN {
35
    use_ok('C4::Circulation');
35
    use_ok('C4::Circulation');
Lines 591-596 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
591
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
591
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
592
    };
592
    };
593
593
594
    subtest "GetLatestAutoRenewDate" => sub {
595
        plan tests => 3;
596
        my $item_to_auto_renew = $builder->build(
597
            {   source => 'Item',
598
                value  => {
599
                    biblionumber  => $biblionumber,
600
                    homebranch    => $branch,
601
                    holdingbranch => $branch,
602
                }
603
            }
604
        );
605
606
        my $ten_days_before = dt_from_string->add( days => -10 );
607
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
608
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
609
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = ""');
610
        my $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
611
        is( $latest_auto_renew_date, undef, 'GetLatestAutoRenewDate should return undef if no_auto_renewal_after is not defined' );
612
        my $five_days_before = dt_from_string->add( days => -5 );
613
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 5');
614
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
615
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
616
            $five_days_before->truncate( to => 'minute' ),
617
            'GetLatestAutoRenewDate should return -5 days if no_auto_renewal_after = 5 and date_due is 10 days before'
618
        );
619
        my $five_days_ahead = dt_from_string->add( days => 5 );
620
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 15');
621
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
622
        is( $latest_auto_renew_date->truncate( to => 'minute' ),
623
            $five_days_ahead->truncate( to => 'minute' ),
624
            'GetLatestAutoRenewDate should return +5 days if no_auto_renewal_after = 15 and date_due is 10 days before'
625
        );
626
    };
627
594
    # Too many renewals
628
    # Too many renewals
595
629
596
    # set policy to forbid renewals
630
    # set policy to forbid renewals
597
- 

Return to bug 15581