X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FGL.pm;h=e79f304cbc3ef61ca5ce73083804f5d3ce42cc33;hb=36b7bf7bb11f3875b818387aeda1fad363eb6c96;hp=ce3799de2a619632fd079819e11a914c4f19317e;hpb=f6ed86efee2a0a38b6e88e98fd9d4403fa64ff5e;p=kivitendo-erp.git diff --git a/SL/Controller/GL.pm b/SL/Controller/GL.pm index ce3799de2..e79f304cb 100644 --- a/SL/Controller/GL.pm +++ b/SL/Controller/GL.pm @@ -8,16 +8,17 @@ 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'); sub action_quicksearch { my ($self, %params) = @_; - + my $limit = $::form->{limit} || 40; # max number of results per type (AR/AP/GL) my $term = $::form->{term} || ''; - + my $descriptionquery = { ilike => '%' . $term . '%' }; my $referencequery = { ilike => '%' . $term . '%' }; my $apinvnumberquery = { ilike => '%' . $term . '%' }; @@ -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 = [ @@ -95,7 +91,7 @@ sub action_quicksearch { push(@{$data},@{$ardata}); push(@{$data},@{$apdata}); - @$data = reverse sort { $a->{'transdate_sort'} cmp $b->{'transdate_sort'} } @$data; + @$data = reverse sort { $a->{'transdate'} cmp $b->{'transdate'} } @$data; $self->render(\SL::JSON::to_json($data), { layout => 0, type => 'json' }); }