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

(-)a/Koha/Account/Lines.pm (+20 lines)
Lines 36-41 Koha::Account::Lines - Koha Account Line Object set class Link Here
36
36
37
=cut
37
=cut
38
38
39
=head3 get_balance
40
41
my $balance = $self->get_balance
42
43
Return the balance (sum of amountoutstanding columns)
44
45
=cut
46
47
sub get_balance {
48
    my ($self) = @_;
49
    my $fines = $self->search(
50
        {},
51
        {
52
            select => [ { sum => 'amountoutstanding' } ],
53
            as => ['total_amountoutstanding']
54
        }
55
    );
56
    return $fines->count ? $fines->next->get_column('total_amountoutstanding') : 0;
57
}
58
39
=head3 type
59
=head3 type
40
60
41
=cut
61
=cut
(-)a/t/db_dependent/Accounts.t (-2 / +36 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 19;
21
use Test::More tests => 20;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 356-359 subtest "makepartialpayment() tests" => sub { Link Here
356
    }
356
    }
357
};
357
};
358
358
359
subtest 'get_balance' => sub {
360
    plan tests => 2;
361
362
    my $patron = $builder->build({source => 'Borrower'});
363
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
364
    my $account_lines = $patron->get_account_lines;
365
    is( $account_lines->get_balance, 0, 'get_balance should return 0 if the patron does not have fines' );
366
367
    my $accountline_1 = $builder->build(
368
        {
369
            source => 'Accountline',
370
            value  => {
371
                borrowernumber    => $patron->borrowernumber,
372
                amount            => 42,
373
                amountoutstanding => 42
374
            }
375
        }
376
    );
377
    my $accountline_2 = $builder->build(
378
        {
379
            source => 'Accountline',
380
            value  => {
381
                borrowernumber    => $patron->borrowernumber,
382
                amount            => -13,
383
                amountoutstanding => -13
384
            }
385
        }
386
    );
387
388
    my $balance = $patron->get_account_lines->get_balance;
389
    is( int($balance), 29, 'get_balance should return the correct value');
390
391
    $patron->delete;
392
};
393
359
1;
394
1;
360
- 

Return to bug 17586