TopQuickSearch für Kunden und Lieferanten
authorG. Richardson <information@kivitendo-premium.de>
Sat, 26 Mar 2016 16:20:07 +0000 (17:20 +0100)
committerG. Richardson <information@kivitendo-premium.de>
Sat, 26 Mar 2016 21:54:02 +0000 (22:54 +0100)
SL/CT.pm
SL/Controller/TopQuickSearch.pm
SL/Controller/TopQuickSearch/Customer.pm [new file with mode: 0644]
SL/Controller/TopQuickSearch/CustomerVendor.pm [new file with mode: 0644]
SL/Controller/TopQuickSearch/Vendor.pm [new file with mode: 0644]
bin/mozilla/ct.pl

index ded4577..bec4a6d 100644 (file)
--- 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)) {
index d4367ce..7a01430 100644 (file)
@@ -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<SL::Controller::TopQuickSeach::Base>
 =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 (file)
index 0000000..8b7e8ae
--- /dev/null
@@ -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 (file)
index 0000000..cd882fa
--- /dev/null
@@ -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 (file)
index 0000000..124530a
--- /dev/null
@@ -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;
index 04fae4e..d256af9 100644 (file)
@@ -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});