|
1 |
package SL::Controller::TopQuickSearch::PhoneNumber;
|
|
2 |
|
|
3 |
use strict;
|
|
4 |
use parent qw(SL::Controller::TopQuickSearch::Base);
|
|
5 |
|
|
6 |
use SL::Controller::TopQuickSearch::Customer;
|
|
7 |
use SL::Controller::TopQuickSearch::Vendor;
|
|
8 |
use SL::DB::Customer;
|
|
9 |
use SL::DB::Vendor;
|
|
10 |
use SL::DBUtils qw(like);
|
|
11 |
use SL::Locale::String qw(t8);
|
|
12 |
use SL::Util qw(trim);
|
|
13 |
|
|
14 |
sub auth { undef }
|
|
15 |
|
|
16 |
sub name { 'phone_number' }
|
|
17 |
|
|
18 |
sub description_config { t8('All phone numbers') }
|
|
19 |
|
|
20 |
sub description_field { t8('All phone numbers') }
|
|
21 |
|
|
22 |
sub query_autocomplete {
|
|
23 |
my ($self) = @_;
|
|
24 |
|
|
25 |
my @results;
|
|
26 |
my $like_search_term = like(trim($::form->{term}));
|
|
27 |
|
|
28 |
foreach my $model (qw(Customer Vendor)) {
|
|
29 |
my $manager = 'SL::DB::Manager::' . $model;
|
|
30 |
my $result = $manager->get_all(
|
|
31 |
query => [ or => [ 'obsolete' => 0, 'obsolete' => undef ],
|
|
32 |
or => [ phone => { ilike => $like_search_term },
|
|
33 |
fax => { ilike => $like_search_term },
|
|
34 |
'contacts.cp_phone1' => { ilike => $like_search_term },
|
|
35 |
'contacts.cp_phone2' => { ilike => $like_search_term },
|
|
36 |
'contacts.cp_fax' => { ilike => $like_search_term },
|
|
37 |
'contacts.cp_mobile1' => { ilike => $like_search_term },
|
|
38 |
'contacts.cp_mobile2' => { ilike => $like_search_term },
|
|
39 |
'contacts.cp_satphone' => { ilike => $like_search_term },
|
|
40 |
'contacts.cp_satfax' => { ilike => $like_search_term },
|
|
41 |
'contacts.cp_privatphone' => { ilike => $like_search_term },
|
|
42 |
] ],
|
|
43 |
with_objects => ['contacts']);
|
|
44 |
|
|
45 |
push @results, map {
|
|
46 |
value => $_->displayable_name,
|
|
47 |
label => $_->displayable_name,
|
|
48 |
id => lc($model) . '_' . $_->id,
|
|
49 |
}, @$result;
|
|
50 |
}
|
|
51 |
|
|
52 |
return \@results;
|
|
53 |
}
|
|
54 |
|
|
55 |
sub select_autocomplete {
|
|
56 |
my ($self) = @_;
|
|
57 |
|
|
58 |
if ($::form->{id} =~ m{^(customer|vendor)_(\d+)$}) {
|
|
59 |
my $type = $1;
|
|
60 |
my $id = $2;
|
|
61 |
$::form->{id} = $id;
|
|
62 |
|
|
63 |
if ($type eq 'customer') {
|
|
64 |
SL::Controller::TopQuickSearch::Customer->new->select_autocomplete;
|
|
65 |
} elsif ($type eq 'vendor') {
|
|
66 |
SL::Controller::TopQuickSearch::Vendor->new->select_autocomplete;
|
|
67 |
}
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
|
71 |
sub do_search {
|
|
72 |
my ($self) = @_;
|
|
73 |
|
|
74 |
my $results = $self->query_autocomplete;
|
|
75 |
|
|
76 |
if (@$results == 1) {
|
|
77 |
$::form->{id} = $results->[0]{id};
|
|
78 |
return $self->select_autocomplete;
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
# TODO: result overview page
|
|
83 |
|
|
84 |
1;
|
Schnellsuche nach "allen" Telefonnummern.
Gesucht wird in allen Telefonnummer-Feldern bei Kunden/Lieferanten
und Ansprechpersonen.