Bug 13098: Sum at DBMS level
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 25 Oct 2018 19:13:27 +0000 (16:13 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 31 Oct 2018 13:13:38 +0000 (13:13 +0000)
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Koha/Account/Offsets.pm

index d788058..bcc5a64 100644 (file)
@@ -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