From d1f58302cc300e4e7a6420eff5e0630d1fb388d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 14 Mar 2022 12:11:23 +0100 Subject: [PATCH] Schnellsuche nach "allen" Telefonnummern. Gesucht wird in allen Telefonnummer-Feldern bei Kunden/Lieferanten und Ansprechpersonen. --- SL/Controller/TopQuickSearch.pm | 1 + SL/Controller/TopQuickSearch/PhoneNumber.pm | 84 +++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 SL/Controller/TopQuickSearch/PhoneNumber.pm diff --git a/SL/Controller/TopQuickSearch.pm b/SL/Controller/TopQuickSearch.pm index 03d650443..4d0aa9492 100644 --- a/SL/Controller/TopQuickSearch.pm +++ b/SL/Controller/TopQuickSearch.pm @@ -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 index 000000000..ab78d450f --- /dev/null +++ b/SL/Controller/TopQuickSearch/PhoneNumber.pm @@ -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; -- 2.20.1