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

(-)a/Koha/Account/Lines.pm (+1 lines)
Lines 23-28 use Koha::Database; Link Here
23
use Koha::Account::Line;
23
use Koha::Account::Line;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects);
26
use List::MoreUtils qw( uniq );
26
27
27
=head1 NAME
28
=head1 NAME
28
29
(-)a/Koha/Patrons.pm (+23 lines)
Lines 436-441 sub update_category_to { Link Here
436
    return $counter;
436
    return $counter;
437
}
437
}
438
438
439
=head3
440
441
    my $patrons_with_fines = Koha::Patrons->search({ ... })->search_patrons_with_unpaid_fines();
442
443
Returns unique borrowernumbers of all patrons with unpaid fines. 
444
445
=cut
446
447
sub search_patrons_with_unpaid_fines {
448
    my ( $self ) = @_;
449
    my @patrons_with_fines;
450
    while ( my $patron = $self->next ) {
451
        my $account_balance = $patron->account()->balance;
452
        if($account_balance > 0){
453
            push @patrons_with_fines, { 
454
                borrowernumber => $patron->borrowernumber, 
455
                accountbalance => $account_balance 
456
            }    
457
        }
458
    }
459
    return \@patrons_with_fines;
460
}
461
439
=head3 _type
462
=head3 _type
440
463
441
=cut
464
=cut
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +35 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 40;
22
use Test::More tests => 41;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 1977-1980 subtest 'anonymize' => sub { Link Here
1977
    $patron2->discard_changes; # refresh
1977
    $patron2->discard_changes; # refresh
1978
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
1978
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
1979
};
1979
};
1980
1980
$schema->storage->txn_rollback;
1981
$schema->storage->txn_rollback;
1981
- 
1982
1983
subtest 'search_patrons_with_unpaid_fines() tests' => sub {
1984
    
1985
    plan tests => 7;
1986
1987
    $schema->storage->txn_begin;
1988
    
1989
    my $patrons_with_fines = Koha::Patrons->search({ branchcode => $library->{branchcode} })->search_patrons_with_unpaid_fines();
1990
    is( scalar( @$patrons_with_fines ), 0, 'search_patrons_with_unpaid_fines() should return empty array' );
1991
1992
    my $library = $builder->build({source => 'Branch' });
1993
1994
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->{branchcode} }});
1995
    my $account1 = $patron1->account;
1996
    $account1->add_debit({ amount => 10, interface => 'commandline', type => 'OVERDUE' });
1997
1998
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->{branchcode} }});
1999
    my $account2 = $patron2->account;
2000
    $account2->add_debit({ amount => 10, interface => 'commandline', type => 'OVERDUE' });
2001
2002
    $patrons_with_fines = Koha::Patrons->search({ branchcode => $library->{branchcode} })->search_patrons_with_unpaid_fines();
2003
    is( scalar( @$patrons_with_fines ), 2, 'search_patrons_with_unpaid_fines() should return array with 2 values' ); 
2004
    is( $patrons_with_fines->[0]->{ borrowernumber }, $patron1->borrowernumber, 'patron1 should be in array');
2005
    is( $patrons_with_fines->[1]->{ borrowernumber }, $patron2->borrowernumber, 'patron2 should be in array');
2006
    is( $patrons_with_fines->[0]->{ accountbalance }, $account1->balance, 'patron1 fines are correct');
2007
    is( $patrons_with_fines->[1]->{ accountbalance }, $account2->balance, 'patron2 fines are correct');
2008
2009
    $account2->add_credit({ amount => 10, interface => 'commandline' });
2010
    $patrons_with_fines = Koha::Patrons->search({ branchcode => $library->{branchcode} })->search_patrons_with_unpaid_fines();
2011
    is( scalar( @$patrons_with_fines ), 1, 'Patron without fines is not in array');
2012
    
2013
    $schema->storage->txn_rollback;
2014
};

Return to bug 15156