ImageUpload: erste Version
[kivitendo-erp.git] / SL / Controller / TopQuickSearch / Contact.pm
index 5607a5b..e0e915d 100644 (file)
@@ -5,10 +5,10 @@ use parent qw(SL::Controller::TopQuickSearch::Base);
 
 use SL::Controller::CustomerVendor;
 use SL::DB::Vendor;
-use SL::DBUtils qw(selectfirst_array_query);
+use SL::DBUtils qw(selectfirst_array_query like);
 use SL::Locale::String qw(t8);
 
-sub auth { 'customer_vendor_edit' }
+sub auth { undef }
 
 sub name { 'contact' }
 
@@ -19,14 +19,26 @@ sub description_field { t8('Contacts') }
 sub query_autocomplete {
   my ($self) = @_;
 
+  my $cv_query = <<SQL;
+    SELECT id FROM customer
+    WHERE (obsolete IS NULL)
+       OR (obsolete = FALSE)
+
+    UNION
+
+    SELECT id FROM vendor
+    WHERE (obsolete IS NULL)
+       OR (obsolete = FALSE)
+SQL
+
   my $result = SL::DB::Manager::Contact->get_all(
     query => [
       or => [
-        cp_name      => { ilike => "%$::form->{term}%" },
-        cp_givenname => { ilike => "%$::form->{term}%" },
-        cp_email     => { ilike => "%$::form->{term}%" },
+        cp_name      => { ilike => like($::form->{term}) },
+        cp_givenname => { ilike => like($::form->{term}) },
+        cp_email     => { ilike => like($::form->{term}) },
       ],
-      cp_cv_id => [ \'SELECT id FROM customer UNION SELECT id FROM vendor' ],
+      cp_cv_id => [ \$cv_query ],
     ],
     limit => 10,
     sort_by => 'cp_name',
@@ -46,7 +58,7 @@ sub select_autocomplete {
 
   my $contact = SL::DB::Manager::Contact->find_by(cp_id => $::form->{id});
 
-  SL::Controller::CustomerVendor->new->url_for(action => 'edit', id => $contact->cp_cv_id, db => db_for_contact($contact));
+  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');
 }
 
 sub do_search {