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

(-)a/C4/Circulation.pm (-4 / +5 lines)
Lines 2211-2217 sub AddReturn { Link Here
2211
    if ( $borrowernumber
2211
    if ( $borrowernumber
2212
      && $borrower->{'debarred'}
2212
      && $borrower->{'debarred'}
2213
      && C4::Context->preference('AutoRemoveOverduesRestrictions')
2213
      && C4::Context->preference('AutoRemoveOverduesRestrictions')
2214
      && !C4::Members::HasOverdues( $borrowernumber )
2214
      && !Koha::Patrons->find( $borrowernumber )->has_overdues
2215
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2215
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2216
    ) {
2216
    ) {
2217
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2217
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
Lines 2944-2951 sub CanBookBeRenewed { Link Here
2944
2944
2945
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2945
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2946
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2946
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2947
    my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred;
2947
    my $patron      = Koha::Patrons->find($borrowernumber);
2948
    my $hasoverdues = C4::Members::HasOverdues($borrowernumber);
2948
    my $restricted  = $patron->is_debarred;
2949
    my $hasoverdues = $patron->has_overdues;
2949
2950
2950
    if ( $restricted and $restrictionblockrenewing ) {
2951
    if ( $restricted and $restrictionblockrenewing ) {
2951
        return ( 0, 'restriction');
2952
        return ( 0, 'restriction');
Lines 3113-3119 sub AddRenewal { Link Here
3113
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
3114
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
3114
    if ( $borrowernumber
3115
    if ( $borrowernumber
3115
      && $borrower->{'debarred'}
3116
      && $borrower->{'debarred'}
3116
      && !C4::Members::HasOverdues( $borrowernumber )
3117
      && !Koha::Patrons->find( $borrowernumber )->has_overdues
3117
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
3118
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
3118
    ) {
3119
    ) {
3119
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
3120
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
(-)a/C4/Members.pm (-16 lines)
Lines 94-100 BEGIN { Link Here
94
        &IssueSlip
94
        &IssueSlip
95
        GetBorrowersWithEmail
95
        GetBorrowersWithEmail
96
96
97
        HasOverdues
98
        GetOverduesForPatron
97
        GetOverduesForPatron
99
    );
98
    );
100
99
Lines 2211-2231 sub AddEnrolmentFeeIfNeeded { Link Here
2211
    }
2210
    }
2212
}
2211
}
2213
2212
2214
=head2 HasOverdues
2215
2216
=cut
2217
2218
sub HasOverdues {
2219
    my ( $borrowernumber ) = @_;
2220
2221
    my $sql = "SELECT COUNT(*) FROM issues WHERE date_due < NOW() AND borrowernumber = ?";
2222
    my $sth = C4::Context->dbh->prepare( $sql );
2223
    $sth->execute( $borrowernumber );
2224
    my ( $count ) = $sth->fetchrow_array();
2225
2226
    return $count;
2227
}
2228
2229
=head2 DeleteExpiredOpacRegistrations
2213
=head2 DeleteExpiredOpacRegistrations
2230
2214
2231
    Delete accounts that haven't been upgraded from the 'temporary' category
2215
    Delete accounts that haven't been upgraded from the 'temporary' category
(-)a/Koha/Patron.pm (+14 lines)
Lines 115-120 sub is_debarred { Link Here
115
    return;
115
    return;
116
}
116
}
117
117
118
=head2 has_overdues
119
120
my $has_overdues = $patron->has_overdues;
121
122
Returns the number of patron's overdues
123
124
=cut
125
126
sub has_overdues {
127
    my ($self) = @_;
128
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
129
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
130
}
131
118
=head3 type
132
=head3 type
119
133
120
=cut
134
=cut
(-)a/Koha/Template/Plugin/Borrowers.pm (-1 / +1 lines)
Lines 54-60 sub HasOverdues { Link Here
54
54
55
    return unless $borrowernumber;
55
    return unless $borrowernumber;
56
56
57
    return C4::Members::HasOverdues($borrowernumber);
57
    return Koha::Patrons->find( $borrower->{borrowernumber} )->has_overdues;
58
}
58
}
59
59
60
60
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +35 lines)
Lines 19-26 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
23
24
use C4::Circulation;
24
use Koha::Patron;
25
use Koha::Patron;
25
use Koha::Patrons;
26
use Koha::Patrons;
26
use Koha::Database;
27
use Koha::Database;
Lines 51-56 my $new_patron_2 = Koha::Patron->new( Link Here
51
    }
52
    }
52
)->store;
53
)->store;
53
54
55
C4::Context->_new_userenv('xxx');
56
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', '');
57
54
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' );
58
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' );
55
59
56
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
60
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
Lines 98-103 subtest 'siblings' => sub { Link Here
98
    $retrieved_guarantee_1->delete;
102
    $retrieved_guarantee_1->delete;
99
};
103
};
100
104
105
subtest 'has_overdues' => sub {
106
    plan tests => 3;
107
108
    my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
109
    my $item_1 = $builder->build(
110
        {   source => 'Item',
111
            value  => {
112
                homebranch    => $library->{branchcode},
113
                holdingbranch => $library->{branchcode},
114
                notforloan    => 0,
115
                itemlost      => 0,
116
                withdrawn     => 0,
117
                biblionumber  => $biblioitem_1->{biblionumber}
118
            }
119
        }
120
    );
121
    my $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
122
    is( $retrieved_patron->has_overdues, 0, );
123
124
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
125
    my $issue = AddIssue( $new_patron_1->unblessed, $item_1->{barcode} );
126
    is( $retrieved_patron->has_overdues, 0, );
127
    AddReturn( $item_1->{barcode} );
128
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
129
    $issue = AddIssue( $new_patron_1->unblessed, $item_1->{barcode}, $yesterday );
130
    $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
131
    is( $retrieved_patron->has_overdues, 1, );
132
    AddReturn( $item_1->{barcode} );
133
};
134
101
$retrieved_patron_1->delete;
135
$retrieved_patron_1->delete;
102
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
136
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
103
137
104
- 

Return to bug 16851