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

(-)a/Koha/Patron.pm (-4 / +4 lines)
Lines 295-309 sub is_expired { Link Here
295
    return 0;
295
    return 0;
296
}
296
}
297
297
298
=head2 is_going_to_expired
298
=head2 is_going_to_expire
299
299
300
my $is_going_to_expired = $patron->is_going_to_expired;
300
my $is_going_to_expire = $patron->is_going_to_expire;
301
301
302
Returns 1 if the patron is going to expired, depending on the NotifyBorrowerDeparture pref or 0
302
Returns 1 if the patron is going to expired, depending on the NotifyBorrowerDeparture pref or 0
303
303
304
=cut
304
=cut
305
305
306
sub is_going_to_expired {
306
sub is_going_to_expire {
307
    my ($self) = @_;
307
    my ($self) = @_;
308
308
309
    my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0;
309
    my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0;
Lines 311-317 sub is_going_to_expired { Link Here
311
    return 0 unless $delay;
311
    return 0 unless $delay;
312
    return 0 unless $self->dateexpiry;
312
    return 0 unless $self->dateexpiry;
313
    return 0 if $self->dateexpiry eq '0000-00-00';
313
    return 0 if $self->dateexpiry eq '0000-00-00';
314
    return 1 if dt_from_string( $self->dateexpiry )->add( days => -$delay ) < dt_from_string->truncate( to => 'day' );
314
    return 1 if dt_from_string( $self->dateexpiry )->subtract( days => $delay ) < dt_from_string->truncate( to => 'day' );
315
    return 0;
315
    return 0;
316
}
316
}
317
317
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 278-284 if ($borrowernumber) { Link Here
278
        );
278
        );
279
    }
279
    }
280
    # check for NotifyBorrowerDeparture
280
    # check for NotifyBorrowerDeparture
281
    elsif ( $patron->is_going_to_expired ) {
281
    elsif ( $patron->is_going_to_expire ) {
282
        # borrower card soon to expire warn librarian
282
        # borrower card soon to expire warn librarian
283
        $template->param( "warndeparture" => $borrower->{dateexpiry} ,
283
        $template->param( "warndeparture" => $borrower->{dateexpiry} ,
284
                        );
284
                        );
(-)a/t/db_dependent/Koha/Patrons.t (-12 / +11 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 13;
22
use Test::More tests => 14;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use C4::Members;
25
use C4::Members;
Lines 190-231 subtest 'is_expired' => sub { Link Here
190
    $patron->delete;
190
    $patron->delete;
191
};
191
};
192
192
193
subtest 'is_going_to_expired' => sub {
193
subtest 'is_going_to_expire' => sub {
194
    plan tests => 9;
194
    plan tests => 9;
195
    my $patron = $builder->build({ source => 'Borrower' });
195
    my $patron = $builder->build({ source => 'Borrower' });
196
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
196
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
197
    $patron->dateexpiry( undef )->store->discard_changes;
197
    $patron->dateexpiry( undef )->store->discard_changes;
198
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
198
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
199
    $patron->dateexpiry( '0000-00-00' )->store->discard_changes;
199
    $patron->dateexpiry( '0000-00-00' )->store->discard_changes;
200
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
200
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
201
201
202
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
202
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
203
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
203
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
204
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today');
204
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today');
205
205
206
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
206
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
207
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
207
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
208
208
209
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
209
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
210
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store->discard_changes;
210
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store->discard_changes;
211
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days ahead and pref is 10');
211
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days ahead and pref is 10');
212
212
213
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
213
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
214
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
214
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
215
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 0');
215
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 0');
216
216
217
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
217
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
218
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
218
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
219
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 10');
219
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 10');
220
    $patron->delete;
220
    $patron->delete;
221
221
222
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
222
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
223
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store->discard_changes;
223
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store->discard_changes;
224
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days ahead and pref is 10');
224
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days ahead and pref is 10');
225
225
226
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
226
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
227
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
227
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
228
    is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20');
228
    is( $patron->is_going_to_expire, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20');
229
229
230
    $patron->delete;
230
    $patron->delete;
231
};
231
};
232
- 

Return to bug 17583