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

(-)a/C4/Circulation.pm (-9 / +2 lines)
Lines 736-751 sub CanBookBeIssued { Link Here
736
            $issuingimpossible{DEBARRED} = 1;
736
            $issuingimpossible{DEBARRED} = 1;
737
        }
737
        }
738
    }
738
    }
739
    if ( !defined $patron->dateexpiry || $patron->dateexpiry eq '0000-00-00') {
739
740
    if ( $patron->is_expired ) {
740
        $issuingimpossible{EXPIRED} = 1;
741
        $issuingimpossible{EXPIRED} = 1;
741
    } else {
742
        my $expiry_dt = dt_from_string( $patron->dateexpiry, 'sql', 'floating' );
743
        $expiry_dt->truncate( to => 'day');
744
        my $today = $now->clone()->truncate(to => 'day');
745
        $today->set_time_zone( 'floating' );
746
        if ( DateTime->compare($today, $expiry_dt) == 1 ) {
747
            $issuingimpossible{EXPIRED} = 1;
748
        }
749
    }
742
    }
750
743
751
    #
744
    #
(-)a/C4/Utils/DataTables/Members.pm (-1 / +2 lines)
Lines 184-190 sub search { Link Here
184
        # FIXME Should be formatted from the template
184
        # FIXME Should be formatted from the template
185
        $patron->{fines} = sprintf("%.2f", $balance);
185
        $patron->{fines} = sprintf("%.2f", $balance);
186
186
187
        if($patron->{dateexpiry} and $patron->{dateexpiry} ne '0000-00-00') {
187
        if( $patron->{dateexpiry} ) {
188
            # FIXME We should not format the date here, do it in template-side instead
188
            $patron->{dateexpiry} = output_pref( { dt => dt_from_string( $patron->{dateexpiry}, 'iso'), dateonly => 1} );
189
            $patron->{dateexpiry} = output_pref( { dt => dt_from_string( $patron->{dateexpiry}, 'iso'), dateonly => 1} );
189
        } else {
190
        } else {
190
            $patron->{dateexpiry} = '';
191
            $patron->{dateexpiry} = '';
(-)a/Koha/Patron.pm (-2 / +2 lines)
Lines 297-303 Returns 1 if the patron is expired or 0; Link Here
297
sub is_expired {
297
sub is_expired {
298
    my ($self) = @_;
298
    my ($self) = @_;
299
    return 0 unless $self->dateexpiry;
299
    return 0 unless $self->dateexpiry;
300
    return 0 if $self->dateexpiry eq '0000-00-00';
300
    return 0 if $self->dateexpiry =~ '^9999';
301
    return 1 if dt_from_string( $self->dateexpiry ) < dt_from_string->truncate( to => 'day' );
301
    return 1 if dt_from_string( $self->dateexpiry ) < dt_from_string->truncate( to => 'day' );
302
    return 0;
302
    return 0;
303
}
303
}
Lines 317-323 sub is_going_to_expire { Link Here
317
317
318
    return 0 unless $delay;
318
    return 0 unless $delay;
319
    return 0 unless $self->dateexpiry;
319
    return 0 unless $self->dateexpiry;
320
    return 0 if $self->dateexpiry eq '0000-00-00';
320
    return 0 if $self->dateexpiry =~ '^9999';
321
    return 1 if dt_from_string( $self->dateexpiry )->subtract( days => $delay ) < dt_from_string->truncate( to => 'day' );
321
    return 1 if dt_from_string( $self->dateexpiry )->subtract( days => $delay ) < dt_from_string->truncate( to => 'day' );
322
    return 0;
322
    return 0;
323
}
323
}
(-)a/t/db_dependent/Circulation/dateexpiry.t (-2 / +2 lines)
Lines 65-77 sub can_book_be_issued { Link Here
65
    $patron = $builder->build_object(
65
    $patron = $builder->build_object(
66
        {   class  => 'Koha::Patrons',
66
        {   class  => 'Koha::Patrons',
67
            value  => {
67
            value  => {
68
                dateexpiry => '0000-00-00',
68
                dateexpiry => undef,
69
                categorycode => $patron_category->{categorycode},
69
                categorycode => $patron_category->{categorycode},
70
            }
70
            }
71
        }
71
        }
72
    );
72
    );
73
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
73
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
74
    is( $issuingimpossible->{EXPIRED}, 1, 'The patron should be considered as expired if dateexpiry is 0000-00-00' );
74
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is not set' );
75
75
76
    my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
76
    my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
77
    $item = $builder->build( { source => 'Item' } );
77
    $item = $builder->build( { source => 'Item' } );
(-)a/t/db_dependent/Koha/Patrons.t (-7 / +2 lines)
Lines 186-198 subtest 'update_password' => sub { Link Here
186
};
186
};
187
187
188
subtest 'is_expired' => sub {
188
subtest 'is_expired' => sub {
189
    plan tests => 5;
189
    plan tests => 4;
190
    my $patron = $builder->build({ source => 'Borrower' });
190
    my $patron = $builder->build({ source => 'Borrower' });
191
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
191
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
192
    $patron->dateexpiry( undef )->store->discard_changes;
192
    $patron->dateexpiry( undef )->store->discard_changes;
193
    is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not set');
193
    is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not set');
194
    $patron->dateexpiry( '0000-00-00' );
195
    is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is 0000-00-00');
196
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
194
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
197
    is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is today');
195
    is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is today');
198
    $patron->dateexpiry( dt_from_string->add( days => 1 ) )->store->discard_changes;
196
    $patron->dateexpiry( dt_from_string->add( days => 1 ) )->store->discard_changes;
Lines 204-216 subtest 'is_expired' => sub { Link Here
204
};
202
};
205
203
206
subtest 'is_going_to_expire' => sub {
204
subtest 'is_going_to_expire' => sub {
207
    plan tests => 9;
205
    plan tests => 8;
208
    my $patron = $builder->build({ source => 'Borrower' });
206
    my $patron = $builder->build({ source => 'Borrower' });
209
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
207
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
210
    $patron->dateexpiry( undef )->store->discard_changes;
208
    $patron->dateexpiry( undef )->store->discard_changes;
211
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
209
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
212
    $patron->dateexpiry( '0000-00-00' );
213
    is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 0000-00-00');
214
210
215
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
211
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
216
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
212
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
217
- 

Return to bug 20145