Bug 17600: Standardize our EXPORT_OK
[srvgit] / Koha / Account / Offsets.pm
1 package Koha::Account::Offsets;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20
21 use Koha::Database;
22
23 use Koha::Account::Offset;
24
25 use base qw(Koha::Objects);
26
27 =head1 NAME
28
29 Koha::Account::Offsets - Koha Account Offset Object set class
30
31 Account offsets track the changes made to the balance of account lines
32
33 =head1 API
34
35 =head2 Class methods
36
37     my $offsets = Koha::Account::Offsets->search({ ...  });
38     my $total   = $offsets->total;
39
40 Returns the sum of the amounts of the account offsets resultset. If the resultset is
41 empty it returns 0.
42
43 =head3 total
44
45 =cut
46
47 sub total {
48     my ($self) = @_;
49
50     my $offsets = $self->search(
51         {},
52         {
53             select => [ { sum => 'amount' } ],
54             as     => ['total_amount'],
55         }
56     );
57
58     return $offsets->count
59       ? $offsets->next->get_column('total_amount') + 0
60       : 0;
61 }
62
63 =head2 Internal methods
64
65 =head3 _type
66
67 =cut
68
69 sub _type {
70     return 'AccountOffset';
71 }
72
73 =head3 object_class
74
75 =cut
76
77 sub object_class {
78     return 'Koha::Account::Offset';
79 }
80
81 1;