From f1dfc8733b503fc00d978cc8498a6999d361df97 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 25 Oct 2018 16:13:27 -0300 Subject: [PATCH] Bug 13098: Sum at DBMS level --- Koha/Account/Offsets.pm | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Koha/Account/Offsets.pm b/Koha/Account/Offsets.pm index d788058c3e..bcc5a6486b 100644 --- a/Koha/Account/Offsets.pm +++ b/Koha/Account/Offsets.pm @@ -18,7 +18,6 @@ package Koha::Account::Offsets; use Modern::Perl; use Carp; -use List::Util qw(sum0); use Koha::Database; @@ -41,11 +40,19 @@ Account offsets track the changes made to the balance of account lines =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 -- 2.11.0