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

(-)a/Koha/Account.pm (+24 lines)
Lines 162-167 sub pay { Link Here
162
    }
162
    }
163
}
163
}
164
164
165
=head3 balance
166
167
my $balance = $self->balance
168
169
Return the balance (sum of amountoutstanding columns)
170
171
=cut
172
173
sub balance {
174
    my ($self) = @_;
175
    my $fines = Koha::Account::Lines->search(
176
        {
177
            borrowernumber => $self->{patron_id},
178
        },
179
        {
180
            select => [ { sum => 'amountoutstanding' } ],
181
            as => ['total_amountoutstanding'],
182
        }
183
    );
184
    return $fines->count
185
      ? $fines->next->get_column('total_amountoutstanding')
186
      : 0;
187
}
188
165
1;
189
1;
166
190
167
=head1 AUTHOR
191
=head1 AUTHOR
(-)a/Koha/Account/Lines.pm (-20 lines)
Lines 36-61 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
59
=head3 type
39
=head3 type
60
40
61
=cut
41
=cut
(-)a/t/db_dependent/Accounts.t (-6 / +5 lines)
Lines 356-368 subtest "makepartialpayment() tests" => sub { Link Here
356
    }
356
    }
357
};
357
};
358
358
359
subtest 'get_balance' => sub {
359
subtest 'balance' => sub {
360
    plan tests => 2;
360
    plan tests => 2;
361
361
362
    my $patron = $builder->build({source => 'Borrower'});
362
    my $patron = $builder->build({source => 'Borrower'});
363
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
363
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
364
    my $account_lines = $patron->get_account_lines;
364
    my $account = $patron->account;
365
    is( $account_lines->get_balance, 0, 'get_balance should return 0 if the patron does not have fines' );
365
    is( $account->balance, 0, 'balance should return 0 if the patron does not have fines' );
366
366
367
    my $accountline_1 = $builder->build(
367
    my $accountline_1 = $builder->build(
368
        {
368
        {
Lines 385-392 subtest 'get_balance' => sub { Link Here
385
        }
385
        }
386
    );
386
    );
387
387
388
    my $balance = $patron->get_account_lines->get_balance;
388
    my $balance = $patron->account->balance;
389
    is( int($balance), 29, 'get_balance should return the correct value');
389
    is( int($balance), 29, 'balance should return the correct value');
390
390
391
    $patron->delete;
391
    $patron->delete;
392
};
392
};
393
- 

Return to bug 17586