Merge branch 'master' of github.com:kivitendo/kivitendo-erp
authorJan Büren <jan@kivitendo-premium.de>
Fri, 30 Jan 2015 14:32:28 +0000 (15:32 +0100)
committerJan Büren <jan@kivitendo-premium.de>
Fri, 30 Jan 2015 14:32:28 +0000 (15:32 +0100)
SL/Controller/GL.pm
SL/DB/GLTransaction.pm
SL/DB/Invoice.pm
SL/DB/PurchaseInvoice.pm

index a407e80..e79f304 100644 (file)
@@ -8,6 +8,7 @@ use SL::DB::Invoice;
 use SL::DB::PurchaseInvoice;
 use SL::DB::AccTransaction;
 use SL::Locale::String qw(t8);
+use List::Util qw(sum);
 
 __PACKAGE__->run_before('check_auth');
 
@@ -38,14 +39,9 @@ sub action_quicksearch {
   my $ars = SL::DB::Manager::Invoice->get_all(        query => [ @arfilter ], limit => $limit, sort_by => 'transdate DESC', with_objects => [ 'customer' ]);
   my $aps = SL::DB::Manager::PurchaseInvoice->get_all(query => [ @apfilter ], limit => $limit, sort_by => 'transdate DESC', with_objects => [ 'vendor' ]);
 
-  # calculate an amount to be displayed for gl transaction
+  # use the sum of all credit amounts as the "amount" of the gl transaction
   foreach my $gl ( @$gls ) {
-    my $amount = 0;
-    my $acc_trans_lines = SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $gl->id ]);
-    foreach my $acc_trans_line ( @$acc_trans_lines ) {
-      $amount += $acc_trans_line->amount if $acc_trans_line->amount > 0 ;
-    };
-    $gl->{'amount'} = $amount;
+    $gl->{'amount'} = sum map { $_->amount if $_->amount > 0 } @{$gl->transactions};
   };
 
   my $gldata = [
index 078e2b9..52c8b6e 100644 (file)
@@ -4,11 +4,24 @@ use strict;
 
 use SL::DB::MetaSetup::GLTransaction;
 
-__PACKAGE__->meta->initialize;
 
 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
 __PACKAGE__->meta->make_manager_class;
 
+__PACKAGE__->meta->add_relationship(
+  transactions   => {
+    type         => 'one to many',
+    class        => 'SL::DB::AccTransaction',
+    column_map   => { id => 'trans_id' },
+    manager_args => {
+      with_objects => [ 'chart' ],
+      sort_by      => 'acc_trans_id ASC',
+    },
+  },
+);
+
+__PACKAGE__->meta->initialize;
+
 sub abbreviation {
   my $self = shift;
 
index 7626793..08c5809 100644 (file)
@@ -45,6 +45,15 @@ __PACKAGE__->meta->add_relationship(
     column_map      => { id => 'trans_id' },
     query_args      => [ module => 'AR' ],
   },
+  transactions   => {
+    type         => 'one to many',
+    class        => 'SL::DB::AccTransaction',
+    column_map   => { id => 'trans_id' },
+    manager_args => {
+      with_objects => [ 'chart' ],
+      sort_by      => 'acc_trans_id ASC',
+    },
+  },
 );
 
 __PACKAGE__->meta->initialize;
@@ -351,15 +360,6 @@ sub customervendor {
   goto &customer;
 }
 
-sub transactions {
-  my ($self) = @_;
-
-  return unless $self->id;
-
-  require SL::DB::AccTransaction;
-  SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $self->id ]);
-}
-
 1;
 
 __END__
index a54f1bd..d5955c5 100644 (file)
@@ -31,6 +31,13 @@ __PACKAGE__->meta->add_relationship(
     column_map      => { id => 'trans_id' },
     query_args      => [ module => 'AP' ],
   },
+  transactions   => {
+    type         => 'one to many',
+    class        => 'SL::DB::AccTransaction',
+    column_map   => { id => 'trans_id' },
+    manager_args => { with_objects => [ 'chart' ],
+                      sort_by      => 'acc_trans_id ASC' }
+  },
 );
 
 __PACKAGE__->meta->initialize;