Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / SL / Controller / Part.pm
1 package SL::Controller::Part;
2
3 use strict;
4 use parent qw(SL::Controller::Base);
5
6 use SL::DB::Part;
7
8 # safety
9 __PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') });
10
11 sub action_ajax_autocomplete {
12   my ($self, %params) = @_;
13
14   my $limit  = $::form->{limit}  || 20;
15   my $type   = $::form->{type} || {};
16   my $query  = { ilike => "%$::form->{term}%" };
17   my @filter;
18   push @filter, SL::DB::Manager::Part->type_filter($type);
19   push @filter, ($::form->{column})
20     ? ($::form->{column} => $query)
21     : (or => [ partnumber => $query, description => $query ]);
22
23   $self->{parts} = SL::DB::Manager::Part->get_all(query => [ @filter ], limit => $limit);
24   $self->{value} = $::form->{column} || 'description';
25
26   $self->render('part/ajax_autocomplete', { no_layout => 1 });
27 }
28
29
30 1;