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

(-)a/Koha/Patron.pm (+19 lines)
Lines 295-300 sub is_expired { Link Here
295
    return 0;
295
    return 0;
296
}
296
}
297
297
298
=head2 is_going_to_expired
299
300
my $is_going_to_expired = $patron->is_going_to_expired;
301
302
Returns 1 if the patron is going to expired, depending on the NotifyBorrowerDeparture pref or 0
303
304
=cut
305
306
sub is_going_to_expired {
307
    my ($self) = @_;
308
309
    my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0;
310
311
    return 0 unless $self->dateexpiry;
312
    return 0 if $self->dateexpiry eq '0000-00-00';
313
    return 1 if dt_from_string( $self->dateexpiry )->add( days => $delay ) < dt_from_string;
314
    return 0;
315
}
316
298
=head2 update_password
317
=head2 update_password
299
318
300
my $updated = $patron->update_password( $userid, $password );
319
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 (-1 / +37 lines)
Lines 190-195 subtest 'is_expired' => sub { Link Here
190
    $patron->delete;
190
    $patron->delete;
191
};
191
};
192
192
193
subtest 'is_going_to_expired' => sub {
194
    plan tests => 8;
195
    my $patron = $builder->build({ source => 'Borrower' });
196
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
197
    $patron->dateexpiry( undef )->store;
198
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
199
    $patron->dateexpiry( '0000-00-00' )->store;
200
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
201
    $patron->dateexpiry( dt_from_string )->store;
202
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today');
203
204
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
205
    my $dt_from_string = dt_from_string;
206
    $patron->dateexpiry( $dt_from_string )->store;
207
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
208
209
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
210
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
211
    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');
212
213
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
214
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
215
    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');
216
217
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
218
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
219
    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');
220
    $patron->delete;
221
222
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
223
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
224
    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');
225
226
    $patron->delete;
227
};
228
229
193
subtest 'renew_account' => sub {
230
subtest 'renew_account' => sub {
194
    plan tests => 10;
231
    plan tests => 10;
195
    my $a_month_ago                = dt_from_string->add( months => -1 )->truncate( to => 'day' );
232
    my $a_month_ago                = dt_from_string->add( months => -1 )->truncate( to => 'day' );
196
- 

Return to bug 17583