Bug 17586: Add the Koha::Account::Lines->get_balance method
[koha.git] / Koha / Account / Lines.pm
1 package Koha::Account::Lines;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 use Modern::Perl;
19
20 use Carp;
21
22 use Koha::Database;
23
24 use Koha::Account::Line;
25
26 use base qw(Koha::Objects);
27
28 =head1 NAME
29
30 Koha::Cities - Koha City Object set class
31 Koha::Account::Lines - Koha Account Line Object set class
32
33 =head1 API
34
35 =head2 Class Methods
36
37 =cut
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
60
61 =cut
62
63 sub _type {
64     return 'Accountline';
65 }
66
67 sub object_class {
68     return 'Koha::Account::Line';
69 }
70
71 1;