16ab8632fec8df007ab7c68980582f1e8754ce0f
[kivitendo-erp.git] / SL / Controller / TopQuickSearch / CustomerVendor.pm
1 package SL::Controller::TopQuickSearch::CustomerVendor;
2
3 use strict;
4 use parent qw(Rose::Object);
5
6 use SL::Locale::String qw(t8);
7 use SL::Controller::Helper::GetModels;
8 use SL::Controller::Base;
9
10 use Rose::Object::MakeMethods::Generic (
11   'scalar --get_set_init' => [ qw(models) ],
12 );
13
14 # nope. this is only for subclassing
15 sub auth { 'NOT ALLOWED' }
16
17 sub name { ... }
18
19 sub description_config { ... }
20
21 sub description_field { ... }
22
23 sub query_autocomplete {
24   my ($self) = @_;
25
26   my $objects = $self->models->get;
27
28   [
29     map {
30      value       => $_->displayable_name,
31      label       => $_->displayable_name,
32      id          => $_->id,
33     }, @$objects
34   ];
35 }
36
37 sub select_autocomplete {
38   $_[0]->redirect_to_object($::form->{id});
39 }
40
41 sub do_search {
42   my ($self) = @_;
43
44   my $objects = $self->models->get;
45
46   return !@$objects     ? ()
47        : @$objects == 1 ? $self->redirect_to_object($objects->[0]->id)
48        :                  $self->redirect_to_search($::form->{term});
49 }
50
51 sub redirect_to_search {
52   SL::Controller::Base->new->url_for(
53     controller => 'ct.pl',
54     action     => 'list_names',
55     db         => $_[0]->db,
56     sortdir    => 0,
57     status     => 'all',
58     obsolete   => 'N',
59     all        => $_[1],
60     (map {; "l_$_" => 'Y' } $_[0]->db . "number", qw(name street contact phone zipcode email city country gln)),
61
62   );
63 }
64
65 sub redirect_to_object {
66   SL::Controller::Base->new->url_for(
67     controller => 'CustomerVendor',
68     action     => 'edit',
69     db         => $_[0]->db,
70     id         => $_[1],
71   );
72 }
73
74 sub init_models {
75   my ($self) = @_;
76
77   my $cvnumber = $self->db eq 'customer' ? 'customernumber' : 'vendornumber';
78
79   SL::Controller::Helper::GetModels->new(
80     controller => $self,
81     model      => $self->model,
82     source     => {
83       filter => {
84         'all:substr:multi::ilike' => $::form->{term}, # all filter spec is set in SL::DB::Manager::Customer
85       },
86     },
87     sorted     => {
88       _default   => {
89         by  => $cvnumber,
90         dir => 0,
91       },
92       $cvnumber => $self->db eq 'customer' ? t8('Customer Number') : t8('Vendor Number'),
93     },
94     paginated  => {
95       per_page => 10,
96     },
97   )
98 }
99
100 sub type {
101   ...
102 }
103
104 sub cv {
105   ...
106 }
107
108 sub model {
109   ...
110 };
111
112 1;