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

(-)a/C4/Circulation.pm (-4 / +5 lines)
Lines 2243-2249 sub AddReturn { Link Here
2243
    if ( $borrowernumber
2243
    if ( $borrowernumber
2244
      && $borrower->{'debarred'}
2244
      && $borrower->{'debarred'}
2245
      && C4::Context->preference('AutoRemoveOverduesRestrictions')
2245
      && C4::Context->preference('AutoRemoveOverduesRestrictions')
2246
      && !C4::Members::HasOverdues( $borrowernumber )
2246
      && !Koha::Patrons->find( $borrowernumber )->has_overdues
2247
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2247
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2248
    ) {
2248
    ) {
2249
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2249
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
Lines 2976-2983 sub CanBookBeRenewed { Link Here
2976
2976
2977
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2977
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2978
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2978
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2979
    my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred;
2979
    my $patron      = Koha::Patrons->find($borrowernumber);
2980
    my $hasoverdues = C4::Members::HasOverdues($borrowernumber);
2980
    my $restricted  = $patron->is_debarred;
2981
    my $hasoverdues = $patron->has_overdues;
2981
2982
2982
    if ( $restricted and $restrictionblockrenewing ) {
2983
    if ( $restricted and $restrictionblockrenewing ) {
2983
        return ( 0, 'restriction');
2984
        return ( 0, 'restriction');
Lines 3145-3151 sub AddRenewal { Link Here
3145
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
3146
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
3146
    if ( $borrowernumber
3147
    if ( $borrowernumber
3147
      && $borrower->{'debarred'}
3148
      && $borrower->{'debarred'}
3148
      && !C4::Members::HasOverdues( $borrowernumber )
3149
      && !Koha::Patrons->find( $borrowernumber )->has_overdues
3149
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
3150
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
3150
    ) {
3151
    ) {
3151
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
3152
        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 2060-2080 sub AddEnrolmentFeeIfNeeded { Link Here
2060
    }
2059
    }
2061
}
2060
}
2062
2061
2063
=head2 HasOverdues
2064
2065
=cut
2066
2067
sub HasOverdues {
2068
    my ( $borrowernumber ) = @_;
2069
2070
    my $sql = "SELECT COUNT(*) FROM issues WHERE date_due < NOW() AND borrowernumber = ?";
2071
    my $sth = C4::Context->dbh->prepare( $sql );
2072
    $sth->execute( $borrowernumber );
2073
    my ( $count ) = $sth->fetchrow_array();
2074
2075
    return $count;
2076
}
2077
2078
=head2 DeleteExpiredOpacRegistrations
2062
=head2 DeleteExpiredOpacRegistrations
2079
2063
2080
    Delete accounts that haven't been upgraded from the 'temporary' category
2064
    Delete accounts that haven't been upgraded from the 'temporary' category
(-)a/Koha/Patron.pm (+14 lines)
Lines 208-213 sub update_password { Link Here
208
    return 1;
208
    return 1;
209
}
209
}
210
210
211
=head2 has_overdues
212
213
my $has_overdues = $patron->has_overdues;
214
215
Returns the number of patron's overdues
216
217
=cut
218
219
sub has_overdues {
220
    my ($self) = @_;
221
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
222
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
223
}
224
211
=head3 type
225
=head3 type
212
226
213
=cut
227
=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( $borrowernumber )->has_overdues;
58
}
58
}
59
59
60
60
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +35 lines)
Lines 19-27 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 7;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use C4::Circulation;
25
use Koha::Patron;
26
use Koha::Patron;
26
use Koha::Patrons;
27
use Koha::Patrons;
27
use Koha::Database;
28
use Koha::Database;
Lines 55-60 my $new_patron_2 = Koha::Patron->new( Link Here
55
    }
56
    }
56
)->store;
57
)->store;
57
58
59
C4::Context->_new_userenv('xxx');
60
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', '');
61
58
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' );
62
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' );
59
63
60
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
64
my $retrieved_patron_1 = Koha::Patrons->find( $new_patron_1->borrowernumber );
Lines 102-107 subtest 'siblings' => sub { Link Here
102
    $retrieved_guarantee_1->delete;
106
    $retrieved_guarantee_1->delete;
103
};
107
};
104
108
109
subtest 'has_overdues' => sub {
110
    plan tests => 3;
111
112
    my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } );
113
    my $item_1 = $builder->build(
114
        {   source => 'Item',
115
            value  => {
116
                homebranch    => $library->{branchcode},
117
                holdingbranch => $library->{branchcode},
118
                notforloan    => 0,
119
                itemlost      => 0,
120
                withdrawn     => 0,
121
                biblionumber  => $biblioitem_1->{biblionumber}
122
            }
123
        }
124
    );
125
    my $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
126
    is( $retrieved_patron->has_overdues, 0, );
127
128
    my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 );
129
    my $issue = AddIssue( $new_patron_1->unblessed, $item_1->{barcode} );
130
    is( $retrieved_patron->has_overdues, 0, );
131
    AddReturn( $item_1->{barcode} );
132
    my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 );
133
    $issue = AddIssue( $new_patron_1->unblessed, $item_1->{barcode}, $yesterday );
134
    $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber );
135
    is( $retrieved_patron->has_overdues, 1, );
136
    AddReturn( $item_1->{barcode} );
137
};
138
105
subtest 'update_password' => sub {
139
subtest 'update_password' => sub {
106
    plan tests => 7;
140
    plan tests => 7;
107
141
108
- 

Return to bug 16851