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

(-)a/Koha/Patron.pm (+19 lines)
Lines 282-287 sub is_expired { Link Here
282
    return 0;
282
    return 0;
283
}
283
}
284
284
285
=head2 is_going_to_expired
286
287
my $is_going_to_expired = $patron->is_going_to_expired;
288
289
Returns 1 if the patron is going to expired, depending on the NotifyBorrowerDeparture pref or 0
290
291
=cut
292
293
sub is_going_to_expired {
294
    my ($self) = @_;
295
296
    my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0;
297
298
    return 0 unless $self->dateexpiry;
299
    return 0 if $self->dateexpiry eq '0000-00-00';
300
    return 1 if dt_from_string( $self->dateexpiry )->add( days => $delay ) < dt_from_string;
301
    return 0;
302
}
303
285
=head2 update_password
304
=head2 update_password
286
305
287
my $updated = $patron->update_password( $userid, $password );
306
my $updated = $patron->update_password( $userid, $password );
(-)a/circ/circulation.pl (-4 / +1 lines)
Lines 278-287 if ($borrowernumber) { Link Here
278
        );
278
        );
279
    }
279
    }
280
    # check for NotifyBorrowerDeparture
280
    # check for NotifyBorrowerDeparture
281
    elsif ( C4::Context->preference('NotifyBorrowerDeparture') &&
281
    elsif ( $patron->is_going_to_expired ) {
282
            Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
283
            Date_to_Days( $today_year, $today_month, $today_day ) ) 
284
    {
285
        # borrower card soon to expire warn librarian
282
        # borrower card soon to expire warn librarian
286
        $template->param( "warndeparture" => $borrower->{dateexpiry} ,
283
        $template->param( "warndeparture" => $borrower->{dateexpiry} ,
287
                        );
284
                        );
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +38 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 14;
22
use Test::More tests => 15;
23
use Test::Warn;
23
use Test::Warn;
24
use DateTime;
24
use DateTime;
25
25
Lines 187-192 subtest 'is_expired' => sub { Link Here
187
    $patron->delete;
187
    $patron->delete;
188
};
188
};
189
189
190
subtest 'is_going_to_expired' => sub {
191
    plan tests => 8;
192
    my $patron = $builder->build({ source => 'Borrower' });
193
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
194
    $patron->dateexpiry( undef )->store;
195
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
196
    $patron->dateexpiry( '0000-00-00' )->store;
197
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
198
    $patron->dateexpiry( dt_from_string )->store;
199
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today');
200
201
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
202
    my $dt_from_string = dt_from_string;
203
    $patron->dateexpiry( $dt_from_string )->store;
204
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
205
206
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
207
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
208
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days before and pref is 10');
209
210
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
211
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
212
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days before and pref is 0');
213
214
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
215
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
216
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days before and pref is 10');
217
    $patron->delete;
218
219
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
220
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
221
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days before and pref is 10');
222
223
    $patron->delete;
224
};
225
226
190
subtest 'renew_account' => sub {
227
subtest 'renew_account' => sub {
191
    plan tests => 10;
228
    plan tests => 10;
192
    my $a_month_ago                = dt_from_string->add( months => -1 )->truncate( to => 'day' );
229
    my $a_month_ago                = dt_from_string->add( months => -1 )->truncate( to => 'day' );
193
- 

Return to bug 17583