From 5c90aae36a36cabae004b03f0b71f30883ac2e8c 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 Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- 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.39.5