Schnellsuche nach "allen" Telefonnummern.
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 14 Mar 2022 11:11:23 +0000 (12:11 +0100)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Mon, 14 Mar 2022 13:19:49 +0000 (14:19 +0100)
Gesucht wird in allen Telefonnummer-Feldern bei Kunden/Lieferanten
und Ansprechpersonen.

SL/Controller/TopQuickSearch.pm
SL/Controller/TopQuickSearch/PhoneNumber.pm [new file with mode: 0644]

index 03d6504..4d0aa94 100644 (file)
@@ -28,6 +28,7 @@ my @available_modules = (
   'SL::Controller::TopQuickSearch::GLTransaction',
   'SL::Controller::TopQuickSearch::Customer',
   'SL::Controller::TopQuickSearch::Vendor',
+  'SL::Controller::TopQuickSearch::PhoneNumber',
 );
 my %modules_by_name;
 
diff --git a/SL/Controller/TopQuickSearch/PhoneNumber.pm b/SL/Controller/TopQuickSearch/PhoneNumber.pm
new file mode 100644 (file)
index 0000000..ab78d45
--- /dev/null
@@ -0,0 +1,84 @@
+package SL::Controller::TopQuickSearch::PhoneNumber;
+
+use strict;
+use parent qw(SL::Controller::TopQuickSearch::Base);
+
+use SL::Controller::TopQuickSearch::Customer;
+use SL::Controller::TopQuickSearch::Vendor;
+use SL::DB::Customer;
+use SL::DB::Vendor;
+use SL::DBUtils qw(like);
+use SL::Locale::String qw(t8);
+use SL::Util qw(trim);
+
+sub auth { undef }
+
+sub name { 'phone_number' }
+
+sub description_config { t8('All phone numbers') }
+
+sub description_field { t8('All phone numbers') }
+
+sub query_autocomplete {
+  my ($self) = @_;
+
+  my @results;
+  my $like_search_term = like(trim($::form->{term}));
+
+  foreach my $model (qw(Customer Vendor)) {
+    my $manager = 'SL::DB::Manager::' . $model;
+    my $result  = $manager->get_all(
+      query => [ or => [ 'obsolete' => 0, 'obsolete' => undef ],
+                 or => [ phone                     => { ilike => $like_search_term },
+                         fax                       => { ilike => $like_search_term },
+                         'contacts.cp_phone1'      => { ilike => $like_search_term },
+                         'contacts.cp_phone2'      => { ilike => $like_search_term },
+                         'contacts.cp_fax'         => { ilike => $like_search_term },
+                         'contacts.cp_mobile1'     => { ilike => $like_search_term },
+                         'contacts.cp_mobile2'     => { ilike => $like_search_term },
+                         'contacts.cp_satphone'    => { ilike => $like_search_term },
+                         'contacts.cp_satfax'      => { ilike => $like_search_term },
+                         'contacts.cp_privatphone' => { ilike => $like_search_term },
+                 ] ],
+      with_objects => ['contacts']);
+
+    push @results, map {
+      value => $_->displayable_name,
+      label => $_->displayable_name,
+      id    => lc($model) . '_' . $_->id,
+    }, @$result;
+  }
+
+  return \@results;
+}
+
+sub select_autocomplete {
+  my ($self) = @_;
+
+  if ($::form->{id} =~ m{^(customer|vendor)_(\d+)$}) {
+    my $type      = $1;
+    my $id        = $2;
+    $::form->{id} = $id;
+
+    if ($type eq 'customer') {
+      SL::Controller::TopQuickSearch::Customer->new->select_autocomplete;
+    } elsif ($type eq 'vendor') {
+      SL::Controller::TopQuickSearch::Vendor->new->select_autocomplete;
+    }
+  }
+}
+
+sub do_search {
+  my ($self) = @_;
+
+  my $results = $self->query_autocomplete;
+
+  if (@$results == 1) {
+    $::form->{id} = $results->[0]{id};
+    return $self->select_autocomplete;
+  }
+}
+
+# TODO: result overview page
+
+1;