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

(-)a/C4/Circulation.pm (-4 / +5 lines)
Lines 2089-2095 sub AddReturn { Link Here
2089
    if ( $borrowernumber
2089
    if ( $borrowernumber
2090
      && $borrower->{'debarred'}
2090
      && $borrower->{'debarred'}
2091
      && C4::Context->preference('AutoRemoveOverduesRestrictions')
2091
      && C4::Context->preference('AutoRemoveOverduesRestrictions')
2092
      && !C4::Members::HasOverdues( $borrowernumber )
2092
      && !Koha::Patrons->find( $borrowernumber )->has_overdues
2093
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2093
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2094
    ) {
2094
    ) {
2095
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2095
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
Lines 2822-2829 sub CanBookBeRenewed { Link Here
2822
2822
2823
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2823
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2824
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2824
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2825
    my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred;
2825
    my $patron      = Koha::Patrons->find($borrowernumber);
2826
    my $hasoverdues = C4::Members::HasOverdues($borrowernumber);
2826
    my $restricted  = $patron->is_debarred;
2827
    my $hasoverdues = $patron->has_overdues;
2827
2828
2828
    if ( $restricted and $restrictionblockrenewing ) {
2829
    if ( $restricted and $restrictionblockrenewing ) {
2829
        return ( 0, 'restriction');
2830
        return ( 0, 'restriction');
Lines 2996-3002 sub AddRenewal { Link Here
2996
    $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
2997
    $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
2997
    if ( $borrowernumber
2998
    if ( $borrowernumber
2998
      && $borrower->{'debarred'}
2999
      && $borrower->{'debarred'}
2999
      && !C4::Members::HasOverdues( $borrowernumber )
3000
      && !Koha::Patrons->find( $borrowernumber )->has_overdues
3000
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
3001
      && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
3001
    ) {
3002
    ) {
3002
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
3003
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
(-)a/C4/Members.pm (-16 lines)
Lines 93-99 BEGIN { Link Here
93
        &IssueSlip
93
        &IssueSlip
94
        GetBorrowersWithEmail
94
        GetBorrowersWithEmail
95
95
96
        HasOverdues
97
        GetOverduesForPatron
96
        GetOverduesForPatron
98
    );
97
    );
99
98
Lines 2039-2059 sub AddEnrolmentFeeIfNeeded { Link Here
2039
    }
2038
    }
2040
}
2039
}
2041
2040
2042
=head2 HasOverdues
2043
2044
=cut
2045
2046
sub HasOverdues {
2047
    my ( $borrowernumber ) = @_;
2048
2049
    my $sql = "SELECT COUNT(*) FROM issues WHERE date_due < NOW() AND borrowernumber = ?";
2050
    my $sth = C4::Context->dbh->prepare( $sql );
2051
    $sth->execute( $borrowernumber );
2052
    my ( $count ) = $sth->fetchrow_array();
2053
2054
    return $count;
2055
}
2056
2057
=head2 DeleteExpiredOpacRegistrations
2041
=head2 DeleteExpiredOpacRegistrations
2058
2042
2059
    Delete accounts that haven't been upgraded from the 'temporary' category
2043
    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