use SL::Common;
use SL::CVar;
use SL::DBUtils;
+use Text::ParseWords;
use strict;
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)) {
'SL::Controller::TopQuickSearch::RequestForQuotation',
'SL::Controller::TopQuickSearch::PurchaseOrder',
'SL::Controller::TopQuickSearch::GLTransaction',
+ 'SL::Controller::TopQuickSearch::Customer',
+ 'SL::Controller::TopQuickSearch::Vendor',
);
my %modules_by_name;
=head1 TODO
* user configuration
- * searches for orders, customers, vendors
=head1 BUGS
--- /dev/null
+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;
--- /dev/null
+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;
--- /dev/null
+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;
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});