Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
use Modern::Perl;
use Carp;
-use List::Util qw(sum0);
use Koha::Database;
=cut
sub total {
- my ( $self ) = @_;
-
- my $total = sum0( $self->get_column('amount') );
-
- return $total;
+ my ($self) = @_;
+
+ my $offsets = $self->search(
+ {},
+ {
+ select => [ { sum => 'amount' } ],
+ as => ['total_amount'],
+ }
+ );
+
+ return $offsets->count
+ ? $offsets->next->get_column('total_amount') + 0
+ : 0;
}
=head2 Internal methods