TopQuickSearch: Auftrag, Angebot, Lieferauftrag, Preisanfrage
authorSven Schöling <s.schoeling@linet-services.de>
Thu, 24 Mar 2016 13:15:47 +0000 (14:15 +0100)
committerSven Schöling <s.schoeling@linet-services.de>
Thu, 24 Mar 2016 13:29:38 +0000 (14:29 +0100)
SL/Controller/TopQuickSearch.pm
SL/Controller/TopQuickSearch/OERecord.pm [new file with mode: 0644]
SL/Controller/TopQuickSearch/PurchaseOrder.pm [new file with mode: 0644]
SL/Controller/TopQuickSearch/RequestForQuotation.pm [new file with mode: 0644]
SL/Controller/TopQuickSearch/SalesOrder.pm [new file with mode: 0644]
SL/Controller/TopQuickSearch/SalesQuotation.pm [new file with mode: 0644]
SL/DB/Manager/Order.pm
SL/DB/Order.pm

index 978eb95..d4367ce 100644 (file)
@@ -17,6 +17,10 @@ my @available_modules = (
   'SL::Controller::TopQuickSearch::Service',
   'SL::Controller::TopQuickSearch::Assembly',
   'SL::Controller::TopQuickSearch::Contact',
+  'SL::Controller::TopQuickSearch::SalesQuotation',
+  'SL::Controller::TopQuickSearch::SalesOrder',
+  'SL::Controller::TopQuickSearch::RequestForQuotation',
+  'SL::Controller::TopQuickSearch::PurchaseOrder',
   'SL::Controller::TopQuickSearch::GLTransaction',
 );
 my %modules_by_name;
diff --git a/SL/Controller/TopQuickSearch/OERecord.pm b/SL/Controller/TopQuickSearch/OERecord.pm
new file mode 100644 (file)
index 0000000..adac74a
--- /dev/null
@@ -0,0 +1,118 @@
+package SL::Controller::TopQuickSearch::OERecord;
+
+use strict;
+use parent qw(Rose::Object);
+
+use SL::Locale::String qw(t8);
+use SL::DB::Order;
+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       => $_->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 => 'oe.pl',
+    action     => 'orders',
+    type       => $_[0]->type,
+    vc         => $_[0]->vc,
+    all        => $_[1],
+    open       => 1,
+    closed     => 1,
+    sortdir    => 0,
+    (map {; "l_$_" => 'Y' } $_[0]->number, qw(transdate cusordnumber reqdate name employee netamount)),
+  );
+}
+
+sub redirect_to_object {
+  SL::Controller::Base->new->url_for(
+    controller => 'oe.pl',
+    action     => 'edit',
+    type       => $_[0]->type,
+    vc         => $_[0]->vc,
+    id         => $_[1],
+  );
+}
+
+sub type {
+  ...
+}
+
+sub cv {
+  ...
+}
+
+sub quotation {
+  $_[0]->type !~ /order/
+}
+
+sub number {
+  $_[0]->quotation ? 'quonumber' : 'ordnumber'
+}
+
+sub init_models {
+  my ($self) = @_;
+
+  SL::Controller::Helper::GetModels->new(
+    controller => $self,
+    model      => 'Order',
+    source     => {
+      filter => {
+        type => $self->type,
+        'all:substr:multi::ilike' => $::form->{term},
+      },
+    },
+    sorted     => {
+      _default   => {
+        by  => 'transdate',
+        dir => 0,
+      },
+      transdate => t8('Transdate'),
+    },
+    paginated  => {
+      per_page => 10,
+    },
+    with_objects => [ qw(customer vendor) ]
+  )
+}
+
+1;
diff --git a/SL/Controller/TopQuickSearch/PurchaseOrder.pm b/SL/Controller/TopQuickSearch/PurchaseOrder.pm
new file mode 100644 (file)
index 0000000..4013c8a
--- /dev/null
@@ -0,0 +1,20 @@
+package SL::Controller::TopQuickSearch::PurchaseOrder;
+
+use strict;
+use parent qw(SL::Controller::TopQuickSearch::OERecord);
+
+use SL::Locale::String qw(t8);
+
+sub auth { 'purchase_order_edit' }
+
+sub name { 'purchase_order' }
+
+sub description_config { t8('Purchase Orders') }
+
+sub description_field { t8('Purchase Orders') }
+
+sub type { 'purchase_order' }
+
+sub vc { 'vendor' }
+
+1;
diff --git a/SL/Controller/TopQuickSearch/RequestForQuotation.pm b/SL/Controller/TopQuickSearch/RequestForQuotation.pm
new file mode 100644 (file)
index 0000000..3b2adef
--- /dev/null
@@ -0,0 +1,20 @@
+package SL::Controller::TopQuickSearch::RequestForQuotation;
+
+use strict;
+use parent qw(SL::Controller::TopQuickSearch::OERecord);
+
+use SL::Locale::String qw(t8);
+
+sub auth { 'request_quotation_edit' }
+
+sub name { 'request_quotation' }
+
+sub description_config { t8('Request Quotations') }
+
+sub description_field { t8('Request Quotations') }
+
+sub type { 'request_quotation' }
+
+sub vc { 'vendor' }
+
+1;
diff --git a/SL/Controller/TopQuickSearch/SalesOrder.pm b/SL/Controller/TopQuickSearch/SalesOrder.pm
new file mode 100644 (file)
index 0000000..1f5296e
--- /dev/null
@@ -0,0 +1,20 @@
+package SL::Controller::TopQuickSearch::SalesOrder;
+
+use strict;
+use parent qw(SL::Controller::TopQuickSearch::OERecord);
+
+use SL::Locale::String qw(t8);
+
+sub auth { 'sales_order_edit' }
+
+sub name { 'sales_order' }
+
+sub description_config { t8('Sales Orders') }
+
+sub description_field { t8('Sales Orders') }
+
+sub type { 'sales_order' }
+
+sub vc { 'customer' }
+
+1;
diff --git a/SL/Controller/TopQuickSearch/SalesQuotation.pm b/SL/Controller/TopQuickSearch/SalesQuotation.pm
new file mode 100644 (file)
index 0000000..28ec9fd
--- /dev/null
@@ -0,0 +1,20 @@
+package SL::Controller::TopQuickSearch::SalesQuotation;
+
+use strict;
+use parent qw(SL::Controller::TopQuickSearch::OERecord);
+
+use SL::Locale::String qw(t8);
+
+sub auth { 'sales_quotation_edit' }
+
+sub name { 'sales_quotation' }
+
+sub description_config { t8('Sales Quotations') }
+
+sub description_field { t8('Sales Quotations') }
+
+sub type { 'sales_quotation' }
+
+sub vc { 'customer' }
+
+1;
index d844683..ff5169b 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::Order' }
 
 __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(ordnumber quonumber customer.name vendor.name transaction_description) ]
+  }
+);
+
 sub type_filter {
   my $class  = shift;
   my $type   = lc(shift || '');
index 4d0a2fa..b7bdae0 100644 (file)
@@ -210,6 +210,16 @@ sub date {
   goto &transdate;
 }
 
+sub digest {
+  my ($self) = @_;
+
+  sprintf "%s %s %s (%s)",
+    $self->number,
+    $self->customervendor->name,
+    $self->amount_as_number,
+    $self->date->to_kivitendo;
+}
+
 1;
 
 __END__