Schnellsuche für Verkaufs- & Einkaufslieferscheine
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 12 Mar 2019 12:26:56 +0000 (13:26 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 13 Mar 2019 13:31:40 +0000 (14:31 +0100)
SL/Controller/TopQuickSearch.pm
SL/Controller/TopQuickSearch/DeliveryOrder.pm [new file with mode: 0644]
SL/Controller/TopQuickSearch/PurchaseDeliveryOrder.pm [new file with mode: 0644]
SL/Controller/TopQuickSearch/SalesDeliveryOrder.pm [new file with mode: 0644]
SL/DB/DeliveryOrder.pm
SL/DB/Manager/DeliveryOrder.pm
SL/DO.pm
bin/mozilla/do.pl

index 4c65ba2..d6ce6e1 100644 (file)
@@ -21,8 +21,10 @@ my @available_modules = (
   'SL::Controller::TopQuickSearch::Contact',
   'SL::Controller::TopQuickSearch::SalesQuotation',
   'SL::Controller::TopQuickSearch::SalesOrder',
+  'SL::Controller::TopQuickSearch::SalesDeliveryOrder',
   'SL::Controller::TopQuickSearch::RequestForQuotation',
   'SL::Controller::TopQuickSearch::PurchaseOrder',
+  'SL::Controller::TopQuickSearch::PurchaseDeliveryOrder',
   'SL::Controller::TopQuickSearch::GLTransaction',
   'SL::Controller::TopQuickSearch::Customer',
   'SL::Controller::TopQuickSearch::Vendor',
diff --git a/SL/Controller/TopQuickSearch/DeliveryOrder.pm b/SL/Controller/TopQuickSearch/DeliveryOrder.pm
new file mode 100644 (file)
index 0000000..fd2694c
--- /dev/null
@@ -0,0 +1,108 @@
+package SL::Controller::TopQuickSearch::DeliveryOrder;
+
+use strict;
+use parent qw(Rose::Object);
+
+use SL::Locale::String qw(t8);
+use SL::DB::DeliveryOrder;
+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 { die 'must be overwritten' }
+
+sub description_config { die 'must be overwritten' }
+
+sub description_field { die 'must be overwritten' }
+
+sub type { die 'must be overwritten' }
+
+sub cv { die 'must be overwritten' }
+
+sub query_autocomplete {
+  my ($self) = @_;
+
+  my $objects = $self->models->get;
+
+  [
+    map {
+     value       => $_->digest,
+     label       => $_->digest,
+     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   => 'do.pl',
+    action       => 'orders',
+    type         => $_[0]->type,
+    vc           => $_[0]->vc,
+    all          => $_[1],
+    open         => 1,
+    closed       => 1,
+    delivered    => 1,
+    notdelivered => 1,
+    sortdir      => 0,
+    (map {; "l_$_" => 'Y' } qw(donumber transdate cusordnumber reqdate name employee transaction_description)),
+  );
+}
+
+sub redirect_to_object {
+  SL::Controller::Base->new->url_for(
+    controller => 'do.pl',
+    action     => 'edit',
+    type       => $_[0]->type,
+    vc         => $_[0]->vc,
+    id         => $_[1],
+  );
+}
+
+sub init_models {
+  my ($self) = @_;
+
+  SL::Controller::Helper::GetModels->new(
+    controller => $self,
+    model      => 'DeliveryOrder',
+    source     => {
+      filter => {
+        type => $self->type,
+        'all:substr:multi::ilike' => $::form->{term},
+      },
+    },
+    sorted     => {
+      _default   => {
+        by  => 'transdate',
+        dir => 0,
+      },
+      transdate => t8('Date'),
+    },
+    paginated  => {
+      per_page => 10,
+    },
+    with_objects => [ qw(customer vendor orderitems) ]
+  )
+}
+
+1;
diff --git a/SL/Controller/TopQuickSearch/PurchaseDeliveryOrder.pm b/SL/Controller/TopQuickSearch/PurchaseDeliveryOrder.pm
new file mode 100644 (file)
index 0000000..0c26dd1
--- /dev/null
@@ -0,0 +1,20 @@
+package SL::Controller::TopQuickSearch::PurchaseDeliveryOrder;
+
+use strict;
+use parent qw(SL::Controller::TopQuickSearch::DeliveryOrder);
+
+use SL::Locale::String qw(t8);
+
+sub auth { 'purchase_delivery_order_edit' }
+
+sub name { 'purchase_delivery_order' }
+
+sub description_config { t8('Purchase Delivery Orders') }
+
+sub description_field { t8('Purchase Delivery Orders') }
+
+sub type { 'purchase_delivery_order' }
+
+sub vc { 'vendor' }
+
+1;
diff --git a/SL/Controller/TopQuickSearch/SalesDeliveryOrder.pm b/SL/Controller/TopQuickSearch/SalesDeliveryOrder.pm
new file mode 100644 (file)
index 0000000..4895b88
--- /dev/null
@@ -0,0 +1,20 @@
+package SL::Controller::TopQuickSearch::SalesDeliveryOrder;
+
+use strict;
+use parent qw(SL::Controller::TopQuickSearch::DeliveryOrder);
+
+use SL::Locale::String qw(t8);
+
+sub auth { 'sales_delivery_order_edit' }
+
+sub name { 'sales_delivery_order' }
+
+sub description_config { t8('Sales Delivery Orders') }
+
+sub description_field { t8('Sales Delivery Orders') }
+
+sub type { 'sales_delivery_order' }
+
+sub vc { 'customer' }
+
+1;
index 66c8982..15eeee0 100644 (file)
@@ -210,6 +210,15 @@ sub convert_to_invoice {
   return $invoice;
 }
 
+sub digest {
+  my ($self) = @_;
+
+  sprintf "%s %s (%s)",
+    $self->donumber,
+    $self->customervendor->name,
+    $self->date->to_kivitendo;
+}
+
 1;
 __END__
 
index 793e88b..156ca7b 100644 (file)
@@ -6,11 +6,23 @@ use parent qw(SL::DB::Helper::Manager);
 
 use SL::DB::Helper::Paginated;
 use SL::DB::Helper::Sorted;
+use SL::DB::Helper::Filtered;
 
 sub object_class { 'SL::DB::DeliveryOrder' }
 
 __PACKAGE__->make_manager_methods;
 
+__PACKAGE__->add_filter_specs(
+  type => sub {
+    my ($key, $value, $prefix) = @_;
+    return __PACKAGE__->type_filter($value, $prefix);
+  },
+  all => sub {
+    my ($key, $value, $prefix) = @_;
+    return or => [ map { $prefix . $_ => $value } qw(donumber customer.name vendor.name transaction_description orderitems.serialnumber) ]
+  }
+);
+
 sub type_filter {
   my $class = shift;
   my $type  = lc(shift || '');
index 1f431ce..6a91953 100644 (file)
--- a/SL/DO.pm
+++ b/SL/DO.pm
@@ -36,6 +36,7 @@ package DO;
 
 use Carp;
 use List::Util qw(max);
+use Text::ParseWords;
 use YAML;
 
 use SL::AM;
@@ -211,6 +212,17 @@ SQL
     push @values, like($form->{parts_description});
   }
 
+  if ($form->{all}) {
+    my @tokens = parse_line('\s+', 0, $form->{all});
+    # ordnumber quonumber customer.name vendor.name transaction_description
+    push @where, <<SQL for @tokens;
+      (   (dord.donumber                ILIKE ?)
+       OR (ct.name                      ILIKE ?)
+       OR (dord.transaction_description ILIKE ?))
+SQL
+    push @values, (like($_))x3 for @tokens;
+  }
+
   if (@where) {
     $query .= " WHERE " . join(" AND ", map { "($_)" } @where);
   }
index 1ce19d6..c356351 100644 (file)
@@ -706,7 +706,7 @@ sub orders {
   push @hidden_variables, $form->{vc}, qw(l_closed l_notdelivered open closed delivered notdelivered donumber ordnumber serialnumber cusordnumber
                                           transaction_description transdatefrom transdateto reqdatefrom reqdateto
                                           type vc employee_id salesman_id project_id parts_partnumber parts_description
-                                          insertdatefrom insertdateto business_id);
+                                          insertdatefrom insertdateto business_id all);
 
   my $href = build_std_url('action=orders', grep { $form->{$_} } @hidden_variables);
 
@@ -808,6 +808,7 @@ sub orders {
   if ($form->{notdelivered}) {
     push @options, $locale->text('Not delivered');
   }
+  push @options, $locale->text('Quick Search') . " : $form->{all}" if $form->{all};
 
   my $pr = SL::DB::Manager::Printer->find_by(
       printer_description => $::locale->text("sales_delivery_order_printer"));