TopQuickSearch für Kunden und Lieferanten
[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     id         => $_[1],
70   );
71 }
72
73 sub init_models {
74   my ($self) = @_;
75
76   my $cvnumber = $self->db eq 'customer' ? 'customernumber' : 'vendornumber';
77
78   SL::Controller::Helper::GetModels->new(
79     controller => $self,
80     model      => $self->model,
81     source     => {
82       filter => {
83         'all:substr:multi::ilike' => $::form->{term}, # all filter spec is set in SL::DB::Manager::Customer
84       },
85     },
86     sorted     => {
87       _default   => {
88         by  => $cvnumber,
89         dir => 0,
90       },
91       $cvnumber => $self->db eq 'customer' ? t8('Customer Number') : t8('Vendor Number'),
92     },
93     paginated  => {
94       per_page => 10,
95     },
96   )
97 }
98
99 sub type {
100   ...
101 }
102
103 sub cv {
104   ...
105 }
106
107 sub model {
108   ...
109 };
110
111 1;