Revision f16c5520
Von Sven Schöling vor mehr als 10 Jahren hinzugefügt
SL/Controller/CustomerVendor.pm | ||
---|---|---|
7 | 7 |
use SL::DBUtils; |
8 | 8 |
use SL::Helper::Flash; |
9 | 9 |
use SL::Locale::String; |
10 |
use SL::Controller::Helper::GetModels; |
|
10 | 11 |
|
11 | 12 |
use SL::DB::Customer; |
12 | 13 |
use SL::DB::Vendor; |
... | ... | |
23 | 24 |
use SL::DB::History; |
24 | 25 |
use SL::DB::Currency; |
25 | 26 |
|
27 |
use Rose::Object::MakeMethods::Generic ( |
|
28 |
'scalar --get_set_init' => [ qw(customer_models vendor_models) ], |
|
29 |
); |
|
30 |
|
|
26 | 31 |
# safety |
27 | 32 |
__PACKAGE__->run_before( |
28 | 33 |
sub { |
... | ... | |
50 | 55 |
'_load_customer_vendor', |
51 | 56 |
only => [ |
52 | 57 |
'edit', |
58 |
'show', |
|
53 | 59 |
'update', |
54 | 60 |
'ajaj_get_shipto', |
55 | 61 |
'ajaj_get_contact', |
... | ... | |
88 | 94 |
); |
89 | 95 |
} |
90 | 96 |
|
97 |
sub action_show { |
|
98 |
my ($self) = @_; |
|
99 |
|
|
100 |
if ($::request->type eq 'json') { |
|
101 |
my $cv_hash; |
|
102 |
if (!$self->{cv}) { |
|
103 |
# TODO error |
|
104 |
} else { |
|
105 |
$cv_hash = $self->{cv}->as_tree; |
|
106 |
$cv_hash->{cvars} = $self->{cv}->cvar_as_hashref; |
|
107 |
} |
|
108 |
|
|
109 |
$self->render(\ SL::JSON::to_json($cv_hash), { layout => 0, type => 'json', process => 0 }); |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
91 | 113 |
sub _save { |
92 | 114 |
my ($self) = @_; |
93 | 115 |
|
... | ... | |
539 | 561 |
$self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 }); |
540 | 562 |
} |
541 | 563 |
|
542 |
sub action_ajaj_customer_autocomplete {
|
|
564 |
sub action_ajaj_autocomplete { |
|
543 | 565 |
my ($self, %params) = @_; |
544 | 566 |
|
545 |
my $limit = $::form->{limit} || 20; |
|
546 |
my $type = $::form->{type} || {}; |
|
547 |
my $query = { ilike => '%'. $::form->{term} .'%' }; |
|
548 |
|
|
549 |
my @filter; |
|
550 |
push( |
|
551 |
@filter, |
|
552 |
$::form->{column} ? ($::form->{column} => $query) : (or => [ customernumber => $query, name => $query ]) |
|
553 |
); |
|
567 |
my ($model, $manager, $number, $matches); |
|
568 |
|
|
569 |
# first see if this is customer or vendor picking |
|
570 |
if ($::form->{type} eq 'customer') { |
|
571 |
$model = $self->customer_models; |
|
572 |
$manager = 'SL::DB::Manager::Customer'; |
|
573 |
$number = 'customernumber'; |
|
574 |
} elsif ($::form->{type} eq 'vendor') { |
|
575 |
$model = $self->vendor_models; |
|
576 |
$manager = 'SL::DB::Manager::Vendor'; |
|
577 |
$number = 'vendornumber'; |
|
578 |
} else { |
|
579 |
die "unknown type $::form->{type}"; |
|
580 |
} |
|
554 | 581 |
|
555 |
push @filter, (or => [ obsolete => undef, obsolete => 0 ]) if !$::form->{obsolete}; |
|
582 |
# if someone types something, and hits enter, assume he entered the full name. |
|
583 |
# if something matches, treat that as sole match |
|
584 |
# unfortunately get_models can't do more than one per package atm, so we d it |
|
585 |
# the oldfashioned way. |
|
586 |
if ($::form->{prefer_exact}) { |
|
587 |
my $exact_matches; |
|
588 |
if (1 == scalar @{ $exact_matches = $manager->get_all( |
|
589 |
query => [ |
|
590 |
obsolete => 0, |
|
591 |
or => [ |
|
592 |
name => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, |
|
593 |
$number => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, |
|
594 |
] |
|
595 |
], |
|
596 |
limit => 2, |
|
597 |
) }) { |
|
598 |
$matches = $exact_matches; |
|
599 |
} |
|
600 |
} |
|
556 | 601 |
|
557 |
my $customers = SL::DB::Manager::Customer->get_all(query => [ @filter ], limit => $limit); |
|
558 |
my $value_col = $::form->{column} || 'name'; |
|
602 |
$matches //= $model->get; |
|
603 |
|
|
604 |
my @hashes = map { |
|
605 |
+{ |
|
606 |
value => $_->name, |
|
607 |
label => $_->displayable_name, |
|
608 |
id => $_->id, |
|
609 |
$number => $_->$number, |
|
610 |
name => $_->name, |
|
611 |
type => $::form->{type}, |
|
612 |
cvars => { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $_->cvars_by_config } }, |
|
613 |
} |
|
614 |
} @{ $matches }; |
|
559 | 615 |
|
560 |
my $data = [ |
|
561 |
map( |
|
562 |
{ |
|
563 |
{ |
|
564 |
value => $_->can($value_col)->($_), |
|
565 |
label => $_->displayable_name, |
|
566 |
id => $_->id, |
|
567 |
customernumber => $_->customernumber, |
|
568 |
name => $_->name, |
|
569 |
} |
|
570 |
} |
|
571 |
@{$customers} |
|
572 |
) |
|
573 |
]; |
|
616 |
$self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 }); |
|
617 |
} |
|
574 | 618 |
|
575 |
$self->render(\SL::JSON::to_json($data), { layout => 0, type => 'json' }); |
|
619 |
sub action_test_page { |
|
620 |
$::request->{layout}->add_javascripts('autocomplete_customer.js'); |
|
621 |
$_[0]->render('customer_vendor/test_page'); |
|
576 | 622 |
} |
577 | 623 |
|
578 | 624 |
sub is_vendor { |
... | ... | |
892 | 938 |
return $address; |
893 | 939 |
} |
894 | 940 |
|
941 |
sub init_customer_models { |
|
942 |
my ($self) = @_; |
|
943 |
|
|
944 |
SL::Controller::Helper::GetModels->new( |
|
945 |
controller => $self, |
|
946 |
model => 'Customer', |
|
947 |
sorted => { |
|
948 |
_default => { |
|
949 |
by => 'name', |
|
950 |
dir => 1, |
|
951 |
}, |
|
952 |
name => t8('name'), |
|
953 |
}, |
|
954 |
); |
|
955 |
} |
|
956 |
|
|
957 |
sub init_vendor_models { |
|
958 |
my ($self) = @_; |
|
959 |
|
|
960 |
SL::Controller::Helper::GetModels->new( |
|
961 |
controller => $self, |
|
962 |
model => 'Vendor', |
|
963 |
sorted => { |
|
964 |
_default => { |
|
965 |
by => 'name', |
|
966 |
dir => 1, |
|
967 |
}, |
|
968 |
name => t8('name'), |
|
969 |
}, |
|
970 |
); |
|
971 |
} |
|
972 |
|
|
895 | 973 |
1; |
Auch abrufbar als: Unified diff
CustomerVendor: Picker nach Art von PartPicker
- reinit_widgets fähig
- Tab und Enter atomar
- unterstützt onChange und set_item:CustomerVendorPicker trigger
- unterstützt fat_set_item