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

(-)a/C4/Circulation.pm (-15 / +6 lines)
Lines 767-790 sub CanBookBeIssued { Link Here
767
    if ( !defined $borrower->{dateexpiry} || $borrower->{'dateexpiry'} eq '0000-00-00') {
767
    if ( !defined $borrower->{dateexpiry} || $borrower->{'dateexpiry'} eq '0000-00-00') {
768
        $issuingimpossible{EXPIRED} = 1;
768
        $issuingimpossible{EXPIRED} = 1;
769
    } else {
769
    } else {
770
        my ($y, $m, $d) =  split /-/,$borrower->{'dateexpiry'};
770
        my $expiry_dt = dt_from_string( $borrower->{dateexpiry}, 'sql' );
771
        if ($y && $m && $d) { # are we really writing oinvalid dates to borrs
771
        $expiry_dt->truncate( to => 'day');
772
            my $expiry_dt = DateTime->new(
772
        my $today = $now->clone()->truncate(to => 'day');
773
                year => $y,
773
774
                month => $m,
774
        if ($expiry_dt->year < 9999 && DateTime->compare($today, $expiry_dt) == 1) {
775
                day   => $d,
776
                time_zone => C4::Context->tz,
777
            );
778
            $expiry_dt->truncate( to => 'day');
779
            my $today = $now->clone()->truncate(to => 'day');
780
            if (DateTime->compare($today, $expiry_dt) == 1) {
781
                $issuingimpossible{EXPIRED} = 1;
782
            }
783
        } else {
784
            carp("Invalid expity date in borr");
785
            $issuingimpossible{EXPIRED} = 1;
775
            $issuingimpossible{EXPIRED} = 1;
786
        }
776
        }
787
    }
777
    }
778
788
    #
779
    #
789
    # BORROWER STATUS
780
    # BORROWER STATUS
790
    #
781
    #
(-)a/t/db_dependent/Circulation.t (-2 / +40 lines)
Lines 18-23 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use DateTime;
20
use DateTime;
21
use Time::HiRes qw( gettimeofday );
21
use C4::Biblio;
22
use C4::Biblio;
22
use C4::Branch;
23
use C4::Branch;
23
use C4::Items;
24
use C4::Items;
Lines 26-33 use C4::Reserves; Link Here
26
use C4::Overdues qw(UpdateFine);
27
use C4::Overdues qw(UpdateFine);
27
use Koha::DateUtils;
28
use Koha::DateUtils;
28
use Koha::Database;
29
use Koha::Database;
30
use t::lib::TestBuilder;
29
31
30
use Test::More tests => 61;
32
use Test::More tests => 65;
31
33
32
BEGIN {
34
BEGIN {
33
    use_ok('C4::Circulation');
35
    use_ok('C4::Circulation');
Lines 594-599 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
594
    is ( $count, 0, "Calling UpdateFine on non-existant fine with an amount of 0 does not result in an empty fine" );
596
    is ( $count, 0, "Calling UpdateFine on non-existant fine with an amount of 0 does not result in an empty fine" );
595
}
597
}
596
598
599
{
600
    my $builder = t::lib::TestBuilder->new();
601
    my $item    = $builder->build( { source => 'Item' } );
602
    my $patron  = $builder->build(
603
        {   source => 'Borrower',
604
            value  => { dateexpiry => '9999-12-31' }
605
        }
606
    );
607
    $patron->{flags} = C4::Members::patronflags($borrower);
608
    my $duration = gettimeofday();
609
    my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
610
    $duration = gettimeofday() - $duration;
611
    cmp_ok $duration, '<', 1, "CanBookBeIssued should not be take more than 1s if the patron is expired";
612
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is 9999-*' );
613
614
    $item = $builder->build( { source => 'Item' } );
615
    $patron = $builder->build(
616
        {   source => 'Borrower',
617
            value  => { dateexpiry => '0000-00-00' }
618
        }
619
    );
620
    $patron->{flags} = C4::Members::patronflags($borrower);
621
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
622
    is( $issuingimpossible->{EXPIRED}, 1, 'The patron should be considered as expired if dateexpiry is 0000-00-00' );
623
624
    my $tomorrow = dt_from_string->add_duration( DateTime::Duration->new( days => 1 ) );
625
    $item = $builder->build( { source => 'Item' } );
626
    $patron = $builder->build(
627
        {   source => 'Borrower',
628
            value  => { dateexpiry => output_pref( { dt => $tomorrow, dateonly => 1, dateformat => 'sql' } ) },
629
        }
630
    );
631
    $patron->{flags} = C4::Members::patronflags($borrower);
632
    ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $patron, $item->{barcode} );
633
    is( not( exists $issuingimpossible->{EXPIRED} ), 1, 'The patron should not be considered as expired if dateexpiry is tomorrow' );
634
}
635
597
$dbh->rollback;
636
$dbh->rollback;
598
637
599
1;
638
1;
600
- 

Return to bug 14494