GDPDU: customer, vendor und chart auf einige wenige Spalten beschränken
[kivitendo-erp.git] / SL / CT.pm
index bec4a6d..e4b1ee0 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 SL::DB;
 use Text::ParseWords;
 
 use strict;
@@ -104,19 +105,19 @@ sub search {
 
   if ($form->{"${cv}number"}) {
     $where .= " AND ct.${cv}number ILIKE ?";
-    push(@values, '%' . $form->{"${cv}number"} . '%');
+    push(@values, like($form->{"${cv}number"}));
   }
 
   foreach my $key (qw(name contact email)) {
     if ($form->{$key}) {
       $where .= " AND ct.$key ILIKE ?";
-      push(@values, '%' . $form->{$key} . '%');
+      push(@values, like($form->{$key}));
     }
   }
 
   if ($form->{cp_name}) {
     $where .= " AND ct.id IN (SELECT cp_cv_id FROM contacts WHERE lower(cp_name) LIKE lower(?))";
-    push @values, '%' . $form->{cp_name} . '%';
+    push @values, like($form->{cp_name});
   }
 
   if ($form->{addr_street}) {
@@ -127,7 +128,7 @@ sub search {
               qq|         WHERE (sc.module = 'CT') | .
               qq|           AND (sc.shiptostreet ILIKE ?) | .
               qq|      ))) |;
-    push @values, ('%' . $form->{addr_street} . '%') x 2;
+    push @values, (like($form->{addr_street})) x 2;
   }
 
   if ($form->{addr_zipcode}) {
@@ -138,7 +139,7 @@ sub search {
               qq|         WHERE (sc.module = 'CT') | .
               qq|           AND (sc.shiptozipcode ILIKE ?) | .
               qq|      ))) |;
-    push @values, ('%' . $form->{addr_zipcode} . '%') x 2;
+    push @values, (like($form->{addr_zipcode})) x 2;
   }
 
   if ($form->{addr_city}) {
@@ -151,7 +152,7 @@ sub search {
                           AND (lower(sc.shiptocity) LIKE lower(?))
                       ))
                      )";
-    push @values, ('%' . $form->{addr_city} . '%') x 2;
+    push @values, (like($form->{addr_city})) x 2;
   }
 
   if ($form->{addr_country}) {
@@ -164,7 +165,7 @@ sub search {
                           AND (lower(so.shiptocountry) LIKE lower(?))
                       ))
                      )";
-    push @values, ('%' . $form->{addr_country} . '%') x 2;
+    push @values, (like($form->{addr_country})) x 2;
   }
 
   if ($form->{addr_gln}) {
@@ -177,7 +178,7 @@ sub search {
                           AND (lower(so.shiptogln) LIKE lower(?))
                       ))
                      )";
-    push @values, ('%' . $form->{addr_gln} . '%') x 2;
+    push @values, (like($form->{addr_gln})) x 2;
   }
 
   if ( $form->{status} eq 'orphaned' ) {
@@ -251,7 +252,7 @@ sub search {
   }
 
   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 $pg_join   = $form->{l_pricegroup} ? qq|LEFT JOIN pricegroup pg ON (ct.pricegroup_id = pg.id) | : '';
   my $query =
     qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
     qq|  pt.description as payment | .
@@ -341,7 +342,7 @@ sub get_contact {
 
   die 'Missing argument: cp_id' unless $::form->{cp_id};
 
-  my $dbh   = $form->dbconnect($myconfig);
+  my $dbh   = SL::DB->client->dbh;
   my $query =
     qq|SELECT * FROM contacts c | .
     qq|WHERE cp_id = ? ORDER BY cp_id limit 1|;
@@ -359,7 +360,6 @@ sub get_contact {
   ($form->{cp_used}) = selectfirst_array_query($form, $dbh, $query, ($form->{cp_id})x2);
 
   $sth->finish;
-  $dbh->disconnect;
 
   $main::lxdebug->leave_sub();
 }
@@ -431,7 +431,7 @@ sub search_contacts {
       'cp.cp_name      ILIKE ?',
       'cp.cp_givenname ILIKE ?',
       'cp.cp_email     ILIKE ?';
-    push @values, ('%' . $params{search_term} . '%') x 3;
+    push @values, (like($params{search_term})) x 3;
 
     if (($params{search_term} =~ m/\d/) && ($params{search_term} !~ m/[^\d \(\)+\-]/)) {
       my $number =  $params{search_term};