]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/CT.pm
trim-Funktion zum Entfernen führender und anhängender Whitespaces
[kivitendo-erp.git] / SL / CT.pm
index f21f73b8280880959d2597b764ce73d33cce101c..bec4a6d73bbc2d19a1ba44385c86b3189db3d4a1 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;
 
@@ -118,6 +119,28 @@ sub search {
     push @values, '%' . $form->{cp_name} . '%';
   }
 
+  if ($form->{addr_street}) {
+    $where .= qq| AND ((ct.street ILIKE ?) | .
+              qq|      OR | .
+              qq|      (ct.id IN ( | .
+              qq|         SELECT sc.trans_id FROM shipto sc | .
+              qq|         WHERE (sc.module = 'CT') | .
+              qq|           AND (sc.shiptostreet ILIKE ?) | .
+              qq|      ))) |;
+    push @values, ('%' . $form->{addr_street} . '%') x 2;
+  }
+
+  if ($form->{addr_zipcode}) {
+    $where .= qq| AND ((ct.zipcode ILIKE ?) | .
+              qq|      OR | .
+              qq|      (ct.id IN ( | .
+              qq|         SELECT sc.trans_id FROM shipto sc | .
+              qq|         WHERE (sc.module = 'CT') | .
+              qq|           AND (sc.shiptozipcode ILIKE ?) | .
+              qq|      ))) |;
+    push @values, ('%' . $form->{addr_zipcode} . '%') x 2;
+  }
+
   if ($form->{addr_city}) {
     $where .= " AND ((lower(ct.city) LIKE lower(?))
                      OR
@@ -202,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)) {
@@ -218,16 +250,6 @@ sub search {
     push @values, @cvar_values;
   }
 
-  if ($form->{addr_street}) {
-    $where .= qq| AND (ct.street ILIKE ?)|;
-    push @values, '%' . $form->{addr_street} . '%';
-  }
-
-  if ($form->{addr_zipcode}) {
-    $where .= qq| AND (ct.zipcode ILIKE ?)|;
-    push @values, $form->{addr_zipcode} . '%';
-  }
-
   my $pg_select = $form->{l_pricegroup} ? qq|, pg.pricegroup as pricegroup | : '';
   my $pg_join   = $form->{l_pricegroup} ? qq|LEFT JOIN pricegroup pg ON (ct.klass = pg.id) | : '';
   my $query =