1 package SL::Controller::TopQuickSearch::Contact;
4 use parent qw(SL::Controller::TopQuickSearch::Base);
6 use SL::Controller::CustomerVendor;
8 use SL::DBUtils qw(selectfirst_array_query like);
9 use SL::Locale::String qw(t8);
13 sub name { 'contact' }
15 sub description_config { t8('Contact') }
17 sub description_field { t8('Contacts') }
19 sub query_autocomplete {
23 SELECT id FROM customer
24 WHERE (obsolete IS NULL)
30 WHERE (obsolete IS NULL)
34 my $result = SL::DB::Manager::Contact->get_all(
37 cp_name => { ilike => like($::form->{term}) },
38 cp_givenname => { ilike => like($::form->{term}) },
39 cp_email => { ilike => like($::form->{term}) },
41 cp_cv_id => [ \$cv_query ],
49 value => $_->full_name,
50 label => $_->full_name,
56 sub select_autocomplete {
59 my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{id});
61 SL::Controller::CustomerVendor->new->url_for(action => 'edit', id => $contact->cp_cv_id, contact_id => $contact->cp_id, db => db_for_contact($contact), fragment => 'contacts');
67 my $results = $self->query_autocomplete;
70 return SL::Controller::CustomerVendor->new->url_for(
71 controller => 'ct.pl',
72 action => 'list_contacts',
73 'filter.status' => 'active',
74 search_term => $::form->{term},
77 $::form->{id} = $results->[0]{id};
78 return $self->select_autocomplete;
86 my ($customer, $vendor) = selectfirst_array_query($::form, $::form->get_standard_dbh, <<SQL, ($contact->cp_cv_id)x2);
87 SELECT (SELECT COUNT(id) FROM customer WHERE id = ?), (SELECT COUNT(id) FROM vendor WHERE id = ?);
90 die 'Contact is orphaned, cannot link to it' if !$customer && !$vendor;
92 $customer ? 'customer' : 'vendor';