From: G. Richardson Date: Sat, 26 Mar 2016 16:20:07 +0000 (+0100) Subject: TopQuickSearch für Kunden und Lieferanten X-Git-Tag: release-3.4.1~277 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1c8c106733572b39dccbb45066d28d4553d31587;p=kivitendo-erp.git TopQuickSearch für Kunden und Lieferanten --- diff --git a/SL/CT.pm b/SL/CT.pm index ded457738..bec4a6d73 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -40,6 +40,7 @@ package CT; use SL::Common; use SL::CVar; use SL::DBUtils; +use Text::ParseWords; use strict; @@ -224,6 +225,15 @@ sub search { push @values, conv_date($form->{insertdateto}); } + if ($form->{all}) { + my @tokens = parse_line('\s+', 0, $form->{all}); + $where .= qq| AND ( + ct.${cv}number ILIKE ? OR + ct.name ILIKE ? + )| for @tokens; + push @values, ("%$_%")x2 for @tokens; + } + # Nur Kunden finden, bei denen ich selber der Verkäufer bin # Gilt nicht für Lieferanten if ($cv eq 'customer' && !$main::auth->assert('customer_vendor_all_edit', 1)) { diff --git a/SL/Controller/TopQuickSearch.pm b/SL/Controller/TopQuickSearch.pm index d4367cef9..7a0143021 100644 --- a/SL/Controller/TopQuickSearch.pm +++ b/SL/Controller/TopQuickSearch.pm @@ -22,6 +22,8 @@ my @available_modules = ( 'SL::Controller::TopQuickSearch::RequestForQuotation', 'SL::Controller::TopQuickSearch::PurchaseOrder', 'SL::Controller::TopQuickSearch::GLTransaction', + 'SL::Controller::TopQuickSearch::Customer', + 'SL::Controller::TopQuickSearch::Vendor', ); my %modules_by_name; @@ -185,7 +187,6 @@ The full interface is described in L =head1 TODO * user configuration - * searches for orders, customers, vendors =head1 BUGS diff --git a/SL/Controller/TopQuickSearch/Customer.pm b/SL/Controller/TopQuickSearch/Customer.pm new file mode 100644 index 000000000..8b7e8ae88 --- /dev/null +++ b/SL/Controller/TopQuickSearch/Customer.pm @@ -0,0 +1,21 @@ +package SL::Controller::TopQuickSearch::Customer; + +use strict; +use parent qw(SL::Controller::TopQuickSearch::CustomerVendor); +use SL::DB::Customer; + +use SL::Locale::String qw(t8); + +sub auth { 'customer_vendor_edit' } + +sub name { 'customer' } + +sub model { 'Customer' } + +sub db { 'customer' } + +sub description_config { t8('Customers') } + +sub description_field { t8('Customers') } + +1; diff --git a/SL/Controller/TopQuickSearch/CustomerVendor.pm b/SL/Controller/TopQuickSearch/CustomerVendor.pm new file mode 100644 index 000000000..cd882fafd --- /dev/null +++ b/SL/Controller/TopQuickSearch/CustomerVendor.pm @@ -0,0 +1,111 @@ +package SL::Controller::TopQuickSearch::CustomerVendor; + +use strict; +use parent qw(Rose::Object); + +use SL::Locale::String qw(t8); +use SL::Controller::Helper::GetModels; +use SL::Controller::Base; + +use Rose::Object::MakeMethods::Generic ( + 'scalar --get_set_init' => [ qw(models) ], +); + +# nope. this is only for subclassing +sub auth { 'NOT ALLOWED' } + +sub name { ... } + +sub description_config { ... } + +sub description_field { ... } + +sub query_autocomplete { + my ($self) = @_; + + my $objects = $self->models->get; + + [ + map { + value => $_->displayable_name, + label => $_->displayable_name, + id => $_->id, + }, @$objects + ]; +} + +sub select_autocomplete { + $_[0]->redirect_to_object($::form->{id}); +} + +sub do_search { + my ($self) = @_; + + my $objects = $self->models->get; + + return !@$objects ? () + : @$objects == 1 ? $self->redirect_to_object($objects->[0]->id) + : $self->redirect_to_search($::form->{term}); +} + +sub redirect_to_search { + SL::Controller::Base->new->url_for( + controller => 'ct.pl', + action => 'list_names', + db => $_[0]->db, + sortdir => 0, + status => 'all', + obsolete => 'N', + all => $_[1], + (map {; "l_$_" => 'Y' } $_[0]->db . "number", qw(name street contact phone zipcode email city country gln)), + + ); +} + +sub redirect_to_object { + SL::Controller::Base->new->url_for( + controller => 'CustomerVendor', + action => 'edit', + id => $_[1], + ); +} + +sub init_models { + my ($self) = @_; + + my $cvnumber = $self->db eq 'customer' ? 'customernumber' : 'vendornumber'; + + SL::Controller::Helper::GetModels->new( + controller => $self, + model => $self->model, + source => { + filter => { + 'all:substr:multi::ilike' => $::form->{term}, # all filter spec is set in SL::DB::Manager::Customer + }, + }, + sorted => { + _default => { + by => $cvnumber, + dir => 0, + }, + $cvnumber => $self->db eq 'customer' ? t8('Customer Number') : t8('Vendor Number'), + }, + paginated => { + per_page => 10, + }, + ) +} + +sub type { + ... +} + +sub cv { + ... +} + +sub model { + ... +}; + +1; diff --git a/SL/Controller/TopQuickSearch/Vendor.pm b/SL/Controller/TopQuickSearch/Vendor.pm new file mode 100644 index 000000000..124530af0 --- /dev/null +++ b/SL/Controller/TopQuickSearch/Vendor.pm @@ -0,0 +1,21 @@ +package SL::Controller::TopQuickSearch::Vendor; + +use strict; +use parent qw(SL::Controller::TopQuickSearch::CustomerVendor); +use SL::DB::Vendor; + +use SL::Locale::String qw(t8); + +sub auth { 'customer_vendor_edit' } + +sub name { 'vendor' } + +sub model { 'Vendor' } + +sub db { 'vendor' } + +sub description_config { t8('Vendors') } + +sub description_field { t8('Vendors') } + +1; diff --git a/bin/mozilla/ct.pl b/bin/mozilla/ct.pl index 04fae4ee9..d256af947 100644 --- a/bin/mozilla/ct.pl +++ b/bin/mozilla/ct.pl @@ -146,6 +146,7 @@ sub list_names { push @options, $locale->text('Billing/shipping address (street)') . " : $form->{addr_street}" if $form->{addr_street}; push @options, $locale->text('Billing/shipping address (country)') . " : $form->{addr_country}" if $form->{addr_country}; push @options, $locale->text('Billing/shipping address (GLN)') . " : $form->{addr_gln}" if $form->{addr_gln}; + push @options, $locale->text('Quick Search') . " : $form->{all}" if $form->{all}; if ($form->{business_id}) { my $business = SL::DB::Manager::Business->find_by(id => $form->{business_id});